@openglobus/og 0.28.3 → 0.28.4
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/lib/og.es.js +1 -1
- package/lib/og.es.js.map +1 -1
- package/package.json +1 -1
package/lib/og.es.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const Xi=2*Math.PI,vo=Math.PI/2,or=Number.MAX_VALUE||17976931348623157e292,pn=Math.log(2),Ae=2147483647,xt=549755748352,Ct=-549755748352,j=Math.PI/180,J=180/Math.PI,Gr=2*J,Qt=.5*j,yo=Math.sqrt(.5),xo=1e-5,ne=1e-10,ar=1e-12,lr=1e-14;function Zi(e,t,i){return Math.max(t,Math.min(e,i))}function Ki(e){return!(e&e-1)}function $e(e,t=4096){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1>t?t:e+1}function Ni(e=0,t=1){return Math.floor(Math.random()*(t-e))+e}function bo(e,t){return(e%t+t)%t}function Ue(e){const t=bo(e,Xi);return Math.abs(t)<lr&&Math.abs(e)>lr?Xi:t}function si(e){const t=Math.abs(e);return t-Math.floor(t)}function wo(e,t,i){return i+e*(t-i)}function Hs(e){return e*e*e}function Vs(e){return e*e}function hr(e){return e-360*Math.floor(e/360)}const kc=Object.freeze(Object.defineProperty({__proto__:null,ARCSECONDS_TO_RADIANS:484813681109536e-20,DEG2RAD:function(e){return e*j},DEGREES:J,DEGREES_DOUBLE:Gr,DEGREES_TO_HOURS:1/15,EPS1:.1,EPS10:ne,EPS11:1e-11,EPS12:ar,EPS13:1e-13,EPS14:lr,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:xo,EPS6:1e-6,EPS7:1e-7,EPS8:1e-8,EPS9:1e-9,HOURS_TO_DEGREES:15,HOURS_TO_RADIANS:.26179938779914946,LOG2:pn,MAX:xt,MAX32:Ae,MAX_FLOAT:or,MIN:Ct,PI_TWO:vo,RAD2DEG:function(e){return e*J},RADIANS:j,RADIANS_HALF:Qt,RADIANS_TO_HOURS:3.819718634205488,SQRT_HALF:yo,TWO_PI:Xi,W:3,X:0,Y:1,Z:2,bezier1v:function(e,t,i,s,r){return Hs(1-e)*t+3*Vs(1-e)*e*i+3*(1-e)*Vs(e)*s+Hs(e)*r},bezier3v:function(e,t,i,s,r){let n=1-e,o=e*e,a=n*n,l=a*n,h=o*e;return t.scaleTo(l).addA(i.scaleTo(3*a*e)).addA(s.scaleTo(3*n*o)).addA(r.scaleTo(h))},clamp:Zi,cube:Hs,degToDec:function(e,t,i,s){return s?e+t/60+i/3600:-e-t/60-i/3600},exp2:function(e){return Math.pow(2,e)},frac:si,getAngleBetweenAzimuths:function(e,t){return(((e=Ue(e))-(t=Ue(t)))%360+360+180)%360-180},isPowerOfTwo:Ki,lerp:wo,log:function(e,t){return Math.log(e)/Math.log(t)},log2:function(e){return Math.log(e)/pn},mod:bo,negativePItoPI:function(e){return Ue(e+Math.PI)-Math.PI},nextHighestPowerOfTwo:$e,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:Ni,rev:hr,slice:function(e,t,i){return e*(t-i)},solve_iteration:function(e,t,i,s=50){let r=0,n=t;for(let t=0;t<s;t++)if(r=n,n=e(r),Math.abs(n-r)<i)return n;return n},solve_iteration_fixed:function(e,t,i){let s=0,r=t;for(let t=0;t<i;t++)s=r,r=e(s);return r},square:Vs,step:function(e,t){return t<e?0:1},zeroTwoPI:Ue},Symbol.toStringTag,{value:"Module"})),Ba=.5*Math.PI,To=180/Math.PI,ka=2*To,Us=Math.PI/360,Ia=To*Ba;class L{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 s=e[i];t[i]=new L(s[0],s[1],s[2])}return t}static createFromArray(e){return new L(e[0],e[1],e[2])}static toArray(e){return[e.lon,e.lat,e.height]}toArray(){return L.toArray(this)}static forwardMercator(e,t,i){return new L(e*Hi,Math.log(Math.tan((90+t)*Us))*We,i)}static forwardMercatorRes(e,t){return t.lon=e.lon*Hi,t.lat=Math.log(Math.tan((90+e.lat)*Us))*We,t.height=e.height,t}static inverseMercator(e,t,i=0){return new L(e*Co,ka*Math.atan(Math.exp(t*jr))-Ia,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 L(this.lon,this.lat,this.height)}forwardMercator(){return L.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 L(this.lon*Hi,Math.log(Math.tan((90+e)*Us))*We)}inverseMercator(){return L.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 Lt=20037508.34,Qi=2*Lt,jr=Math.PI/Lt,We=Lt/Math.PI,za=.5*Math.PI,Hi=Lt/180,Co=180/Lt,Eo=Math.PI/360,mn=Math.PI/180,Da=180/Math.PI,Ao=2*Lt,ri=1/Ao;function Ji(e){return new L(e.lon*Lt/180,Math.log(Math.tan((90+e.lat)*Eo))*We,e.height)}function ni(e){return e*Lt/180}function oi(e){return Math.log(Math.tan((90+e)*Eo))*We}function Lo(e){return Da*(2*Math.atan(Math.exp(e*jr))-za)}function Ze(e,t,i){let s=Qi/(1<<i),r=new L(e*s-20037508.34,Lt-t*s-s);return new U(r,new L(r.lon+s,r.lat+s))}const ct=Lo(Lt),Ot=-ct,Ic=Object.freeze(Object.defineProperty({__proto__:null,INV_POLE_BY_180:Co,MAX_LAT:ct,MIN_LAT:Ot,ONE_BY_POLE_DOUBLE:ri,PI_BY_POLE:jr,POLE:Lt,POLE2:Qi,POLE_BY_180:Hi,POLE_BY_PI:We,POLE_DOUBLE:Ao,forward:Ji,forwardArray:function(e){let t=[];for(let i=0;i<e.length;i++)t.push(e[i].forwardMercator());return t},forward_lat:oi,forward_lon:ni,getTileExtent:Ze,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*mn)+1/Math.cos(e*mn))/Math.PI)*Math.pow(2,t))},inverse_lat:Lo,inverse_lon:function(e){return 180*e/Lt}},Symbol.toStringTag,{value:"Module"}));class U{constructor(e=new L,t=new L){this.southWest=e,this.northEast=t}static createFromArray(e){return new U(new L(e[0],e[1]),new L(e[2],e[3]))}static createByCoordinates(e){let t=xt,i=Ct,s=xt,r=Ct;for(let n=0;n<e.length;n++){const o=e[n];o.lon<t&&(t=o.lon),o.lon>i&&(i=o.lon),o.lat<s&&(s=o.lat),o.lat>r&&(r=o.lat)}return new U(new L(t,s),new L(i,r))}static createByCoordinatesArr(e){let t=xt,i=Ct,s=xt,r=Ct;for(let n=0;n<e.length;n++){const o=e[n];o[0]<t&&(t=o[0]),o[0]>i&&(i=o[0]),o[1]<s&&(s=o[1]),o[1]>r&&(r=o[1])}return new U(new L(t,s),new L(i,r))}static fromTile(e,t,i,s=40075016.68,r=40075016.68){const n=1<<i,o=s/n,a=r/n,l=.5*-s+e*o,h=.5*r-t*a,c=l+o;return new U(new L(l,h-a),new L(c,h))}setByCoordinates(e){let t=xt,i=Ct,s=xt,r=Ct;for(let n=0;n<e.length;n++){const o=e[n];o.lon<t&&(t=o.lon),o.lon>i&&(i=o.lon),o.lat<s&&(s=o.lat),o.lat>r&&(r=o.lat)}return this.southWest.lon=t,this.southWest.lat=s,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 U(this.southWest.clone(),this.northEast.clone())}getCenter(){const e=this.southWest,t=this.northEast;return new L(e.lon+.5*(t.lon-e.lon),e.lat+.5*(t.lat-e.lat))}getNorthWest(){return new L(this.southWest.lon,this.northEast.lat)}getNorthEast(){return new L(this.northEast.lon,this.northEast.lat)}getSouthWest(){return new L(this.southWest.lon,this.southWest.lat)}getSouthEast(){return new L(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 U(this.southWest.forwardMercator(),this.northEast.forwardMercator())}inverseMercator(){return new U(this.southWest.inverseMercator(),this.northEast.inverseMercator())}getCartesianBounds(e){let t=xt,i=Ct,s=xt,r=Ct,n=xt,o=Ct;const a=[new L(this.southWest.lon,this.southWest.lat),new L(this.southWest.lon,this.northEast.lat),new L(this.northEast.lon,this.northEast.lat),new L(this.northEast.lon,this.southWest.lat)];for(let l=0;l<a.length;l++){const h=e.lonLatToCartesian(a[l]),c=h.x,d=h.y,_=h.z;c<t&&(t=c),c>i&&(i=c),d<s&&(s=d),d>r&&(r=d),_<n&&(n=_),_>o&&(o=_)}return[t,s,n,i,r,o]}toString(){return`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`}}class Se{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 Se;return e.set(this._m),e}copy(e){return this.set(e._m)}transposeTo(){let e=new Se,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,s=e.z,r=this._m;return new v(r[0]*t+r[3]*i+r[6]*s,r[1]*t+r[4]*i+r[7]*s,r[2]*t+r[5]*i+r[8]*s)}getMat4(){let e=new tt,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 et{constructor(e=0,t=0,i=0,s=0){this.x=e,this.y=t,this.z=i,this.w=s}static get identity(){return new et(0,0,0,1)}static fromVec(e){return new et(e[0],e[1],e[2],e[3])}toVec3(){return new v(this.x,this.y,this.z)}clone(){return new et(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,s){return this.x=e,this.y=t,this.z=i,this.w=s,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 et(this.x*e,this.y*e,this.z*e,this.w*e)}getStep(e){return new et(this.x<e?0:1,this.y<e?0:1,this.z<e?0:1,this.w<e?0:1)}getFrac(e){return new et(si(e.x),si(e.y),si(e.z),si(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 tt{constructor(){this._m=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}static identity(){let e=new tt;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}static getRotationAroundPoint(e,t=v.ZERO,i=v.UP){let s=tt.getRotation(e,i),r=(new tt).setIdentity().translate(t),n=(new tt).setIdentity().translate(t.negateTo());return r.mul(s).mul(n)}static getRotation(e,t=v.UP){return(new tt).setRotation(t,e)}getPosition(){return new v(this._m[12],this._m[13],this._m[14])}getScaling(){let e=this._m[0],t=this._m[1],i=this._m[2],s=this._m[4],r=this._m[5],n=this._m[6],o=this._m[8],a=this._m[9],l=this._m[10];return new v(Math.sqrt(e*e+t*t+i*i),Math.sqrt(s*s+r*r+n*n),Math.sqrt(o*o+a*a+l*l))}getQuat(){let e=this.getScaling();const t=[0,0,0,1];let i=1/e.x,s=1/e.y,r=1/e.z,n=this._m[0]*i,o=this._m[1]*s,a=this._m[2]*r,l=this._m[4]*i,h=this._m[5]*s,c=this._m[6]*r,d=this._m[8]*i,_=this._m[9]*s,u=this._m[10]*r,f=n+h+u,g=0;return f>0?(g=2*Math.sqrt(f+1),t[3]=.25*g,t[0]=(c-_)/g,t[1]=(d-a)/g,t[2]=(o-l)/g):n>h&&n>u?(g=2*Math.sqrt(1+n-h-u),t[3]=(c-_)/g,t[0]=.25*g,t[1]=(o+l)/g,t[2]=(d+a)/g):h>u?(g=2*Math.sqrt(1+h-n-u),t[3]=(d-a)/g,t[0]=(o+l)/g,t[1]=.25*g,t[2]=(c+_)/g):(g=2*Math.sqrt(1+u-n-h),t[3]=(o-l)/g,t[0]=(d+a)/g,t[1]=(c+_)/g,t[2]=.25*g),new F(...t)}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 tt;return e.set(this._m),e}copy(e){return this.set(e._m)}getMat3(){let e=new Se,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,s=e.z;return new v(this._m[0]*t+this._m[4]*i+this._m[8]*s+this._m[12],this._m[1]*t+this._m[5]*i+this._m[9]*s+this._m[13],this._m[2]*t+this._m[6]*i+this._m[10]*s+this._m[14])}mulVec4(e){let t=e.x,i=e.y,s=e.z,r=e.w;return new et(this._m[0]*t+this._m[4]*i+this._m[8]*s+this._m[12]*r,this._m[1]*t+this._m[5]*i+this._m[9]*s+this._m[13]*r,this._m[2]*t+this._m[6]*i+this._m[10]*s+this._m[14]*r,this._m[3]*t+this._m[7]*i+this._m[11]*s+this._m[15]*r)}toInverseMatrix3(){let e=this._m,t=e[0],i=e[1],s=e[2],r=e[4],n=e[5],o=e[6],a=e[8],l=e[9],h=e[10],c=h*n-o*l,d=-h*r+o*a,_=l*r-n*a,u=t*c+i*d+s*_;if(!u)return;u=1/u;let f=new Se;return f._m[0]=c*u,f._m[1]=(-h*i+s*l)*u,f._m[2]=(o*i-s*n)*u,f._m[3]=d*u,f._m[4]=(h*t-s*a)*u,f._m[5]=(-o*t+s*r)*u,f._m[6]=_*u,f._m[7]=(-l*t+i*a)*u,f._m[8]=(n*t-i*r)*u,f}inverseTo(e=new tt){let t=this._m[0],i=this._m[1],s=this._m[2],r=this._m[3],n=this._m[4],o=this._m[5],a=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*o-i*n,v=t*a-s*n,y=t*l-r*n,x=i*a-s*o,b=i*l-r*o,w=s*l-r*a,T=h*f-c*u,C=h*g-d*u,E=h*p-_*u,A=c*g-d*f,L=c*p-_*f,P=d*p-_*g,S=1/(m*P-v*L+y*A+x*E-b*C+w*T);return e._m[0]=(o*P-a*L+l*A)*S,e._m[1]=(-i*P+s*L-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]=(-n*P+a*E-l*C)*S,e._m[5]=(t*P-s*E+r*C)*S,e._m[6]=(-u*w+g*y-p*v)*S,e._m[7]=(h*w-d*y+_*v)*S,e._m[8]=(n*L-o*E+l*T)*S,e._m[9]=(-t*L+i*E-r*T)*S,e._m[10]=(u*b-f*y+p*m)*S,e._m[11]=(-h*b+c*y-_*m)*S,e._m[12]=(-n*A+o*C-a*T)*S,e._m[13]=(t*A-i*C+s*T)*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 tt;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],s=this._m[2],r=this._m[3],n=this._m[4],o=this._m[5],a=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],E=e._m[8],A=e._m[9],L=e._m[10],P=e._m[11],S=e._m[12],R=e._m[13],M=e._m[14],B=e._m[15],k=new tt;return k._m[0]=m*t+v*n+y*h+x*u,k._m[1]=m*i+v*o+y*c+x*f,k._m[2]=m*s+v*a+y*d+x*g,k._m[3]=m*r+v*l+y*_+x*p,k._m[4]=b*t+w*n+T*h+C*u,k._m[5]=b*i+w*o+T*c+C*f,k._m[6]=b*s+w*a+T*d+C*g,k._m[7]=b*r+w*l+T*_+C*p,k._m[8]=E*t+A*n+L*h+P*u,k._m[9]=E*i+A*o+L*c+P*f,k._m[10]=E*s+A*a+L*d+P*g,k._m[11]=E*r+A*l+L*_+P*p,k._m[12]=S*t+R*n+M*h+B*u,k._m[13]=S*i+R*o+M*c+B*f,k._m[14]=S*s+R*a+M*d+B*g,k._m[15]=S*r+R*l+M*_+B*p,k}translate(e){let t=e.x,i=e.y,s=e.z,r=this._m;return r[12]=r[0]*t+r[4]*i+r[8]*s+r[12],r[13]=r[1]*t+r[5]*i+r[9]*s+r[13],r[14]=r[2]*t+r[6]*i+r[10]*s+r[14],r[15]=r[3]*t+r[7]*i+r[11]*s+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),s=Math.sin(t),r=new tt,n=r._m;return n[0]=i+(1-i)*e.x*e.x,n[1]=(1-i)*e.y*e.x-s*e.z,n[2]=(1-i)*e.z*e.x+s*e.y,n[3]=0,n[4]=(1-i)*e.x*e.y+s*e.z,n[5]=i+(1-i)*e.y*e.y,n[6]=(1-i)*e.z*e.y-s*e.x,n[7]=0,n[8]=(1-i)*e.x*e.z-s*e.y,n[9]=(1-i)*e.y*e.z+s*e.x,n[10]=i+(1-i)*e.z*e.z,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this.mul(r)}setRotation(e,t){let i=Math.cos(t),s=Math.sin(t),r=this._m;return r[0]=i+(1-i)*e.x*e.x,r[1]=(1-i)*e.y*e.x-s*e.z,r[2]=(1-i)*e.z*e.x+s*e.y,r[3]=0,r[4]=(1-i)*e.x*e.y+s*e.z,r[5]=i+(1-i)*e.y*e.y,r[6]=(1-i)*e.z*e.y-s*e.x,r[7]=0,r[8]=(1-i)*e.x*e.z-s*e.y,r[9]=(1-i)*e.y*e.z+s*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 F.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,s,r,n){let o=t-e,a=s-i,l=r-n,h=2*r,c=this._m;return c[0]=h/o,c[1]=0,c[2]=0,c[3]=0,c[4]=0,c[5]=h/a,c[6]=0,c[7]=0,c[8]=(t+e)/o,c[9]=(s+i)/a,c[10]=(n+r)/l,c[11]=-1,c[12]=0,c[13]=0,c[14]=h*n/l,c[15]=0,this}setOrthographic(e,t,i,s,r,n){let o=1/(e-t),a=1/(i-s),l=1/(r-n),h=this._m;return h[0]=-2*o,h[1]=0,h[2]=0,h[3]=0,h[4]=0,h[5]=-2*a,h[6]=0,h[7]=0,h[8]=0,h[9]=0,h[10]=2*l,h[11]=0,h[12]=(e+t)*o,h[13]=(s+i)*a,h[14]=(n+r)*l,h[15]=1,this}eulerToMatrix(e,t,i){let s=Math.cos(e),r=Math.sin(e),n=Math.cos(t),o=Math.sin(t),a=Math.cos(i),l=Math.sin(i),h=s*o,c=r*o,d=this._m;return d[0]=n*a,d[1]=-n*l,d[2]=-o,d[4]=-c*a+s*l,d[5]=c*l+s*a,d[6]=-r*n,d[8]=h*a+r*l,d[9]=-h*l+r*a,d[10]=s*n,d[3]=d[7]=d[11]=d[12]=d[13]=d[14]=0,d[15]=1,this}}class F{constructor(e=0,t=0,i=0,s=0){this.x=e,this.y=t,this.z=i,this.w=s}static get IDENTITY(){return new F(0,0,0,1)}static xRotation(e){return e*=.5,new F(Math.sin(e),0,0,Math.cos(e))}static yRotation(e){return e*=.5,new F(0,Math.sin(e),0,Math.cos(e))}static zRotation(e){return e*=.5,new F(0,0,Math.sin(e),Math.cos(e))}static axisAngleToQuat(e,t=0){let i=e.getNormal(),s=.5*t,r=Math.sin(s);return new F(i.x*r,i.y*r,i.z*r,Math.cos(s))}static getLookRotation(e,t){let i=e.getNormal().negate(),s=t.cross(i).normalize(),r=i.cross(s),n=1+s.x+r.y+i.z;if(n>1e-6){let e=1/(2*Math.sqrt(n));return new F((i.y-r.z)*e,(s.z-i.x)*e,(r.x-s.y)*e,.25/e)}if(s.x>r.y&&s.x>i.z){let e=1/(2*Math.sqrt(1+s.x-r.y-i.z));return new F(.25/e,(r.x+s.y)*e,(s.z+i.x)*e,(i.y-r.z)*e)}if(r.y>i.z){let e=1/(2*Math.sqrt(1+r.y-s.x-i.z));return new F((r.x+s.y)*e,.25/e,(i.y+r.z)*e,(s.z-i.x)*e)}let o=1/(2*Math.sqrt(1+i.z-s.x-r.y));return new F((s.z+i.x)*o,(i.y+r.z)*o,.25/o,(r.x-s.y)*o)}static getLookAtSourceDest(e,t){let i=t.subA(e).normalize(),s=v.FORWARD.dot(i);if(Math.abs(s- -1)<1e-6)return F.axisAngleToQuat(v.UP,Math.PI);if(Math.abs(s-1)<1e-6)return new F(0,0,0,1);let r=Math.acos(s),n=v.FORWARD.cross(i).normalize();return F.axisAngleToQuat(n,r)}static getRotationBetweenVectors(e,t){let i=e.cross(t);return new F(i.x,i.y,i.z,1+e.dot(t)).normalize()}static getRotationBetweenVectorsRes(e,t,i){let s=e.cross(t);return i.set(s.x,s.y,s.z,1+e.dot(t)),i.normalize()}static getRotationBetweenVectorsUp(e,t,i){let s=e.dot(t);if(Math.abs(s+1)<1e-6)return F.axisAngleToQuat(i,Math.PI);if(Math.abs(s-1)<1e-6)return new F(0,0,0,1);let r=Math.acos(s),n=e.cross(t).normalize();return F.axisAngleToQuat(n,r)}isZero(){return 0===this.x&&0===this.y&&0===this.z&&0===this.w}isNaN(){return isNaN(this.x)||isNaN(this.y)||isNaN(this.z)||isNaN(this.w)}clear(){return this.x=this.y=this.z=this.w=0,this}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,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 F(this.x,this.y,this.z,this.w)}add(e){return new F(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}addRes(e,t){return t.set(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}sub(e){return new F(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)}scaleTo(e){return new F(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]}get xyz(){return new v(this.x,this.y,this.z)}setLookRotation(e,t){let i=e.getNormal().negate(),s=t.cross(i).normalize(),r=i.cross(s),n=1+s.x+r.y+i.z;if(n>1e-6){let e=1/(2*Math.sqrt(n));this.x=(i.y-r.z)*e,this.y=(s.z-i.x)*e,this.z=(r.x-s.y)*e,this.w=.25/e}else if(s.x>r.y&&s.x>i.z){let e=1/(2*Math.sqrt(1+s.x-r.y-i.z));this.x=.25/e,this.y=(r.x+s.y)*e,this.z=(s.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-s.x-i.z));this.x=(r.x+s.y)*e,this.y=.25/e,this.z=(i.y+r.z)*e,this.w=(s.z-i.x)*e}else{let e=1/(2*Math.sqrt(1+i.z-s.x-r.y));this.x=(s.z+i.x)*e,this.y=(i.y+r.z)*e,this.z=.25/e,this.w=(r.x-s.y)*e}return this}setFromSphericalCoords(e,t,i){let s=Math.sin(i/2),r=Math.cos(i/2),n=Math.sin(e),o=Math.cos(e),a=Math.sin(t),l=Math.cos(t);return this.x=s*o*a,this.y=s*n,this.z=s*n*l,this.w=r,this}getSphericalCoords(){let e=this.w,t=Math.sqrt(1-e*e);Math.abs(t)<5e-4&&(t=1);let i,s=this.x/t,r=this.y/t,n=this.z/t,o=-Math.asin(r);return i=s*s+n*n<5e-4?0:Math.atan2(s,n),i<0&&(i+=360),{lat:o,lon:i,alpha:Math.acos(e)}}setFromAxisAngle(e,t){let i=e.getNormal(),s=.5*t,r=Math.sin(s);return this.set(i.x*r,i.y*r,i.z*r,Math.cos(s)),this}getAxisAngle(){let e,t,i=this.x,s=this.y,r=this.z,n=this.w,o=Math.sqrt(i*i+s*s+r*r);if(o>1e-7){let a=1/o;e=new v(i*a,s*a,r*a),t=n<0?2*Math.atan2(-o,-n):2*Math.atan2(o,n)}else e=new v(0,0,0),t=0;return{axis:e,angle:t}}getPitch(){let e=-2*(this.y*this.z-this.w*this.x);return Math.abs(e)>=1?Math.sign(e)*vo:Math.asin(e)}getYaw(){return-Math.atan2(2*(this.x*this.z+this.w*this.y),1-2*(this.y*this.y+this.x*this.x))}getRoll(){return Math.atan2(2*(this.x*this.y+this.w*this.z),1-2*(this.z*this.z+this.x*this.x))}setPitchYawRoll(e,t,i,s=F.IDENTITY){let r=F.xRotation(-e),n=F.yRotation(t),o=F.zRotation(-i);return this.copy(o.mul(r).mul(n).mul(s).conjugate())}setFromEulerAngles(e,t,i){let s=e*Qt,r=t*Qt,n=i*Qt,o=Math.cos(s),a=Math.cos(r),l=Math.cos(n),h=Math.sin(s),c=Math.sin(r),d=Math.sin(n),_=a*l,u=c*d;return this.w=o*_+h*u,this.x=h*_-o*u,this.y=o*c*l+h*a*d,this.z=o*a*d-h*c*l,this.normalize()}getEulerAngles(){let e=this.x,t=this.y,i=this.z,s=this.w,r=t*t,n=s*t-i*e;return n<-1?n=-1:n>1&&(n=1),{roll:Math.atan2(2*(s*e+t*i),1-2*(e*e+r)),pitch:Math.asin(2*n),yaw:Math.atan2(2*(s*i+e*t),1-2*(r+i*i))}}setFromMatrix4(e){let t,i,s,r,n,o=[],a=e._m,l=[1,2,0];return t=a[0]+a[5]+a[10],t>0?(i=Math.sqrt(t+1),this.w=i/2,i=.5/i,this.x=(a[6]-a[9])*i,this.y=(a[8]-a[2])*i,this.z=(a[1]-a[4])*i):(s=0,a[5]>a[0]&&(s=1),a[10]>a[5*s]&&(s=2),r=l[s],n=l[r],i=Math.sqrt(a[5*s]-(a[5*r]+a[5*n])+1),o[s]=.5*i,0!==i&&(i=.5/i),o[3]=(a[4*r+n]-a[4*n+r])*i,o[r]=(a[4*s+r]+a[4*r+s])*i,o[n]=(a[4*s+n]+a[4*n+s])*i,this.x=o[0],this.y=o[1],this.z=o[2],this.w=o[3]),this}getMat4(e=new tt){let t=this.x+this.x,i=this.y+this.y,s=this.z+this.z,r=this.w*t,n=this.w*i,o=this.w*s,a=this.x*t,l=this.x*i,h=this.x*s,c=this.y*i,d=this.y*s,_=this.z*s;return e.set([1-(c+_),l-o,h+n,0,l+o,1-(a+_),d-r,0,h-n,d+r,1-(a+c),0,0,0,0,1])}getMat3(){let e=new Se,t=e._m,i=this.x,s=this.y,r=this.z,n=this.w,o=i+i,a=s+s,l=r+r,h=i*o,c=i*a;i*=l;let d=s*a;return s*=l,r*=l,o*=n,a*=n,n*=l,t[0]=1-(d+r),t[1]=c-n,t[2]=i+a,t[3]=c+n,t[4]=1-(h+r),t[5]=s-o,t[6]=i-a,t[7]=s+o,t[8]=1-(h+d),e}mulVec3(e){let t=e.x,i=e.y,s=e.z,r=this.x,n=this.y,o=this.z,a=this.w,l=a*t+n*s-o*i,h=a*i+o*t-r*s,c=a*s+r*i-n*t;return t=-r*t-n*i-o*s,new v(l*a+t*-r+h*-o-c*-n,h*a+t*-n+c*-r-l*-o,c*a+t*-o+l*-n-h*-r)}mulVec3Res(e,t){let i=e.x,s=e.y,r=e.z,n=this.x,o=this.y,a=this.z,l=this.w,h=l*i+o*r-a*s,c=l*s+a*i-n*r,d=l*r+n*s-o*i;return i=-n*i-o*s-a*r,t.set(h*l+i*-n+c*-a-d*-o,c*l+i*-o+d*-n-h*-a,d*l+i*-a+h*-o-c*-n)}mul(e){let t=this.x,i=this.y,s=this.z,r=this.w,n=e.x,o=e.y,a=e.z,l=e.w;return new F(t*l+r*n+i*a-s*o,i*l+r*o+s*n-t*a,s*l+r*a+t*o-i*n,r*l-t*n-i*o-s*a)}mulRes(e,t){let i=this.x,s=this.y,r=this.z,n=this.w,o=e.x,a=e.y,l=e.z,h=e.w;return t.set(i*h+n*o+s*l-r*a,s*h+n*a+r*o-i*l,r*h+n*l+i*a-s*o,n*h-i*o-s*a-r*l)}mulA(e){let t=this.x,i=this.y,s=this.z,r=this.w,n=e.x,o=e.y,a=e.z,l=e.w;return this.x=t*l+r*n+i*a-s*o,this.y=i*l+r*o+s*n-t*a,this.z=s*l+r*a+t*o-i*n,this.w=r*l-t*n-i*o-s*a,this}conjugate(){return new F(-this.x,-this.y,-this.z,this.w)}inverse(){let e=1/this.magnitude2();return new F(-this.x*e,-this.y*e,-this.z*e,this.w*e)}magnitude(){let e=this.x,t=this.y,i=this.z,s=this.w;return Math.sqrt(e*e+t*t+i*i+s*s)}magnitude2(){let e=this.x,t=this.y,i=this.z,s=this.w;return e*e+t*t+i*i+s*s}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,s=this.w,r=Math.sqrt(e*e+t*t+i*i+s*s);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=s*r,this)}isEqual(e){let t=this.dot(e);return Math.abs(t-1)<.001}slerp(e,t){let i,s,r,n,o,a=this.x,l=this.y,h=this.z,c=this.w,d=e.x,_=e.y,u=e.z,f=e.w;return s=a*d+l*_+h*u+c*f,s<0&&(s=-s,d=-d,_=-_,u=-u,f=-f),1-s>1e-6?(i=Math.acos(s),r=Math.sin(i),n=Math.sin((1-t)*i)/r,o=Math.sin(t*i)/r):(n=1-t,o=t),new F(n*a+o*d,n*l+o*_,n*h+o*u,n*c+o*f)}}class v{constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}static get UP(){return new v(0,1,0)}static get DOWN(){return new v(0,-1,0)}static get RIGHT(){return new v(1,0,0)}static get LEFT(){return new v(-1,0,0)}static get FORWARD(){return new v(0,0,-1)}static get BACKWARD(){return new v(0,0,1)}static get ZERO(){return new v}static get UNIT_X(){return new v(1,0,0)}static get UNIT_Y(){return new v(0,1,0)}static get UNIT_Z(){return new v(0,0,1)}static get NORTH(){return v.UNIT_Z}static doubleToTwoFloats(e,t,i){let s=e.x,r=e.y,n=e.z;if(s>=0){let e=65536*Math.floor(s/65536);t.x=Math.fround(e),i.x=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.x=Math.fround(-e),i.x=Math.fround(s+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(n>=0){let e=65536*Math.floor(n/65536);t.z=Math.fround(e),i.z=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.z=Math.fround(-e),i.z=Math.fround(n+e)}}static doubleToTwoFloat32Array(e,t,i){let s=e.x,r=e.y,n=e.z;if(s>=0){let e=65536*Math.floor(s/65536);t[0]=Math.fround(e),i[0]=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t[0]=Math.fround(-e),i[0]=Math.fround(s+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(n>=0){let e=65536*Math.floor(n/65536);t[2]=Math.fround(e),i[2]=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t[2]=Math.fround(-e),i[2]=Math.fround(n+e)}}static fromVec(e){return new v(e[0],e[1],e[2])}static angle(e,t){let i=e.dot(t),s=e.cross(t).length();return Math.atan2(s,i)}static lerp(e,t,i){return new v(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 v(e.x,e.y,e.z);return i.addA(t),i}static sub(e,t){let i=new v(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 v(e.x,e.y,e.z);return i.mulA(t),i}static noncollinear(e,t){return!!(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 s=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&s.isZero()?new v(i.x,i.y,i.z):s}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 isOrthogonal(e,t,i=1e-6){const s=e.x*t.x+e.y*t.y+e.z*t.z;return Math.abs(s)<i}isOrthogonal(e,t=1e-6){const i=this.x*e.x+this.y*e.y+this.z*e.z;return Math.abs(i)<t}static div(e,t){let i=new v(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 et(this.x,this.y,this.z,1)}clone(){return new v(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 F(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 v(this.x+e.x,this.y+e.y,this.z+e.z)}addRes(e,t){return t.set(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 v(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 v(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 v(this.x*e.x,this.y*e.y,this.z*e.z)}mulRes(e,t){return t.set(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 v(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 v(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 v;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normal(){let e=new v;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegate(){let e=new v;e.copy(this);let t=-1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegateScale(e){let t=new v;t.copy(this);let i=-e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalScale(e){let t=new v;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,s=this.z-e.z;return Math.sqrt(t*t+i*i+s*s)}distance2(e){let t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return t*t+i*i+s*s}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 v(-this.x,-this.y,-this.z)}projToRay(e,t){let i=v.proj_b_to_a(v.sub(this,e),t);return i.addA(e),i}angle(e){return v.angle(this,e)}lerp(e,t){return new v(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 v(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,s,r,n,o=new v;if(t<=0)return o.copy(this),o;if(t>=1)return o.copy(e),o;let a=this.dot(e);return 1-a>v.LERP_DELTA?(i=Math.acos(a),s=Math.sin(i),r=Math.sin((1-t)*i)/s,n=Math.sin(t*i)/s):(r=1-t,n=t),v.add(this.scaleTo(r),e.scale(n))}mulVecA(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}getRotationTo(e,t){let i=this.clone(),s=e.clone();i.normalize(),s.normalize();let r=i.dot(s);if(r>=1)return F.IDENTITY.clone();if(r<-.999999){if(t.equal(v.ZERO)){let e=v.UNIT_X.cross(i);return e.isZero()&&(e=v.UNIT_Y.cross(i)),e.normalize(),F.axisAngleToQuat(e,Math.PI)}return F.axisAngleToQuat(t,Math.PI)}{let e=Math.sqrt(2*(1+r)),t=1/e,n=i.cross(s),o=new F(n.x*t,n.y*t,n.z*t,.5*e);return o.normalize(),o}}}class H{constructor(e=0,t=0){this.x=e,this.y=t}static get UP(){return new H(0,1)}static get DOWN(){return new H(0,-1)}static get RIGHT(){return new H(1,0)}static get LEFT(){return new H(-1,0)}static get ZERO(){return new H}static add(e,t){const i=new H(e.x,e.y);return i.addA(t),i}static sub(e,t){var i=new H(e.x,e.y);return i.subA(t),i}static scale(e,t){let i=new H(e.x,e.y);return i.scale(t),i}static mul(e,t){let i=new H(e.x,e.y);return i.mulA(t),i}static div(e,t){let i=new H(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()}static proj_b_to_plane(e,t,i){let s=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&s.isZero()?new H(i.x,i.y):s}toVector3(){return new v(this.x,this.y,0)}clone(){return new H(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 H(this.x+e.x,this.y+e.y)}subA(e){return this.x-=e.x,this.y-=e.y,this}sub(e){return new H(this.x-e.x,this.y-e.y)}scale(e){return this.x*=e,this.y*=e,this}scaleTo(e){return new H(this.x*e,this.y*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this}mul(e){return new H(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(){return this.getNormal()}getNormal(){let e=new H;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 H.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 H(-this.x,-this.y)}projToRay(e,t){let i=H.proj_b_to_a(H.sub(this,e),t);return i.add(e),i}angle(e){return H.angle(this,e)}lerp(e,t,i){let s=this.clone();return i<=0?s.copy(e):i>=1?s.copy(t):s=H.add(e,H.sub(t,e).scale(i)),s}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,s,r,n,o=new H;if(t<=0)return o.copy(this),o;if(t>=1)return o.copy(e),o;let a=this.dot(e);return 1-a>H.LERP_DELTA?(i=Math.acos(a),s=Math.sin(i),r=Math.sin((1-t)*i)/s,n=Math.sin(t*i)/s):(r=1-t,n=t),H.add(this.scale(r),e.scale(n))}isZero(){return!(this.x||this.y)}}const Po={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"};class qr{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 v(e,e,t),this._radii2=new v(this._a2,this._a2,this._b2),this._invRadii=new v(1/e,1/e,1/t),this._invRadii2=new v(1/this._a2,1/this._a2,1/this._b2)}rhumbDistanceTo(e,t){const i=e.lat*j,s=t.lat*j,r=s-i;let n=Math.abs(t.lon-e.lon)*j;Math.abs(n)>Math.PI&&(n=n>0?-(2*Math.PI-n):2*Math.PI+n);const o=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),a=Math.abs(o)>1e-11?r/o:Math.cos(i);return Math.sqrt(r*r+a*a*n*n)*this._a}getIntermediatePointOnGreatCircle(e,t,i){if(0==i)return e.clone();if(1==i)return t.clone();const s=this.inverse(e,t),r=s.distance,n=s.initialAzimuth;return isNaN(n)?e:this.getGreatCircleDestination(e,n,r*i)}static getBearing(e,t){let i=e.lat*j,s=e.lon*j,r=t.lat*j,n=t.lon*j,o=Math.sin(n-s)*Math.cos(r),a=Math.cos(i)*Math.sin(r)-Math.sin(i)*Math.cos(r)*Math.cos(n-s);return Math.atan2(o,a)*J}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,s=new v){let r=j*t,n=j*e,o=Math.sin(r),a=this._a/Math.sqrt(1-this._e2*o*o),l=(a+i)*Math.cos(r);return s.x=l*Math.cos(n),s.y=l*Math.sin(n),s.z=(a*(1-this._e2)+i)*o,s}projToSurface(e){let t=e.x||0,i=e.y||0,s=e.z||0,r=Math.sqrt(t*t+i*i+s*s);if(0===r)return this.lonLatToCartesian(new L);let n=this._invRadii2.x,o=this._invRadii2.y,a=this._invRadii2.z,l=t*t*n,h=i*i*o,c=s*s*a,d=l+h+c,_=Math.sqrt(1/d),u=e.scaleTo(_);if(d<.1)return Number.isFinite(_)?u:new v;let f=(1-_)*r/u.mulA(this._invRadii2).length(),g=0,p=0,m=0;for(;;){g=1/(1+f*n),p=1/(1+f*o),m=1/(1+f*a);let e=g*g,t=p*p,i=m*m,s=l*e+h*t+c*i-1;if(Math.abs(s)<ar)break;f+=.5*s/(l*(e*g)*n+h*(t*p)*o+c*(i*m)*a)}return new v(t*g,i*p,s*m)}cartesianToLonLat(e){return this.cartesianToLonLatRes(e)}cartesianToLonLatRes(e,t=new L){let i=this.projToSurface(e),s=this.getSurfaceNormal3v(i),r=e.sub(i);return t.lon=Math.atan2(s.y,s.x)*J,t.lat=Math.asin(s.z)*J,t.height=Math.sign(r.dot(e))*r.length(),t}getSurfaceNormal3v(e){let t=this._invRadii2,i=e.x*t.x,s=e.y*t.y,r=e.z*t.z,n=1/Math.sqrt(i*i+s*s+r*r);return new v(i*n,s*n,r*n)}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,s=this._b,r=this._flattening;const n=e.lat*j,o=e.lon*j,a=t.lat*j,l=t.lon*j-o,h=(1-r)*Math.tan(n),c=1/Math.sqrt(1+h*h),d=h*c,_=(1-r)*Math.tan(a),u=1/Math.sqrt(1+_*_),f=_*u,g=Math.abs(l)>Math.PI/2||Math.abs(a-n)>Math.PI/2;let p=l,m=null,v=null,y=g?Math.PI:0,x=0,b=g?-1:1,w=null,T=1,C=1,E=null,A=0;do{if(m=Math.sin(p),v=Math.cos(p),w=(u*m)**2+(c*f-d*u*v)**2,Math.abs(w)<1e-24)break;x=Math.sqrt(w),b=d*f+c*u*v,y=Math.atan2(x,b);const e=c*u*m/x;C=1-e*e,T=0!=C?b-2*d*f/C:0;const t=r/16*C*(4+r*(4-3*C));E=p,p=l+(1-t)*r*e*(y+t*x*(T+t*b*(2*T*T-1)))}while(Math.abs(p-E)>ar&&++A<1e3);const L=C*(i*i-s*s)/(s*s),P=L/1024*(256+L*(L*(74-47*L)-128)),S=s*(1+L/16384*(4096+L*(L*(320-175*L)-768)))*(y-P*x*(T+P/4*(b*(2*T*T-1)-P/6*T*(4*x*x-3)*(4*T*T-3)))),R=Math.abs(w)<Number.EPSILON?0:Math.atan2(u*m,c*f-d*u*v),M=Math.abs(w)<Number.EPSILON?Math.PI:Math.atan2(c*m,-d*u+c*f*v);return{distance:S,initialAzimuth:Math.abs(S)<Number.EPSILON?NaN:Ue(R)*J,finalAzimuth:Math.abs(S)<Number.EPSILON?NaN:Ue(M)*J}}direct(e,t,i){let s=e.lon,r=e.lat,n=this._a,o=this._b,a=this._flattening,l=i,h=t*j,c=Math.sin(h),d=Math.cos(h),_=(1-a)*Math.tan(r*j),u=1/Math.sqrt(1+_*_),f=_*u,g=Math.atan2(_,d),p=u*c,m=1-p*p,v=m*(n*n-o*o)/(o*o),y=1+v/16384*(4096+v*(v*(320-175*v)-768)),x=v/1024*(256+v*(v*(74-47*v)-128)),b=l/(o*y),w=2*Math.PI,T=0,C=0,E=0,A=0;for(;Math.abs(b-w)>1e-12;)T=Math.cos(2*g+b),C=Math.sin(b),E=Math.cos(b),A=x*C*(T+x/4*(E*(2*T*T-1)-x/6*T*(4*C*C-3)*(4*T*T-3))),w=b,b=l/(o*y)+A;let P=f*C-u*E*d,S=Math.atan2(f*E+u*C*d,(1-a)*Math.sqrt(p*p+P*P)),R=a/16*m*(4+a*(4-3*m)),M=Math.atan2(C*c,u*E-f*C*d)-(1-R)*a*p*(b+R*C*(T+R*E*(2*T*T-1))),B=Math.atan2(p,-P);return{destination:new L(s+M*J,S*J),finalAzimuth:B*J}}hitRay(e,t){let i,s,r,n,o,a=this._invRadii.mul(e),l=this._invRadii.mul(t),h=a.dot(a),c=a.dot(l);if(h>1){if(c>=0)return;var d=c*c;if(i=h-1,s=l.dot(l),r=s*i,Math.abs(d-r)>1e-15&&d<r)return;if(d>r){n=c*c-r,o=-c+Math.sqrt(n);var _=o/s,u=i/o;return _<u?e.add(t.scaleTo(_)):e.add(t.scaleTo(u))}var f=Math.sqrt(i/s);return e.add(t.scaleTo(f))}return h<1?(i=h-1,s=l.dot(l),r=s*i,n=c*c-r,o=-c+Math.sqrt(n),e.add(t.scaleTo(o/s))):c<0?(s=l.dot(l),e.add(t.scaleTo(-c/s))):void 0}getNorthFrameRotation(e){let t=this.getSurfaceNormal3v(e),i=v.proj_b_to_plane(v.NORTH,t);return F.getLookRotation(i,t)}getBearingDestination(e,t=0,i=0){t*=j;var s=(e.lon+540)%360-180,r=e.lat*j,n=s*j,o=i/this._a,a=Math.asin(Math.sin(r)*Math.cos(o)+Math.cos(r)*Math.sin(o)*Math.cos(t));return new L((n+Math.atan2(Math.sin(t)*Math.sin(o)*Math.cos(r),Math.cos(o)-Math.sin(r)*Math.sin(a)))*J,a*J)}static getIntermediatePointOnGreatCircle(e,t,i){var s=e.lat*j,r=e.lon*j,n=t.lat*j,o=t.lon*j,a=Math.sin(s),l=Math.cos(s),h=Math.sin(r),c=Math.cos(r),d=Math.sin(n),_=Math.cos(n),u=Math.sin(o),f=Math.cos(o),g=n-s,p=o-r,m=Math.sin(g/2)*Math.sin(g/2)+Math.cos(s)*Math.cos(n)*Math.sin(p/2)*Math.sin(p/2),v=2*Math.atan2(Math.sqrt(m),Math.sqrt(1-m)),y=Math.sin((1-i)*v)/Math.sin(v),x=Math.sin(i*v)/Math.sin(v),b=y*l*c+x*_*f,w=y*l*h+x*_*u,T=y*a+x*d,C=Math.atan2(T,Math.sqrt(b*b+w*w)),E=Math.atan2(w,b);return new L((E*J+540)%360-180,C*J)}static getRhumbBearing(e,t){var i=(t.lon-e.lon)*j,s=Math.log(Math.tan(t.lat*j/2+Math.PI/4)/Math.tan(e.lat*j/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,s)*J+360)%360}getLonLatVisibilitySimple(e,t,i){const s=this.lonLatToCartesian(t),r=t.height,n=this.polarSize+r,o=Math.max(e.length()-this.polarSize,0),a=s.sub(e);let l;return l=o>0?Math.sqrt((n+o)**2-n**2):n,l>a.length()&&(!i||i.dot(a.normalize())>0)}}const So=new qr(6378137,6356752.314245179);function Vi(e,t){return e??t}function Gt(e){return null==e}function vn(e){return void 0===e}let Fa=0;function Yr(e){let t=e._openglobus_id;return t||(t=e._openglobus_id=++Fa),t}function ks(e){return"string"==typeof e||e instanceof String}function ke(e){return e.toString(16).padStart(2,"0")}function cr(e){let t,i,s;return e instanceof Array?(t=ke(e[0]),i=ke(e[1]),s=ke(e[2])):(t=ke(e.x),i=ke(e.y),s=ke(e.z)),`#${t}${i}${s}`}function he(e,t){let i=Po[e];if(i&&(e=i),"#"===e[0]){let i=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,s=e.replace(i,(function(e,t,i,s){return t+t+i+i+s+s})),r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(s);return r?new et(parseInt(r[1],16)/255,parseInt(r[2],16)/255,parseInt(r[3],16)/255,Gt(t)?1:t):new et}{Gt(t)&&(t=1);let i=e.split(",");return new et(parseInt(i[0].split("(")[1])/255,parseInt(i[1])/255,parseInt(i[2])/255,Gt(i[3])?t:parseFloat(i[3]))}}function ve(e,t){let i=he(e,t);return new Float32Array([i.x,i.y,i.z,i.w])}function ts(e){let t=Po[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,s){return t+t+i+i+s+s})),s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return s?new v(parseInt(s[1],16)/255,parseInt(s[2],16)/255,parseInt(s[3],16)/255):new v}{let t=e.split(",");return new v(parseInt(t[0].split("(")[1])/255,parseInt(t[1])/255,parseInt(t[2])/255)}}function Dt(e,t){return e.replace(/{[^{}]+}/g,(function(e){return t[e.replace(/[{}]+/g,"")]||""}))}function di(e,t){return e.replace(/\$\{([^}]+)\}/g,((e,i)=>(null==t?void 0:t[i.trim()])??""))}function Wr(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 Ro(e,t,i,s){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=`${s}px`}function Mo(e){return"number"==typeof e}function Bo(e,t=""){return e?e.trim():t}function Yt(e,t){if(e){if(Mo(e))return new v(e,e,e);if(e instanceof v)return e.clone();if(e instanceof Array)return v.fromVec(e);if(e instanceof H)return new v(e.x,e.y,0)}else if(t)return t;return new v}function le(e,t){if(e){if(ks(e))return he(e);if(e instanceof Array)return et.fromVec(e);if(e instanceof et)return e.clone()}else if(t)return t;return new et(1,1,1,1)}function jt(e,t){if(e){if(ks(e))return ts(e);if(e instanceof Array)return v.fromVec(e);if(e instanceof v)return e.clone()}else if(t)return t;return new v(1,1,1)}function $r(e,t){if(e){if(e instanceof Array)return new U(vi(e[0]),vi(e[1]));if(e instanceof U)return e.clone()}else if(t)return t;return new U}function vi(e,t){if(e){if(e instanceof Array)return new L(e[0],e[1],e[2]);if(e instanceof L)return e.clone()}else if(t)return t;return new L}function Xr(e,t){let i=0,s=e.length-1;for(;i<=s;){let r=Math.floor(.5*(i+s));if(Math.abs(e[r]-t)<.001)return r;e[r]<t?i=r+1:s=r-1}return-1}function Re(e,t,i){let s=0,r=e.length-1;for(;s<=r;){let n=r+s>>1,o=i(t,e[n],n);if(o>0)s=n+1;else{if(!(o<0))return n;r=n-1}}return-s-1}function Zr(e,t,i){let s=Re(e,t,i);return s<0&&(s=~s),e.splice(s,0,t),s}function ko(e,t,i,s,r=!1){let n=new L(t.lon-e.lon,t.lat-e.lat),o=new L(s.lon-i.lon,s.lat-i.lat),a=-n.lat,l=+n.lon,h=-(a*e.lon+l*e.lat),c=-o.lat,d=+o.lon,_=-(c*i.lon+d*i.lat),u=c*e.lon+d*e.lat+_,f=c*t.lon+d*t.lat+_,g=a*i.lon+l*i.lat+h,p=a*s.lon+l*s.lat+h;if(r&&(u*f>0||g*p>0))return;let m=u/(u-f);return new L(e.lon+m*n.lon,e.lat+m*n.lat)}const Oa={string:function(e){return Gt(e)?e:e.toString()},date:function(e){return Gt(e)?e:new Date(1e3*e)},datetime:function(e){return Gt(e)?e:new Date(1e3*e)},time:function(e){return Gt(e)?e:parseInt(e)},integer:function(e){return Gt(e)?e:parseInt(e)},float:function(e){return Gt(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 yn(e,t=""){let i=1024,s=atob(e),r=s.length,n=Math.ceil(r/i),o=new Array(n);for(let e=0;e<n;++e){let t=e*i,n=Math.min(t+i,r),a=new Array(n-t);for(let e=t,i=0;e<n;++i,++e)a[i]=s[e].charCodeAt(0);o[e]=new Uint8Array(a)}return new Blob(o,{type:t})}function yi(e,t,i=!1){let s,r=0;return function(){const n=arguments;r?(i&&clearTimeout(s),s=setTimeout((()=>{Date.now()-r>=t&&(e.apply(null,n),r=Date.now())}),t-(Date.now()-r))):(e.apply(null,n),r=Date.now())}}function it(e,t){let i=new e.constructor(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function bt(e=[],t=[]){if(ArrayBuffer.isView(e))return it(e,t);for(let i=0;i<t.length;i++)e.push(t[i]);return e}function st(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 Et(e,t,i,s){if(ArrayBuffer.isView(e))return t<0&&(i=Math.abs(t),t+=e.length),ot(e,t,i,s);{let r;return r=t<0?e.splice(t):e.splice(t,i),s&&(s.result=r),e}}function ot(e,t,i,s){if(0===e.length)return e;const r=e.length-i,n=new e.constructor(r);return n.set(e.subarray(0,t)),n.set(e.subarray(t+i),t),s&&(s.result=e.subarray(t,t+i)),n}function Kr(e,t,i,s,r){const n=r+1,o=i+n,a=s+n;let l=new Float64Array(n*n*3),h=0;for(let r=i;r<o;r++)for(let i=s;i<a;i++){let s=3*(r*(t+1)+i);l[h++]=e[s],l[h++]=e[s+1],l[h++]=e[s+2]}return l}function Io(e,t,i,s,r){const n=r+1,o=i+n,a=s+n;let l=new Float32Array(n*n*3),h=0;for(let r=i;r<o;r++)for(let i=s;i<a;i++){let s=3*(r*(t+1)+i);l[h++]=e[s],l[h++]=e[s+1],l[h++]=e[s+2]}return l}function dr(e,t,i,s,r,n,o,a,l,h,c,d,_){const u=n+a+1,f=o+a+1;r+=1;let g=0,p=0;for(let a=n;a<u;a++)for(let n=o;n<f;n++){let o=a*r+n,u=3*o,f=e[u],m=e[u+1],v=e[u+2];s&&0!==s[o]?_[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 Qr(e){return e.map((e=>Array.isArray(e)?Qr(e):e))}async function Ui(e){return new Promise((t=>{const i=new Image;return i.addEventListener("load",(()=>{t(i)})),i.src=e,i.crossOrigin="",i}))}function ur(e){return e.complete&&0!==e.naturalHeight}function Ge(e){return e>1e3?e-Math.floor(e)!=0?[(e/1e3).toFixed(2),"km"]:[(e/1e3).toFixed(0),"km"]:e>9?[Math.round(e).toString(),"m"]:e<=.01?["0","m"]:[e.toFixed(1),"m"]}function zo(e){let t=new URLSearchParams(location.search).get(e);if(t)return Number(t)}function _r(e,t=-1){if(t<0)return e.toString();const i=Math.pow(10,t);return(Math.round(e*i)/i).toString()}const zc=Object.freeze(Object.defineProperty({__proto__:null,base64StringToBlog:function(e){let t=e.split(";"),i=t[0].split(":")[1];return yn(t[1].split(",")[1],i)},base64toBlob:yn,binaryInsert:Zr,binarySearch:Re,binarySearchFast:Xr,blerp:function(e,t,i,s,r,n,o=0,a=1,l=0,h=1){return(i*(a-e)*(h-t)+s*(e-o)*(h-t)+r*(a-e)*(t-l)+n*(e-o)*(t-l))/((a-o)*(h-l))},blerp2:function(e,t,i,s,r,n){return i*(1-e)*(1-t)+s*e*(1-t)+r*(1-e)*t+n*e*t},castType:Oa,cloneArray:Qr,concatArrays:bt,concatTypedArrays:it,createColorRGB:jt,createColorRGBA:le,createExtent:$r,createLonLat:vi,createVector3:Yt,createVector4:function(e,t){if(e){if(e instanceof et)return e.clone();if(e instanceof Array)return et.fromVec(e)}else if(t)return t;return new et},defaultString:Bo,distanceFormat:function(e){return e>1e3?`${(e/1e3).toFixed(2)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`},distanceFormatExt:Ge,extractElevationTiles:function(e,t,i){let s=Math.sqrt(t.length)-1,r=s+1,n=Math.sqrt(e.length/4),o=n/s,a=0,l=0;for(let h=0,c=0,d=e.length/4;h<d;h++){let d=e[4*h],_=Math.floor(h/n),u=h%n,f=Math.floor(u/s),g=Math.floor(_/s),p=i[g][f],m=_%s,v=u%s,y=(m+g)*r+v+f;if(p[y]=d,(_+g)%o==0&&(u+f)%o==0&&(t[c++]=d),(u+1)%s==0&&u!==n-1){a=e[4*(h+1)];let n=.5*(d+a);y=(m+g)*r+v+1,p[y]=n,(_+g)%o==0&&(t[c++]=n);let l=(m+g)*r+(v+1)%s;i[g][f+1][l]=n}if((_+1)%s==0&&_!==n-1){l=e[4*(h+n)];let a=.5*(d+l);y=(m+1)*r+v+f,p[y]=a,(u+f)%o==0&&(t[c++]=a);let _=(m+1)%s*r+v+f;i[g+1][f][_]=a}if((u+1)%s==0&&u!==n-1&&(_+1)%s==0&&_!==n-1){let o=.25*(d+a+l+e[4*(h+n+1)]);y=(m+1)*r+(v+1),p[y]=o,t[c++]=o;let _=(m+1)*r;i[g][f+1][_]=o;let u=s;i[g+1][f][u]=o;let x=0;i[g+1][f+1][x]=o}}},getDefault:Vi,getHTML:function(e,t){return Dt(e,t)},getLinesIntersection2v:function(e,t,i,s,r){let n=t.sub(e),o=s.sub(i),a=-n.y,l=+n.x,h=-(a*e.x+l*e.y),c=-o.y,d=+o.x,_=-(c*i.x+d*i.y),u=c*e.x+d*e.y+_,f=c*t.x+d*t.y+_,g=a*i.x+l*i.y+h,p=a*s.x+l*s.y+h;if(r&&(u*f>0||g*p>0))return;let m=u/(u-f);return new H(e.x+m*n.x,e.y+m*n.y)},getLinesIntersectionLonLat:ko,getMatrixSubArray32:Io,getMatrixSubArray64:Kr,getMatrixSubArrayBoundsExt:dr,getTileImageResolution:function(e,t,i,s=256,r=So){let n=Ze(e,t,i),o=n.getSouthWest().inverseMercator(),a=n.getNorthEast().inverseMercator();return[r.getGreatCircleDistance(o,new L(a.lon,o.lat))/s,r.getGreatCircleDistance(o,new L(o.lon,a.lat))/s]},getUrlParam:zo,htmlColorToFloat32Array:ve,htmlColorToRgb:ts,htmlColorToRgba:he,isEmpty:Gt,isImageLoaded:ur,isNumber:Mo,isString:ks,isUndef:vn,isUndefExt:function(e,t){return vn(e)?t:e},loadImage:Ui,makeArray:Ve,makeArrayTyped:st,parseHTML:Wr,print2d:Ro,rgbToStringHTML:cr,spliceArray:Et,spliceTypedArray:ot,stamp:Yr,stringTemplate:Dt,stringTemplate2:di,throttle:yi,toFixedMax:_r,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 s=t.attributes.item(e);i["@attributes"][s.nodeName]=s.nodeValue}}}else 3===t.nodeType&&(i=t.nodeValue);if(t.hasChildNodes())for(let s=0;s<t.childNodes.length;s++){let r=t.childNodes.item(s),n=r.nodeName;if(void 0===i[n])i[n]=e(r);else{if(void 0===i[n].push){let e=i[n];i[n]=[],i[n].push(e)}i[n].push(e(r))}}return i}},Symbol.toStringTag,{value:"Module"})),Gi=1e3,fr=1/60,xn=1/24,xi=3600,gr=1/xi,Jr=43200,ji=1440,Na=1/ji,ee=86400,Ha=864e5,tn=1.1574074074074074e-8,oe=1/ee,es=2451545;function Do(e,t,i){let s=(t-14)/12|0,r=e+4800+s;return(1461*r/4|0)+(367*(t-2-12*s)/12|0)-(3*((r+100)/100|0)/4|0)+i-32075}function is(e){let t=Do(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()),i=e.getUTCHours()-12;i<0&&(i+=24);let s=e.getUTCSeconds()+i*xi+60*e.getUTCMinutes()+.001*e.getUTCMilliseconds();s>=Jr&&t--;let r=s*oe|0;return t+=r,s-=ee*r,s<0&&(t--,s+=ee),t+s*oe}function pr(e){let t=Oo,i=Re(t,e,(function(e,t){return e-t.jd}));i<0&&(i=~i),i>=t.length&&(i=t.length-1);let s=t[i].leapSeconds;return 0!==i&&(t[i].jd-e)*ee>s&&(s=t[i-1].leapSeconds),e+s*oe}function Gs(e){let t=Oo,i=Re(t,e,(function(e,t){return e-t.jd}));if(i<0&&(i=~i),i>=t.length)return e-t[i-1].leapSeconds*oe;if(0===i)return e-t[0].leapSeconds*oe;let s=(t[i].jd-e)*ee;return 0===s?e-t[i].leapSeconds*oe:s<=1?void 0:e-t[i-1].leapSeconds*oe}function mr(e){let t=0|e,i=(e-t)*ee;i>=Jr&&t++;let s=t+68569|0,r=4*s/146097|0;s=s-((146097*r+3)/4|0)|0;let n=4e3*(s+1)/1461001|0;s=s-(1461*n/4|0)+31|0;let o=80*s/2447|0,a=s-(2447*o/80|0)|0;s=o/11|0;let l=o+2-12*s|0,h=100*(r-49)+n+s|0,c=i*gr|0,d=i-c*xi,_=d*fr|0;d-=60*_;let u=0|d,f=(d-u)*Gi|0;return c+=12,c>23&&(c-=24),new Date(Date.UTC(h,l-1,a,c,_,u,f))}function Fo(e,t){return e+t*tn}function bn(e,t){return e+t*oe}function nt(e,t){return{jd:e,leapSeconds:t}}const Oo=[nt(2441317.5,10),nt(2441499.5,11),nt(2441683.5,12),nt(2442048.5,13),nt(2442413.5,14),nt(2442778.5,15),nt(2443144.5,16),nt(2443509.5,17),nt(2443874.5,18),nt(2444239.5,19),nt(2444786.5,20),nt(2445151.5,21),nt(2445516.5,22),nt(2446247.5,23),nt(2447161.5,24),nt(2447892.5,25),nt(2448257.5,26),nt(2448804.5,27),nt(2449169.5,28),nt(2449534.5,29),nt(2450083.5,30),nt(2450630.5,31),nt(2451179.5,32),nt(2453736.5,33),nt(2454832.5,34),nt(2456109.5,35),nt(2457204.5,36)],Va=pr(es),Dc=Object.freeze(Object.defineProperty({__proto__:null,DAYS_PER_JULIAN_CENTURY:36525,DAYS_PER_JULIAN_YEAR:365.25,DateToTAI:function(e){return pr(is(e))},DateToUTC:is,HOURS_PER_DAY:24,J2000:es,J2000TAI:Va,MILLISECONDS_PER_DAY:Ha,MILLISECONDS_PER_SECOND:Gi,MINUTES_PER_DAY:ji,MINUTES_PER_HOUR:60,MODIFIED_JULIAN_DATE_DIFFERENCE:2400000.5,ONE_BY_HOURS_PER_DAY:xn,ONE_BY_MILLISECONDS_PER_DAY:tn,ONE_BY_MINUTES_PER_DAY:Na,ONE_BY_SECONDS_PER_DAY:oe,ONE_BY_SECONDS_PER_HOUR:gr,ONE_BY_SECONDS_PER_MINUTE:fr,PICOSECOND:1e-9,SECONDS_PER_12_HOURS:Jr,SECONDS_PER_DAY:ee,SECONDS_PER_HOUR:xi,SECONDS_PER_MILLISECOND:.001,SECONDS_PER_MINUTE:60,T:function(e){return(e-es)/36525},TAItoDate:function(e){let t=Gs(e);return t||(t=Gs(bn(e,-1)),console.trace(`TAItoDate - can't convert ${e.toString()} to utc.`)),mr(t)},TAItoUTC:Gs,UTCtoDate:mr,UTCtoTAI:pr,addDays:function(e,t){return e+t},addHours:function(e,t){return e+t*xn},addMilliseconds:Fo,addMinutes:function(e,t){return e+t*ji},addSeconds:bn,daysToSeconds:function(e){return e*ee},getDayNumber:Do,getDays:function(e){return 0|e},getHours:function(e){let t=(e-(0|e))*ee,i=t*gr|0,s=t-i*xi,r=s*fr|0;s-=60*r;let n=0|s;return i+=12+r/60+n/3600+((s-n)*Gi|0)/1e3,i>23&&(i-=24),i},getMilliseconds:function(e){let t=e-(0|e);return t*=ee,(t-(0|t))*Gi|0},getMinutes:function(e){return(e-(0|e))*ji|0},getSeconds:function(e){return(e-(0|e))*ee},secondsToDays:function(e){return e*oe}},Symbol.toStringTag,{value:"Module"}));class No{constructor(e){this.vertices=[new v,new v,new v,new v,new v,new v,new v,new v],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],s=e[1],r=e[4],n=e[2],o=e[5],a=this.vertices;a[0].set(t,s,n),a[1].set(i,s,n),a[2].set(i,s,o),a[3].set(t,s,o),a[4].set(t,r,n),a[5].set(i,r,n),a[6].set(i,r,o),a[7].set(t,r,o)}setFromExtent(e,t){this.setFromBoundsArr(t.getCartesianBounds(e))}}class Ft{constructor(e=0,t){this.radius=e,this.center=t?t.clone():new v}setFromBounds(e){let t=new v(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))}}const Fc=Object.freeze(Object.defineProperty({__proto__:null,Box:No,Sphere:Ft},Symbol.toStringTag,{value:"Module"}));function lt(e,t){return new bi(e,t)}const cs=class e{constructor(t,i){this.__id=e.__counter__++,this._eventNames=[],t&&this.registerNames(t),this._sender=i||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=Yr(t),s=this._getStamp(e,this.__id,i);return!this._stampCache[s]&&(this._stampCache[s]=i,!0)}on(e,t,i,s=0){if(this._stamp(e,t)&&this[e]){let r=t.bind(i||this._sender);r._openglobus_id=t._openglobus_id,r._openglobus_priority=s,Zr(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 s=this[e].handlers,r=s.length,n=-1;for(;r--;)if(s[r]._openglobus_id===t._openglobus_id){n=r;break}-1!==n&&(s.splice(n,1),this._stampCache[i]=void 0,delete this._stampCache[i])}}}dispatch(e,...t){let i=!0;if(e&&e.active&&!this._stopPropagation){let s=e.handlers.slice(0),r=s.length;for(;r--;)!1===s[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=[]}};cs.__counter__=0;let bi=cs;const Ua=["render"],Vt=class e{constructor(t={}){this.__id=e.__counter__++,this.events=lt(Ua),this.model=t.model||null,this.template=t.template||"",this.parent=t.parent||null,this._classList=t.classList||[],this.el=null,t.initRender&&this.render()}on(e,t,i,s){this.events.on(e,t,i,s)}off(e,t){this.events.off(e,t)}static getHTML(e,t){return Dt(e,t)}static parseHTML(e){return Wr(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(t){this.el||this.render(),this.el&&(t instanceof HTMLElement&&t.parentNode&&e.insertBefore(this.el,t),t instanceof e&&t.el&&t.el.parentNode&&e.insertBefore(this.el,t.el))}insertAfter(t){this.el||this.render(),this.el&&(t instanceof HTMLElement&&t.parentNode&&e.insertAfter(this.el,t),t instanceof e&&t.el&&t.el.parentNode&&e.insertAfter(this.el,t.el))}isEqual(e){return e.__id===this.__id}appendTo(t,i=!1,s=!1){return t&&(this.el||(this.beforeRender(t),this.render()),this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),i&&(t.innerHTML=""),this.el&&(s&&t.childNodes[0]?e.insertBefore(this.el,t.childNodes[0]):t.appendChild(this.el)),this.afterRender(t)),this}afterRender(e){}beforeRender(e){}stopPropagation(){this.events.stopPropagation()}renderTemplate(t){return e.parseHTML(e.getHTML(this.template,t||{}))[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,s=i.length;e<s;e++)t(i[e],e);return i}}remove(){this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el)}};Vt.__counter__=0;let ut=Vt;const Ga=["click","mousedown","mouseup","touchstart","touchend","touchcancel"];class ce extends ut{constructor(e={}){super({template:Dt('<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(Ga),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)}}const ds=class e{constructor(t={}){this.__id=e.__counter__++,this._name=t.name||`_control_${this.__id.toString()}`,this.planet=null,this._initialized=!1,this.renderer=null,this.autoActivate=t.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&&(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}};ds.__counter__=0;let Q=ds;class Ho extends Q{constructor(e={}){super(e),this._heading=0,this._svg=null}oninit(){let e=new ce({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),e.events.on("touchstart",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)),{amplitude:0,completeCallback:()=>{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 Vo='<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>',ja=["resize","focus","visibility","dragstart","dragend"],us=class e extends ut{constructor(e={}){super({template:Dt('<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:Vi(e.visible,!0)?"flex":"none",resize:Vi(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(ja),this._width=e.width||300,this._height=e.height||200,this._startPosX=0,this._startPosY=0,this.$header=null,this.$title=null,this.$container=null,this.$buttons=null,this._closeBtn=new ce({icon:Vo,classList:["og-button-size__20"]}),this.useHide=e.useHide||!1,this._visibility=Vi(e.visible,!0),this._right=null!=e.right?e.right:null}setContainer(e){this.$container.innerHTML=e}get container(){return this.$container}get width(){return this.el?parseFloat(this.el.style.width):this._width}get height(){return this.el?parseFloat(this.el.style.height):this._height}bringToFront(){this.el.style.zIndex=String(e.__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(),null!=this._right&&(this.el.style.visibility="hidden",new IntersectionObserver(((e,t)=>{e.forEach((e=>{e.isIntersecting&&(this.el.style.visibility="visible",this.el.parentNode&&(this.setPosition(this.el.parentNode.clientWidth-this.el.clientWidth-this._right),t.disconnect()))}))})).observe(this.el)),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()}getVisibility(){return this._visibility}_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)}};us.__zIndex__=0;let Kt=us;const qa=["change"];class dt extends ce{constructor(e){super({...e}),this._onMouseClick=e=>{this.preventClick||(this._mouseClickHandler(e),this.setActive(!this.isActive))},this.events=this.events.registerNames(qa),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 ui=[2,3,0,1],wn=[[-1,-1,0,1],[1,-1,3,-1],[2,3,-1,-1],[-1,0,-1,2]],Ya=[[2,3,0,1],[1,0,3,2],[2,3,0,1],[1,0,3,2]],Wa=[[0,1,0,0],[1,0,0,0],[0,1,0,1],[1,1,1,1]];class Uo{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 _s=class e{constructor(t,i={}){if(this.isVector=!1,this.__id=e.__counter__++,this._iconSrc=i.iconSrc||null,this.events=lt(Go,this),this.name=t||"noname",this.properties=i.properties||{},this.hideInLayerSwitcher=i.hideInLayerSwitcher||!1,this._hasImageryTiles=!0,this._opacity=null!=i.opacity?i.opacity:1,this.minZoom=i.minZoom||0,this.maxZoom=null!=i.maxZoom?i.maxZoom:50,this._planet=null,this.isVector=!1,this._attribution=i.attribution||"",this._zIndex=i.zIndex||0,this._isBaseLayer=i.isBaseLayer||!1,this._defaultTextures=i.defaultTextures||[null,null],this._visibility=void 0===i.visibility||i.visibility,this._fading=i.fading||!1,this._fadingFactor=this._opacity/30,this._fading?this._fadingOpacity=0:this._fadingOpacity=this._opacity,this._height=i.height||0,this._extent=new U,this.createTexture=null,this._textureFilter=i.textureFilter?i.textureFilter.trim().toUpperCase():"MIPMAP",this._isSRGB=null!=i.isSRGB&&i.isSRGB,this._internalFormat=null,this._extentMerc=new U,this.setExtent($r(i.extent,new U(new L(-180,-90),new L(180,90)))),this._pickingColor=new v,this._pickingEnabled=void 0===i.pickingEnabled||i.pickingEnabled,this._isPreloadDone=!1,this._preLoadZoomLevels=i.preLoadZoomLevels||[0,1],this._ambient=null,this._diffuse=null,this._specular=null,i.ambient){let e=jt(i.ambient,new v(.2,.2,.2));this._ambient=new Float32Array([e.x,e.y,e.z])}if(i.diffuse){let e=jt(i.diffuse,new v(.8,.8,.8));this._diffuse=new Float32Array([e.x,e.y,e.z])}if(i.specular){let e=jt(i.specular,new v(3e-4,3e-4,3e-4)),t=i.shininess||20;this._specular=new Float32Array([e.x,e.y,e.z,t])}this.nightTextureCoefficient=i.nightTextureCoefficient||1}get iconSrc(){return this._iconSrc}set iconSrc(e){this._iconSrc=e}set diffuse(e){if(e){let t=jt(e);this._diffuse=new Float32Array(t.toArray())}else this._diffuse=null}set ambient(e){if(e){let t=jt(e);this._ambient=new Float32Array(t.toArray())}else this._ambient=null}set specular(e){if(e){let t=jt(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,s){return`${s}::${e}_${t}_${i}`}get instanceName(){return"Layer"}get rendererEvents(){return this.events}set opacity(e){e!==this._opacity&&(this._fading?e>this._opacity?this._fadingFactor=(e-this._opacity)/30:e<this._opacity&&(this._fadingFactor=(this._opacity-e)/30):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.quadTreeStrategy._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||(e.quadTreeStrategy._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,s=e.nodes.length;i<s;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,s=e.quadTreeStrategy.quadTreeList.length;i<s;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<Ot&&(t.lat=Ot),i.lat>ct&&(i.lat=ct),this._extent=e.clone(),this._extentMerc=new U(t.forwardMercator(),i.forwardMercator()),this._correctFullExtent()}getExtent(){return this._extent}getExtentMerc(){return this._extentMerc}flyExtent(){var e;null==(e=this._planet)||e.flyExtent(this.getExtent())}viewExtent(){var e;null==(e=this._planet)||e.viewExtent(this.getExtent())}_correctFullExtent(){}get opacity(){return this._opacity}get screenOpacity(){return this._fading?this._fadingOpacity:this._opacity}_refreshFadingOpacity(e,t){let i=this._planet;return this._visibility&&i.getViewExtent().overlaps(this._extent)&&t>=this.minZoom&&e<=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-=this._fadingFactor,this._fadingOpacity<=0&&(this._fadingOpacity=0),!1)}createMaterial(e){return new Uo(e,this)}redraw(){var e;null==(e=this._planet)||e.quadTreeStrategy.clearLayerMaterial(this)}abortMaterialLoading(e){}abortLoading(){}};_s.__counter__=0;let zt=_s;const Go=["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"],$a=["load","loadend"],Ut=class e extends zt{constructor(e,t){super(e,t),this.events=this.events.registerNames($a),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.quadTreeStrategy._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(t){let i=t.segment;this._isBaseLayer?t.texture=i.getDefaultTexture():t.texture=i.planet.transparentTexture,(this._planet.layerLock.isFree()||t.segment.tileZoom<2)&&(t.isReady=!1,t.isLoading=!0,e.__requestsCounter>=e.MAX_REQUESTS&&this._counter?this._pendingsQueue.push(t):this._exec(t))}_exec(t){e.__requestsCounter++,this._counter++;const i=this.events.load;i.handlers.length&&this.events.dispatch(i,t),requestAnimationFrame((()=>{this.drawTile(t,(i=>{this._counter--,e.__requestsCounter--,this._correctCounter(),t.isLoading&&t.applyImage(i),this._dequeueRequest()}))}))}_correctCounter(){this._counter<0&&(this._counter=0),e.__requestsCounter<0&&(e.__requestsCounter=0)}abortMaterialLoading(t){t.isLoading&&(this._counter--,e.__requestsCounter--,this._correctCounter(),this._dequeueRequest()),t.isLoading=!1,t.isReady=!1}_dequeueRequest(){if(this._pendingsQueue.length){if(e.__requestsCounter<e.MAX_REQUESTS){const e=this._whilePendings();e&&this._exec(e)}}else 0===this._counter&&this._planet&&this._planet.quadTreeStrategy._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,s=!1,r=e.layer.maxNativeZoom;t.passReady&&!e.isLoading&&t.tileZoom<=r&&this.loadMaterial(e);let n=this._id,o=e;for(;i.parentNode;)if(i=i.parentNode,o=i.segment.materials[n],o&&o.textureExists){s=!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 s=i.segment.materials[n];s?!s.isLoading&&!s.isReady&&this.loadMaterial(s):(s=i.segment.materials[e.layer._id]=e.layer.createMaterial(i.segment),this.loadMaterial(s))}if(s){e.layer.animated&&requestAnimationFrame((()=>{e.segment&&this.drawTile(e,(function(t){e.applyImage(t)}))})),e.appliedNodeId=i.nodeId,e.texture=o.texture;let s=1/(2<<t.tileZoom-i.segment.tileZoom-1);e.texOffset[0]=t.tileX*s-i.segment.tileX,e.texOffset[1]=t.tileY*s-i.segment.tileY,e.texOffset[2]=s,e.texOffset[3]=s}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}};Ut.MAX_REQUESTS=20,Ut.__requestsCounter=0;let ss=Ut;const Xa=["change"];class jo{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=lt(Xa),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 en{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){if(ks(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)}}else for(let t=0;t<this._numWorkers;t++){let t=new e;t.onmessage=e=>{this._onMessage(e),this._workerQueue&&this._workerQueue.unshift(e.target),this.check()},this._workerQueue.push(t)}}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=[],this._workerQueue=[]}get pendingQueue(){return this._pendingQueue}}const qo='(function(){"use strict";function n(i,f,u){let o=u.length,b=f*o;for(let A=0;A<o;A++)i[b+A]=u[A]}self.onmessage=function(i){var f=i.data.labelData,u=f[0],o=f[1],b=f[2],A=f[3],z=f[4],D=f[5],H=f[6],I=f[7],L=f[8],M=f[9],P=f[10],j=f[11],q=f[12],B=f[13],E=f[14],G=f[15],J=f[16],K=f[17],N=f[18],O=f[19],Q=f[20],R=f[21],S=f[22],T=f[23],U=f[24],Z=f[25],_=f[26],$=f[27],V=f[28],X=f[29];let w=new Float32Array(12*o),s=new Float32Array(24*o),y=new Float32Array(24*o),F=new Float32Array(18*o),g=new Float32Array(18*o),c=new Float32Array(6*o),d=new Float32Array(18*o),p=new Float32Array(24*o),x=new Float32Array(6*o),h=new Float32Array(18*o),v=new Float32Array(6*o),C=new Float32Array(6*o),m=new Float32Array(24*o),k=new Float32Array(18*o);for(let t=0;t<o;t++){n(w,t,b!==0?[0,0,0,-1,1,-1,1,-1,1,0,0,0]:[0,0,0,0,0,0,0,0,0,0,0,0]),n(s,t,[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(y,t,[1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0]);var l,r=A,e=z,a=D;n(F,t,[r,e,a,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a]),n(g,t,[r=H,e=I,a=L,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a]),n(c,t,[r=M,r,r,r,r,r]),n(d,t,[r=P,e=j,a=q,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a]),n(p,t,[r=B,e=E,a=G,l=J,r,e,a,l,r,e,a,l,r,e,a,l,r,e,a,l,r,e,a,l]),n(x,t,[r=K,r,r,r,r,r]),n(h,t,[r=N,e=O,a=Q,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a]),n(v,t,[r=R,r,r,r,r,r]),n(C,t,[r=S,r,r,r,r,r]),n(m,t,[r=T,e=U,a=Z,l=_,r,e,a,l,r,e,a,l,r,e,a,l,r,e,a,l,r,e,a,l]),n(k,t,[r=$/255,e=V/255,a=X/255,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a])}self.postMessage({id:u,vertexArr:w,texCoordArr:s,gliphParamArr:y,positionHighArr:F,positionLowArr:g,sizeArr:c,offsetArr:d,rgbaArr:p,rotationArr:x,alignedAxisArr:h,fontIndexArr:v,outlineArr:C,outlineColorArr:m,pickingColorArr:k},[w.buffer,s.buffer,y.buffer,F.buffer,g.buffer,c.buffer,d.buffer,p.buffer,x.buffer,h.buffer,v.buffer,C.buffer,m.buffer,k.buffer])}})();\n//# sourceMappingURL=LabelWorker.worker-BT1uJgYn.js.map\n',Tn=typeof self<"u"&&self.Blob&&new Blob([qo],{type:"text/javascript;charset=utf-8"});function Za(e){let t;try{if(t=Tn&&(self.URL||self.webkitURL).createObjectURL(Tn),!t)throw"";const i=new Worker(t,{name:null==e?void 0:e.name});return i.addEventListener("error",(()=>{(self.URL||self.webkitURL).revokeObjectURL(t)})),i}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(qo),{name:null==e?void 0:e.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}const Mt=-2,mt=-1;class Ka extends en{constructor(e=4){super(e,Za)}_onMessage(e){let t=this._source.get(e.data.id);-2===t.label._lockId?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 s=this._workerQueue.pop();this._source.set(this._sourceId,e),t._lockId=this._sourceId,this._sourceId++,s.postMessage({labelData:i},[i.buffer])}else this._pendingQueue.push(e)}}}const fs=class e{constructor(t={}){this.__id=e.__counter__++,this._position=Yt(t.position),this._positionHigh=new v,this._positionLow=new v,v.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._rotation=t.rotation||0,this._color=le(t.color),this._alignedAxis=Yt(t.alignedAxis),this._offset=Yt(t.offset),this._visibility=null==t.visibility||t.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1,this._isReady=!1,this._lockId=-1}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,v.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):-1!==this._lockId&&(this._lockId=-2)}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z,v.doubleToTwoFloats(e,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):-1!==this._lockId&&(this._lockId=-2)}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):-1!==this._lockId&&(this._lockId=-2)}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):-1!==this._lockId&&(this._lockId=-2))}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):-1!==this._lockId&&(this._lockId=-2))}setColor(e,t,i,s){s===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!=s&&(this._color.w=s),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):-1!==this._lockId&&(this._lockId=-2))}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(he(e))}getColor(){return this._color}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._isReady&&this._handler?this._handler.setVisibility(this._handlerIndex,e):-1!==this._lockId&&(this._lockId=-2))}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):-1!==this._lockId&&(this._lockId=-2)}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):-1!==this._lockId&&(this._lockId=-2)}serializeWorkerData(e){return this._handler?new Float32Array([]):null}};fs.__counter__=0;let rs=fs;class Qa extends rs{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 s=i.renderer.billboardsTextureAtlas,r=this;s.loadImage(e,(function(e){null!=e.__nodeIndex&&s.get(e.__nodeIndex)?(r._image=e,t.setTexCoordArr(r._handlerIndex,s.get(r._image.__nodeIndex).texCoords)):(s.addImage(e),s.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=(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",e))(ai||{});const Ja={POINT:1,LINESTRING:2,POLYGON:3,MULTIPOLYGON:4,MULTILINESTRING:5},ue=class e{constructor(t={}){this.__id=e.__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=t.type&&e.getType(t.type)||1,this._coordinates=t.coordinates||[],this._extent=e.getExtent({type:t.type||"POINT",coordinates:t.coordinates||[]},this._coordinates),t.style=t.style||{},this._style={fillColor:le(t.style.fillColor,new et(.19,.62,.85,.4)),lineColor:le(t.style.lineColor,new et(.19,.62,.85,1)),strokeColor:le(t.style.strokeColor,new et(1,1,1,.95)),lineWidth:t.style.lineWidth||3,strokeWidth:t.style.strokeWidth||0},this._visibility=t.visibility||!0,this._pickingReady=!1}get id(){return this.__id}get type(){return this._type}static getType(e){return Ja[e.toUpperCase()]}static getExtent(t,i){let s=new U(new L(180,90),new L(-180,-90)),r=e.getType(t.type);if(1===r){let e=t.coordinates[0],r=t.coordinates[1];s.southWest.lon=e,s.southWest.lat=r,s.northEast.lon=e,s.northEast.lat=r,i&&(i[0]=e)&&(i[1]=r)}else if(2===r){let e=t.coordinates;for(let t=0;t<e.length;t++){let r=e[t][0],n=e[t][1];r<s.southWest.lon&&(s.southWest.lon=r),n<s.southWest.lat&&(s.southWest.lat=n),r>s.northEast.lon&&(s.northEast.lon=r),n>s.northEast.lat&&(s.northEast.lat=n),i&&(i[t]=[r,n])}}else if(3===r){let e=t.coordinates;for(let t=0;t<e.length;t++){let r=e[t];i&&(i[t]=[]);for(let e=0;e<r.length;e++){let n=r[e],o=n[0],a=n[1];o<s.southWest.lon&&(s.southWest.lon=o),a<s.southWest.lat&&(s.southWest.lat=a),o>s.northEast.lon&&(s.northEast.lon=o),a>s.northEast.lat&&(s.northEast.lat=a),i&&(i[t][e]=[o,a])}}}else if(4===r){let e=t.coordinates;for(let t=0;t<e.length;t++){let r=e[t];i&&(i[t]=[]);for(let e=0;e<r.length;e++){let n=r[e];i&&(i[t][e]=[]);for(let r=0;r<n.length;r++){let o=n[r],a=o[0],l=o[1];a<s.southWest.lon&&(s.southWest.lon=a),l<s.southWest.lat&&(s.southWest.lat=l),a>s.northEast.lon&&(s.northEast.lon=a),l>s.northEast.lat&&(s.northEast.lat=l),i&&(i[t][e][r]=[a,l])}}}}else if(5===r){let e=t.coordinates;for(let t=0;t<e.length;t++){let r=e[t];i&&(i[t]=[]);for(let e=0;e<r.length;e++){let n=r[e],o=n[0],a=n[1];o<s.southWest.lon&&(s.southWest.lon=o),a<s.southWest.lat&&(s.southWest.lat=a),o>s.northEast.lon&&(s.northEast.lon=o),a>s.northEast.lat&&(s.northEast.lat=a),i&&(i[t][e]=[o,a])}}}else s.southWest.lon=s.southWest.lat=s.northEast.lon=s.northEast.lat=0,i&&(i[0]=0)&&(i[1]=0);return s}setGeometry(t){let i=this._handler;return i&&(this.remove(),this._type=e.getType(t.type||"Point"),this._extent=e.getExtent(t,this._coordinates),i.add(this)),this}setFillColor(e,t,i,s=1){let r=this._style.fillColor;return(0===r.w&&0!==s||0!==r.w&&0===s)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=s,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,s=1){let r=this._style.strokeColor;return(0===r.w&&0!==s||0!==r.w&&0===s)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=s,this._handler&&this._handler.setLineStrokeColorArr(this,r),this}setLineColor(e,t,i,s=1){let r=this._style.lineColor;return(0===r.w&&0!==s||0!==r.w&&0===s)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=s,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}};ue.__counter__=0;let vr=ue;class qi{constructor(e=0,t=0,i=0){this.a=e,this.b=t,this.c=i}static get(e,t){return new qi(t.y-e.y,e.x-t.x,t.x*e.y-e.x*t.y)}static getParallel(e,t){return new qi(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 H(i,-(e.c+e.a*i)/e.b)}intersects(e){return qi.getIntersection(this,e)}}class Jt{constructor(e,t){this.p0=e||new v,this.p1=t||new v}getMagnitude(){return this.p0.distance(this.p1)}getSphereIntersection(e){let t=this.p0,i=this.p1,s=e.center.x,r=e.center.y,n=e.center.z,o=t.x,a=t.y,l=t.z,h=i.x-o,c=i.y-a,d=i.z-l,_=h*h+c*c+d*d,u=2*(o*h+a*c+l*d-h*s-c*r-d*n),f=u*u-4*_*(o*o-2*o*s+s*s+a*a-2*a*r+r*r+l*l-2*l*n+n*n-e.radius*e.radius);if(f<0)return[];let g=(-u-Math.sqrt(f))/(2*_),p=new v(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*_),y=new v(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,y]:[y,p]}intersects(e,t,i){let s=this.p0.sub(e.p0),r=e.p1.sub(e.p0);if(Math.abs(r.x)<ne&&Math.abs(r.y)<ne&&Math.abs(r.z)<ne)return!1;let n=this.p1.sub(this.p0);if(Math.abs(n.x)<ne&&Math.abs(n.y)<ne&&Math.abs(n.z)<ne)return!1;let o=s.x*r.x+s.y*r.y+s.z*r.z,a=r.x*n.x+r.y*n.y+r.z*n.z,l=s.x*n.x+s.y*n.y+s.z*n.z,h=r.x*r.x+r.y*r.y+r.z*r.z,c=(n.x*n.x+n.y*n.y+n.z*n.z)*h-a*a;if(Math.abs(c)<ne)return!1;let d=(o*a-l*h)/c;if(t.x=this.p0.x+d*n.x,t.y=this.p0.y+d*n.y,t.z=this.p0.z+d*n.z,i){let t=(o+a*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,s=this.p1,r=this.getMagnitude(),n=((e.x-i.x)*(s.x-i.x)+(e.y-i.y)*(s.y-i.y)+(e.z-i.z)*(s.z-i.z))/(r*r);return t.x=i.x+n*(s.x-i.x),t.y=i.y+n*(s.y-i.y),t.z=i.z+n*(s.z-i.z),!(n<0||n>1)}}class vt{constructor(e,t){this.p=e?e.clone():new v,this.n=t?t.clone():this.p.isZero()?v.UP:this.p.getNormal()}setByPoints(e,t,i){let s=v.sub(t,e),r=v.sub(i,e);return this.n=s.cross(r),this.p.copy(e),this}static fromPoints(e,t,i){return(new vt).setByPoints(e,t,i)}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 v.proj_b_to_plane(e,this.n,t)}getProjectionPoint(e,t){let i=e.sub(this.p),s=this.n,r=i.dot(s);return t?t.copy(s.scale(r)):t=s.scale(r),e.sub(t)}getIntersection(e,t,i){let s,r=e.n.cross(t.n),n=r.x>=0?r.x:-r.x,o=r.y>=0?r.y:-r.y,a=r.z>=0?r.z:-r.z;if(n+o+a<xo){let i=t.p.sub(e.p);return 0==e.n.dot(i)?1:0}s=n>o?n>a?1:3:o>a?2:3;let l,h,c=new v;return l=-e.n.dot(e.p),h=-t.n.dot(t.p),1===s?(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===s?(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===s&&(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 V=class e{constructor(e=v.ZERO,t=v.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 v.add(this.origin,this.direction.scaleTo(e))}hitTriangleRes(t,i,s,r){let n=i.sub(t),o=s.sub(t),a=n.cross(o),l=this.origin.sub(t),h=-a.dot(l),c=a.dot(this.direction);if(Math.abs(c)<ne)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 _=n.dot(n),u=n.dot(o),f=o.dot(o),g=r.sub(t),p=g.dot(n),m=g.dot(o),v=u*u-_*f,y=(u*m-f*p)/v;if(y<0||y>1)return e.OUTSIDE;let x=(u*p-_*m)/v;return x<0||y+x>1?e.OUTSIDE:e.INSIDE}hitPlaneRes(t,i){const s=this.direction.dot(t.n);if(Math.abs(s)<ne)return e.OUTSIDE;const r=t.p.sub(this.origin).dot(t.n)/s;return r<0?e.AWAY:(i.copy(this.getPoint(r)),e.INSIDE)}hitSphere(e){const t=v.sub(this.origin,e.center),i=this.direction.dot(this.direction),s=2*t.dot(this.direction),r=s*s-4*i*(t.dot(t)-e.radius*e.radius);if(r<0)return null;const n=Math.sqrt(r);let o=(-s-n)/(2*i);return o<0&&(o=(-s+n)/(2*i)),o<0?null:v.add(this.origin,this.direction.scaleTo(o))}hitBox(e){}};function js(e){let t=e.split("/"),i=t[t.length-1],s=t[t.length-2];return`${s?s+"/":""}${i}`}class Cn{constructor(){this.objPositions=[],this.objTexcoords=[],this.objNormals=[],this.objVertexData=[this.objPositions,this.objTexcoords,this.objNormals],this.vertexData=[[],[],[]],this._materialLibs=[],this.geometries=[],this.geometry=null,this.materials={},this.material={},this.object="default",this.groups=["default"],this._path="",this.keywords={v:e=>{this.objPositions.push(e.map(parseFloat))},vn:e=>{this.objNormals.push(e.map(parseFloat))},vt:e=>{this.objTexcoords.push([parseFloat(e[0]),1-parseFloat(e[1])])},f:e=>{this.setGeometry();const t=e.length-2;for(let i=0;i<t;++i)this.addVertex(e[0]),this.addVertex(e[i+1]),this.addVertex(e[i+2])},s:()=>{},mtllib:(e,t)=>{this._materialLibs.push(t)},usemtl:(e,t)=>{this.newGeometry(),this.setGeometry(),this.geometry&&(this.geometry.material=t)},g:e=>{this.groups=e,this.newGeometry()},o:(e,t)=>{this.object=t,this.newGeometry()},newmtl:(e,t)=>{const i={};this.material=i,this.materials[t]=i},Ns:(e,t)=>{this.material.shininess=parseFloat(t)},Ni:(e,t)=>{},Ka:(e,t)=>{this.material.ambient=e.map((e=>parseFloat(e)))},Kd:(e,t)=>{this.material.diffuse=e.map((e=>parseFloat(e)))},Ks:(e,t)=>{this.material.specular=e.map((e=>parseFloat(e)))},Ke:(e,t)=>{this.material.color=e.map((e=>parseFloat(e)))},illum:(e,t)=>{this.material.illum=parseFloat(t)},d:(e,t)=>{this.material.opacity=parseFloat(t)},Tr:(e,t)=>{this.material.opacity=parseFloat(t)},Tf:(e,t)=>{},map_Ka:(e,t)=>{},map_Kd:(e,t)=>{this.material.colorTexture=`${this._path}/${js(t)}`},map_Bump:(e,t)=>{this.material.normalTexture=`${this._path}/${js(t)}`},map_Ns:(e,t)=>{this.material.metallicRoughnessTexture=`${this._path}/${js(t)}`}}}newGeometry(){this.geometry&&this.geometry.data.vertices.length&&(this.geometry=null)}setGeometry(){if(!this.geometry){const e=[],t=[],i=[];this.vertexData=[e,t,i],this.geometry={object:this.object,groups:this.groups,material:"",data:{vertices:e,texCoords:t,normals:i}},this.geometries.push(this.geometry)}}addVertex(e){let t=e.split("/");for(let e=0;e<t.length;e++){let i=t[e];if(!i)continue;let s=parseInt(i)-1,r=this.vertexData[e],n=r.length,o=this.objVertexData[e][s],a=o.length;this.vertexData[e].length=n+a;for(let e=0;e<a;e++)r[n+e]=o[e]}}_innerParser(e,t){const i=/(\w*)(?: )*(.*)/,s=e.split("\n");for(let e=0;e<s.length;++e){const r=s[e].trim();if(""===r||r.startsWith("#"))continue;const n=i.exec(r);if(!n)continue;const[,o,a]=n,l=r.split(/\s+/).slice(1),h=this.keywords[o];h?h(l,a):console.warn(`Unknown keyword '${o}' in '${t}:${e}'`)}}get data(){return{geometries:this.geometries,materials:this.materials}}async load(e){this._path=e.substring(0,e.lastIndexOf("/"));const t=await fetch(e);if(!t.ok)throw new Error(`Unable to load '${e}'`);const i=t.body.getReader(),s=new TextDecoder;let{value:r,done:n}=await i.read(),o="";for(;!n;){const t=(o+s.decode(r,{stream:!0})).split("\n");o=t.pop();for(const i of t)this._innerParser(i,e);({value:r,done:n}=await i.read())}o&&this._innerParser(o,e),this._cleanupGeometryArrays();let a=this._materialLibs.map((e=>(e=`${this._path}/${e}`,fetch(e).then((e=>e.text())).then((t=>({text:t,filename:e}))))));return await Promise.all(a).then((e=>{e.forEach((e=>this._innerParser(e.text,e.filename)))})),this.data}async _readAndParse(e){const t=e.stream().getReader(),i=new TextDecoder;let{value:s,done:r}=await t.read(),n="";for(;!r;){const o=(n+i.decode(s,{stream:!0})).split("\n");n=o.pop();for(const t of o)this._innerParser(t,e.name);({value:s,done:r}=await t.read())}n&&this._innerParser(n,e.name)}async readFile(e,t){return this._path="",await this._readAndParse(e),this._cleanupGeometryArrays(),t&&await this._readAndParse(t),this.data}_cleanupGeometryArrays(){for(const e of this.geometries)e.data=Object.fromEntries(Object.entries(e.data).filter((([e,t])=>t.length>0)))}}function Ie(e){let t=new Float32Array([1,1,1]);if(e instanceof Array)t[0]=e[0],t[1]=e[1],t[2]=e[2];else if("string"==typeof e){let i=ve(e);t[0]=i[0],t[1]=i[1],t[2]=i[2]}return t}class ${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),this.color=(t=e.color)instanceof Array?new Float32Array(t):"string"==typeof t?ve(t):new Float32Array([.5,.5,.5,1]),this.ambient=Ie(e.ambient),this.diffuse=Ie(e.diffuse),this.specular=Ie(e.specular),this.shininess=e.shininess||100,this.colorTextureSrc=e.colorTextureSrc||null,this.colorTextureImage=e.colorTextureImage||null,this.normalTextureSrc=e.normalTextureSrc||null,this.normalTextureImage=e.normalTextureImage||null,this.metallicRoughnessTextureSrc=e.metallicRoughnessTextureSrc||null,this.metallicRoughnessTextureImage=e.metallicRoughnessTextureImage||null,e.scale){let t,i=e.scale;t="number"==typeof i?new v(i,i,i):i,$.scale(this._vertices,t)}if(e.center&&$.centering(this._vertices),this.center=$.getCenter(this._vertices),e.indices)this._indices=e.indices,this._normals=e.normals||[];else{this._normals=e.normals||$.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 getCenter(e){let t=xt,i=xt,s=xt,r=Ct,n=Ct,o=Ct;for(let a=0,l=e.length;a<l;a+=3){let l=e[a],h=e[a+1],c=e[a+2];l<t&&(t=l),h<i&&(i=h),c<s&&(s=c),l>r&&(r=l),h>n&&(n=h),c>o&&(o=c)}return new v(t+.5*(r-t),i+.5*(n-i),s+.5*(o-s))}static centering(e){let t=$.getCenter(e);for(let i=0,s=e.length;i<s;i+=3)e[i]-=t.x,e[i+1]-=t.y,e[i+2]-=t.z}setMaterial(e){return e.ambient&&(this.ambient=Ie(e.ambient)),e.diffuse&&(this.diffuse=Ie(e.diffuse)),e.specular&&(this.specular=Ie(e.specular)),void 0!==e.shininess&&(this.shininess=e.shininess),this}centering(){return $.centering(this._vertices),this}applyMat4(e){for(let t=0,i=this._vertices.length;t<i;t+=3){let i=new v(this._vertices[t],this._vertices[t+1],this._vertices[t+2]),s=new v(this._normals[t],this._normals[t+1],this._normals[t+2]);i=e.mulVec3(i),s=e.mulVec3(s),this._vertices[t]=i.x,this._vertices[t+1]=i.y,this._vertices[t+2]=i.z,this._normals[t]=s.x,this._normals[t+1]=s.y,this._normals[t+2]=s.z}return this}scale(e){return $.scale(this._vertices,e),this}translate(e){for(let t=0,i=this._vertices.length;t<i;t+=3)this._vertices[t]+=e.x,this._vertices[t+1]+=e.y,this._vertices[t+2]+=e.z;return this}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+=3)e[i]*=t.x,e[i+1]*=t.y,e[i+2]*=t.z}static centroid(e){let t=1e3,i=1e3,s=1e3,r=-1e3,n=-1e3,o=-1e3;for(let a=0;a<e.length;a+=3){let l=e[a],h=e[a+1],c=e[a+2];l<t&&(t=l),h<i&&(i=h),c<s&&(s=c),l>r&&(r=l),h>n&&(n=h),c>o&&(o=c)}return[t+.5*(r-t),i+.5*(n-i),s+.5*(o-s)]}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 s=i,r=i+3,n=i+6,o=e[s],a=e[s+1],l=e[s+2],h=e[r]-o,c=e[r+1]-a,d=e[r+2]-l,_=e[n]-o,u=e[n+1]-a,f=e[n+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[s]=g,t[s+1]=p,t[s+2]=m,t[r]=g,t[r+1]=p,t[r+2]=m,t[n]=g,t[n+1]=p,t[n+2]=m}return t}static createSphere(e=16,t=16,i=1,s=0,r=0,n=0){let o=[],a=[],l=[];for(let a=0;a<=t;a++){let h=a*Math.PI/t,c=Math.sin(h),d=Math.cos(h);for(let t=0;t<=e;t++){let a=2*t*Math.PI/e,h=Math.sin(a),_=Math.cos(a)*c+s,u=d+r,f=h*c+n;l.push(_),l.push(u),l.push(f),o.push(i*_),o.push(i*u),o.push(i*f)}}for(let i=0;i<t;i++)for(let t=0;t<e;t++){let s=i*(e+1)+t,r=s+e+1;a.push(s),a.push(s+1),a.push(r),a.push(r),a.push(s+1),a.push(r+1)}return new $({vertices:o,normals:l,indices:a})}static createDisc(e=1,t=0,i=8,s=!0,r=0,n=0,o=0,a=0){let l=[],h=[],c=[],d=2*Math.PI,_=s?1:-1,u=r;for(let e=1;e<=i;e++)l.push(n,t*_+o,a),c.push(0,_,0),r++;let f=r;for(let s=0;s<=i;s++){let h=s/i*d+0,u=Math.cos(h),f=Math.sin(h);l.push(e*f+n,t*_+o,e*u+a),c.push(0,_,0),r++}for(let e=0;e<i;e++){let t=u+e,i=f+e;s?h.push(i,i+1,t):h.push(i+1,i,t)}return new $({vertices:l,normals:c,indices:h})}static getFrustumScaleByCameraAngles(e,t,i){return new v(2*e*Math.tan(Qt*t),2*e*Math.tan(Qt*i),e)}static getFrustumScaleByCameraAspectRatio(e,t,i){let s=Gr*Math.atan(Math.tan(Qt*t)/i);return $.getFrustumScaleByCameraAngles(e,t,s)}static createFrustum(e=1,t=1,i=1,s=0,r=0,n=0){return new $({vertices:[0+s,0+r,0+n,-1*(t*=.5)+s,1*(i*=.5)+r,-1*e+n,1*t+s,1*i+r,-1*e+n,0+s,0+r,0+n,1*t+s,-1*i+r,-1*e+n,-1*t+s,-1*i+r,-1*e+n,0+s,0+r,0+n,1*t+s,1*i+r,-1*e+n,1*t+s,-1*i+r,-1*e+n,0+s,0+r,0+n,-1*t+s,-1*i+r,-1*e+n,-1*t+s,1*i+r,-1*e+n,0+s,0+r,0+n,1*t+s,1*i+r,-1*e+n,-1*t+s,1*i+r,-1*e+n,0+s,0+r,0+n,-1*t+s,-1*i+r,-1*e+n,1*t+s,-1*i+r,-1*e+n,0+s,0+r,0+n,1*t+s,-1*i+r,-1*e+n,1*t+s,1*i+r,-1*e+n,0+s,0+r,0+n,-1*t+s,1*i+r,-1*e+n,-1*t+s,-1*i+r,-1*e+n]})}static createCylinder(e=1,t=1,i=1,s=32,r=1,n=!0,o=!0,a=0,l=0,h=0){let c=[],d=[],_=[],u=2*Math.PI,f=0,g=[],p=new v,m=(t-e)/i;for(let n=0;n<=r;n++){let o=[],d=n/r,v=d*(t-e)+e;for(let e=0;e<=s;e++){let t=e/s*u+0,r=Math.sin(t),n=Math.cos(t);c.push(v*r+a,-d*i+i+l,v*n+h),p.set(r,m,n).normalize(),_.push(p.x,p.y,p.z),o.push(f++)}g.push(o)}for(let e=0;e<s;e++)for(let t=0;t<r;t++){let i=g[t][e],s=g[t+1][e],r=g[t+1][e+1],n=g[t][e+1];d.push(i,s,n),d.push(s,r,n)}if(0!==e&&n){let t=$.createDisc(e,i,s,!0,f,a,l,h);c.push(...t.vertices),_.push(...t.normals),d.push(...t.indices)}if(0!==t&&o){let e=$.createDisc(t,0,s,!1,f+(n?1+2*s:0),a,l,h);c.push(...e.vertices),_.push(...e.normals),d.push(...e.indices)}return new $({vertices:c,normals:_,indices:d})}static createCube(e=1,t=1,i=1,s=0,r=0,n=0){let o=.5*e+s,a=.5*t+r,l=.5*i+n;return new $({vertices:[-o,-a,l,o,-a,-l,o,-a,l,-o,-a,l,-o,-a,-l,o,-a,-l,-o,a,l,o,a,l,o,a,-l,-o,a,l,o,a,-l,-o,a,-l,-o,-a,l,o,-a,l,-o,a,l,-o,a,l,o,-a,l,o,a,l,-o,-a,-l,-o,a,-l,o,-a,-l,-o,a,-l,o,a,-l,o,-a,-l,o,-a,l,o,-a,-l,o,a,l,o,a,l,o,-a,-l,o,a,-l,-o,-a,l,-o,a,l,-o,-a,-l,-o,a,l,-o,a,-l,-o,-a,-l]})}static createPlane(e=1,t=1,i=0,s=0,r=0){let n=.5*e,o=.5*t;return new $({vertices:[-n+i,s,o+r,n+i,s,-o+r,n+i,s,o+r,-n+i,s,o+r,-n+i,s,-o+r,n+i,s,-o+r,-n+i,s,o+r,n+i,s,o+r,n+i,s,-o+r,-n+i,s,o+r,n+i,s,-o+r,-n+i,s,-o+r]})}static createArrow(e=0,t=2.1,i=-15){return new $({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 readFileObj(e,t,i){const s=await(new Cn).readFile(e,t);let r=s.materials;return s.geometries.map((e=>{let t=r[e.material]||{};return new $({name:e.object,vertices:e.data.vertices,normals:e.data.normals,texCoords:e.data.texCoords,ambient:t.ambient,diffuse:t.diffuse,specular:t.specular,shininess:t.shininess,color:t.color,colorTextureSrc:i?`${i}/${t.colorTexture}`:t.colorTexture,normalTextureSrc:i?`${i}/${t.normalTexture}`:t.normalTexture,metallicRoughnessTextureSrc:i?`${i}/${t.metallicRoughnessTexture}`:t.metallicRoughnessTexture})}))}static async loadObj(e){const t=await(new Cn).load(e);let i=t.materials;return t.geometries.map((e=>{let t=i[e.material]||{};return new $({name:e.object,vertices:e.data.vertices,normals:e.data.normals,texCoords:e.data.texCoords,ambient:t.ambient,diffuse:t.diffuse,specular:t.specular,shininess:t.shininess,color:t.color,colorTextureSrc:t.colorTexture,normalTextureSrc:t.normalTexture,metallicRoughnessTextureSrc:t.metallicRoughnessTexture})}))}merge(e){const t=this._vertices.length/3;let i=this._vertices.length;this._vertices.length=i+e._vertices.length;for(let t=0;t<e._vertices.length;t++)this._vertices[i+t]=e._vertices[t];i=this._normals.length,this._normals.length=i+e._normals.length;for(let t=0;t<e._normals.length;t++)this._normals[i+t]=e._normals[t];i=this._texCoords.length,this._texCoords.length=i+e._texCoords.length;for(let t=0;t<e._texCoords.length;t++)this._texCoords[i+t]=e._texCoords[t];i=this._indices.length,this._indices.length=i+e._indices.length;for(let s=0;s<e._indices.length;s++)this._indices[i+s]=e._indices[s]+t;return this._numVertices=this._vertices.length/3,this}static merge(e,t){let i=new $,s=t||e.length;for(let t=0;t<s;t++)i.merge(e[t]);return i}}const tl=new v(0,0,-1),gs=class e{constructor(t){var i,s;this._handlerIndex=-1,this._tag=t.tag||"tag_"+e.__counter__++,this._entity=null,this._position=Yt(t.position),this._rtcPositionHigh=new v,this._rtcPositionLow=new v,this._scale=Yt(t.scale,new v(1,1,1)),this._translate=Yt(t.translate,new v),this._localPosition=new v;const[r=.15,n=.15,o=.15,a=1]=null!=(i=t.object3d)&&i.color?Array.from(t.object3d.color):[];this._color=le(t.color,new et(r,n,o,a)),this._handler=null,this._handlerIndex=-1,this._tagData=null,this._tagDataIndex=-1;let l=t.object3d;t.object3d&&0!==(null==(s=t.object3d)?void 0:s.vertices.length)||(l=new $),t.objSrc&&(this.setObjectSrc(t.objSrc),this._objectSrc=t.objSrc),this._object3d=l,this._visibility=null==t.visibility||t.visibility,this._children=[],this._direction=new v,this._qFrame=new F,this._qRot=F.IDENTITY}get tag(){return this._tag}getPosition(){return this._position}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)}getOpacity(){return this._color.w}setColor(e,t,i,s){this._color.x=e,this._color.y=t,this._color.z=i,null!=s&&(this._color.w=s),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,this.updateRTCPosition(),this.updateRotation()}updateRTCPosition(){this._handler&&(this._handler.getRTCPosition(this._position,this._rtcPositionHigh,this._rtcPositionLow),this._handler.setRTCPositionArr(this._tagData,this._tagDataIndex,this._rtcPositionHigh,this._rtcPositionLow))}setPosition3v(e){this.setPosition(e.x,e.y,e.z)}setObject(e){this._object3d=e}setObjectSrc(e){this._objectSrc=e,this._handler&&this._handler.setObjectSrc(e,this.tag)}setColorHTML(e){this.setColor4v(he(e))}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}setTranslate3v(e){this._translate.copy(e),this._handler&&this._handler.setTranslateArr(this._tagData,this._tagDataIndex,e)}getTranslate(){return this._translate.clone()}setLocalPosition3v(e){this._localPosition.copy(e),this._handler&&this._handler.setLocalPositionArr(this._tagData,this._tagDataIndex,e)}getLocalPosition(){return this._localPosition.clone()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._tagData,this._tagDataIndex,e)}setRotation(e){this._qRot.copy(e),this._qRot.mulVec3Res(tl,this._direction).normalize(),this.updateRotation()}getRotation(){return this._qRot}updateRotation(){this._handler&&this._handler.setQRotArr(this._tagData,this._tagDataIndex,this._qRot)}getDirection(){return this._direction.clone()}};gs.__counter__=0;let yr=gs;const _i={RIGHT:0,LEFT:1,CENTER:2},En={left:_i.LEFT,right:_i.RIGHT,center:_i.CENTER};class el extends rs{constructor(e={}){super(e),this._handler=null,this._text=e.text||"",this._face=Bo(e.face,"arial"),this._size=e.size||24,this._outline=null!=e.outline?e.outline:0,this._outlineColor=le(e.outlineColor,new et(0,0,0,1)),this._align=e.align&&En[e.align.trim().toLowerCase()]||_i.RIGHT,this._fontIndex=0,this._fontAtlas=null,this._isRTL=e.isRTL||!1,this._letterSpacing=e.letterSpacing||0}setText(e){this._text=e.toString(),this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,e,this._fontIndex,this._align,this._letterSpacing,this._isRTL)}setLetterSpacing(e){this._letterSpacing=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,e,this._isRTL)}getLetterSpacing(){return this._letterSpacing}setRtl(e){this._isRTL=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL)}getText(){return this._text}setAlign(e){this._align=En[e.trim().toLowerCase()],this._isReady&&this._handler?this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL):-1!==this._lockId&&(this._lockId=-2)}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):-1!==this._lockId&&(this._lockId=-2))}getSize(){return this._size}setOutline(e){this._outline=e,this._isReady&&this._handler?this._handler.setOutlineArr(this._handlerIndex,e):-1!==this._lockId&&(this._lockId=-2)}getOutline(){return this._outline}setOpacity(e){super.setOpacity(e),this.setOutlineOpacity(e)}setOutlineColor(e,t,i,s){s===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=s,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):-1!==this._lockId&&(this._lockId=-2))}setOutlineColor4v(e){this.setOutlineColor(e.x,e.y,e.z,e.w)}setOutlineColorHTML(e){this.setOutlineColor4v(he(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):-1!==this._lockId&&(this._lockId=-2))}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._letterSpacing,this._isRTL)):-1!==this._lockId&&(this._lockId=-2)}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}}const ps=class e{constructor(t={}){this.__id=e.__counter__++,this.visibility=null==t.visibility||t.visibility,this.pointSize=t.pointSize||3,this.pickingScale=t.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),t.points&&this.setPoints(t.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],s=new v(i[0],i[1],i[2]),r=new et(i[3],i[4],i[5],null==i[6]?255:i[6]);this._coordinatesData.push(s.x,s.y,s.z),this._colorData.push(r.x/255,r.y/255,r.z/255,r.w/255);let n={_entity:this._entity,_pickingColor:new v,_entityCollection:this._entity?this._entity._entityCollection:null,index:t,position:s,color:r,pointCloud:this,properties:i[7]||{}};this._points.push(n),this._renderNode&&this._renderNode.renderer&&(this._renderNode.renderer.assignPickingColor(n),this._pickingColorData.push(n._pickingColor.x/255,n._pickingColor.y/255,n._pickingColor.z/255,1))}this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}setPointPosition(e,t,i,s){this._changedBuffers[0]=!0}setPointColor(e,t,i,s,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,s=e.handler.gl,r=i.attributes,n=i.uniforms;t.activate(),s.uniformMatrix4fv(n.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),s.uniform1f(n.opacity,this._handler._entityCollection._fadingOpacity),s.uniform1f(n.pointSize,this.pointSize),s.bindBuffer(s.ARRAY_BUFFER,this._coordinatesBuffer),s.vertexAttribPointer(r.coordinates,this._coordinatesBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._colorBuffer),s.vertexAttribPointer(r.colors,this._colorBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.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,s=e.handler.gl,r=i.attributes,n=i.uniforms;t.activate(),s.uniformMatrix4fv(n.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),s.uniform1f(n.opacity,this._handler._entityCollection._fadingOpacity),s.uniform1f(n.pointSize,this.pointSize+this.pickingScale),s.bindBuffer(s.ARRAY_BUFFER,this._coordinatesBuffer),s.vertexAttribPointer(r.coordinates,this._coordinatesBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._pickingColorBuffer),s.vertexAttribPointer(r.colors,this._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.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}}};ps.__counter__=0;let xr=ps;const qe=class e{constructor(t={}){this.__id=e.__counter__++,this.__doubleToTwoFloats=v.doubleToTwoFloats,this.altitude=t.altitude||0,this.thickness=t.thickness||1.5,this._opacity=null!=t.opacity?t.opacity:1,this._defaultColor=ve(t.color||"#0000FF",t.opacity),this.visibility=null==t.visibility||t.visibility,this._closedLine=t.isClosed||!1,this._path3v=[],this._pathLengths=[],this._pathLonLat=[],this._pathLonLatMerc=[],this._pathColors=t.pathColors?Qr(t.pathColors):[],this._extent=new U,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._texCoordArr=[],this._atlasTexCoords=[],this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null,this._texCoordBuffer=null,this._pickingColor=[0,0,0],this._renderNode=null,this._entity=null,this._handler=null,this._handlerIndex=-1,this._image=t.image||null,this._src=t.src||null,this._texOffset=t.texOffset||0,this._strokeSize=null!=t.strokeSize?t.strokeSize:32,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createVerticesBuffer,this._buffersUpdateCallbacks[1]=this._createIndexBuffer,this._buffersUpdateCallbacks[2]=this._createColorsBuffer,this._buffersUpdateCallbacks[3]=this._createTexCoordBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length);let i=Yt(t.visibleSpherePosition).toArray(),s=t.visibleSphereRadius||0;this._visibleSphere=new Float32Array([...i,s]),t.pathLonLat?this.setPathLonLat(t.pathLonLat):t.path3v&&this.setPath3v(t.path3v),this._refresh()}get texOffset(){return this._texOffset}set texOffset(e){this._texOffset=e}get strokeSize(){return this._strokeSize}set strokeSize(e){this._strokeSize=e}setSrc(e){this._src=e;let t=this._handler;if(t){let i=t._entityCollection.renderNode;if(i&&i.renderer){let t=i.renderer.strokeTextureAtlas;e&&e.length?t.loadImage(e,(e=>{if(null!=e.__nodeIndex&&t.get(e.__nodeIndex)){this._image=e;let i=t.get(e.__nodeIndex);this._setTexCoordArr(i.texCoords)}else t.addImage(e),t.createTexture(),this._image=e,i.updateStrokeTexCoords()})):(this.setTextureDisabled(),i.updateStrokeTexCoords())}}}getSrc(){return this._src}setImage(e){this.setSrc(e.src)}getImage(){return this._image}_setTexCoordArr(t){this._texCoordArr=[],this._atlasTexCoords=t,e.setPathTexCoords(this._path3v,t,this._texCoordArr),this._changedBuffers[3]=!0}setTextureDisabled(){this._strokeSize=0}__appendLineData3v(e,t,i,s,r,n,o,a,l,h,c,d,_,u){var f=0,g=new v,p=new v;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),a.length>0?(f=a[a.length-5]+9,a.push(f,f)):a.push(0,0);for(let L=0,P=e.length;L<P;L++){var m=e[L],y=t[L];if(h[L]=[],d[L]=[],c[L]=[],0===m.length)continue;var x,b=f;if(s)(x=m[m.length-1])instanceof Array&&(x=new v(x[0],x[1],x[2]));else{var w=m[0],T=m[1]||w;w instanceof Array&&(w=new v(w[0],w[1],w[2])),T instanceof Array&&(T=new v(T[0],T[1],T[2])),x=new v(w.x+w.x-T.x,w.y+w.y-T.y,w.z+w.z-T.z)}let P=i;y&&y[0]&&(P=y[0]),this.__doubleToTwoFloats(x,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),n.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 S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1;L>0&&u.push(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.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 v(C[0],C[1],C[2])),c[L].push(C),l){var E=l.cartesianToLonLat(C);h[L].push(E),d[L].push(E.forwardMercator()),E.lon<_.southWest.lon&&(_.southWest.lon=E.lon),E.lat<_.southWest.lat&&(_.southWest.lat=E.lat),E.lon>_.northEast.lon&&(_.northEast.lon=E.lon),E.lat>_.northEast.lat&&(_.northEast.lat=E.lat)}y&&y[e]&&(P=y[e]),S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1,this.__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),n.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(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),a.push(f++,f++,f++,f++)}var A;if(s)(A=m[0])instanceof Array&&(A=new v(A[0],A[1],A[2])),a.push(b,b+1,b+1,b+1);else{let e=m[m.length-1],t=m[m.length-2]||e;e instanceof Array&&(e=new v(e[0],e[1],e[2])),t instanceof Array&&(t=new v(t[0],t[1],t[2])),A=new v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),a.push(f-1,f-1,f-1,f-1)}y&&y[m.length-1]&&(P=y[m.length-1]),S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1,this.__doubleToTwoFloats(A,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),n.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(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),L<e.length-1&&0!==e[L+1].length&&(f+=8,a.push(f,f))}}__appendPoint3v(e,t,i,s,r,n,o,a,l,h,c,d,_,u){var f=new v,g=new v,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 y=e[e.length-1],x=y.length;y.push(t);let b=s[0],w=s[1],T=s[2],C=null!=s[3]?s[3]:1,E=i[e.length-1];if(E[x]?(E[x][0]=b,E[x][1]=w,E[x][2]=T,E[x][3]=C):E.push(s),1===x){var A;if(r)(A=y[x-1])instanceof Array&&(A=new v(A[0],A[1],A[2]));else{let e=y[0],t=y[1]||e;e instanceof Array&&(e=new v(e[0],e[1],e[2])),t instanceof Array&&(t=new v(t[0],t[1],t[2])),A=new v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(A,f,g);let e=n.length-36;n[e]=f.x,n[e+1]=f.y,n[e+2]=f.z,n[e+3]=f.x,n[e+4]=f.y,n[e+5]=f.z,n[e+6]=f.x,n[e+7]=f.y,n[e+8]=f.z,n[e+9]=f.x,n[e+10]=f.y,n[e+11]=f.z,o[e]=g.x,o[e+1]=g.y,o[e+2]=g.z,o[e+3]=g.x,o[e+4]=g.y,o[e+5]=g.z,o[e+6]=g.x,o[e+7]=g.y,o[e+8]=g.z,o[e+9]=g.x,o[e+10]=g.y,o[e+11]=g.z}var L=m;if(c){0===d.length&&d.push([]),0===_.length&&_.push([]);var P=d[d.length-1],S=_[_.length-1];let e=c.cartesianToLonLat(t);P.push(e),S.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)}this.__doubleToTwoFloats(t,f,g);let R=n.length-12;n[R]=f.x,n[R+1]=f.y,n[R+2]=f.z,n[R+3]=f.x,n[R+4]=f.y,n[R+5]=f.z,n[R+6]=f.x,n[R+7]=f.y,n[R+8]=f.z,n[R+9]=f.x,n[R+10]=f.y,n[R+11]=f.z,o[R]=g.x,o[R+1]=g.y,o[R+2]=g.z,o[R+3]=g.x,o[R+4]=g.y,o[R+5]=g.z,o[R+6]=g.x,o[R+7]=g.y,o[R+8]=g.z,o[R+9]=g.x,o[R+10]=g.y,o[R+11]=g.z;let M=a.length-16;var B;if(a[M]=b,a[M+1]=w,a[M+2]=T,a[M+3]=C,a[M+4]=b,a[M+5]=w,a[M+6]=T,a[M+7]=C,a[M+8]=b,a[M+9]=w,a[M+10]=T,a[M+11]=C,a[M+12]=b,a[M+13]=w,a[M+14]=T,a[M+15]=C,h[p]=m++,h[p+1]=m++,h[p+2]=m++,h[p+3]=m++,r)B=y[0],h.push(L,L+1,L+1,L+1);else{let e=y[y.length-1],t=y[y.length-2]||e;B=new v(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)}this.__doubleToTwoFloats(B,f,g),n.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),o.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),a.push(b,w,T,C,b,w,T,C,b,w,T,C,b,w,T,C),l.push(1,-1,2,-2)}static setPathTexCoords(e,t,i){let s=t[1],r=t[3]-s,n=new H(t[4],t[5]),o=new H(t[2],t[3]),a=new H(t[8],t[9]),l=new H(t[0],t[1]);for(let t=0,c=e.length;t<c;t++){var h=e[t];if(0!==h.length){t>0&&i.push(n.x,n.y,s,r,o.x,o.y,s,r,a.x,a.y,s,r,l.x,l.y,s,r);for(let e=0,t=h.length;e<t;e++)i.push(n.x,n.y,s,r,o.x,o.y,s,r,a.x,a.y,s,r,l.x,l.y,s,r);i.push(n.x,n.y,s,r,o.x,o.y,s,r,a.x,a.y,s,r,l.x,l.y,s,r)}}}static setPathColors(e,t,i,s){for(let o=0,a=e.length;o<a;o++){var r=e[o],n=t[o];if(0===r.length)continue;let a=i;n&&n[0]&&(a=n[0]);let l=a[0],h=a[1],c=a[2],d=null!=a[3]?a[3]:1;o>0&&s.push(l,h,c,d,l,h,c,d,l,h,c,d,l,h,c,d);for(let e=0,t=r.length;e<t;e++)n&&n[e]&&(a=n[e]),l=a[0],h=a[1],c=a[2],d=null!=a[3]?a[3]:1,s.push(l,h,c,d,l,h,c,d,l,h,c,d,l,h,c,d);n&&n[r.length-1]&&(a=n[r.length-1]),l=a[0],h=a[1],c=a[2],d=null!=a[3]?a[3]:1,s.push(l,h,c,d,l,h,c,d,l,h,c,d,l,h,c,d)}}__appendLineDataLonLat(e,t,i,s,r,n,o,a,l,h,c,d,_,u,f){var g=0,p=new v,m=new v;u&&(u.southWest.set(180,90),u.northEast.set(-180,-90)),a.length>0?(g=a[a.length-5]+9,a.push(g)):a.push(0);for(let A=0,P=e.length;A<P;A++){var y=e[A],x=t[A];if(c[A]=[],_[A]=[],d[A]=[],0===y.length)continue;var b,w=g;if(s){let e=y[y.length-1];b=e instanceof Array?h.lonLatToCartesian(new L(e[0],e[1],e[2])):h.lonLatToCartesian(e)}else{let e,t,i=y[0];e=i instanceof Array?h.lonLatToCartesian(new L(i[0],i[1],i[2])):h.lonLatToCartesian(i),i=y[1],i||(i=y[0]),t=i instanceof Array?h.lonLatToCartesian(new L(i[0],i[1],i[2])):h.lonLatToCartesian(i),b=new v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}let P=i;x&&x[0]&&(P=x[0]),this.__doubleToTwoFloats(b,p,m),r.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),n.push(m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z);let S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1;A>0&&f.push(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),l.push(0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0);for(let e=0,t=y.length;e<t;e++){var T=y[e];T instanceof Array&&(T=new L(T[0],T[1],T[2])),x&&x[e]&&(P=x[e]),S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1;var C=h.lonLatToCartesian(T);c[A].push(C),d[A].push(T),_[A].push(T.forwardMercator()),this.__doubleToTwoFloats(C,p,m),r.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),n.push(m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z),f.push(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),a.push(g++,g++,g++,g++),l.push(0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0),T.lon<u.southWest.lon&&(u.southWest.lon=T.lon),T.lat<u.southWest.lat&&(u.southWest.lat=T.lat),T.lon>u.northEast.lon&&(u.northEast.lon=T.lon),T.lat>u.northEast.lat&&(u.northEast.lat=T.lat)}var E;if(s){let e=y[0];E=e instanceof Array?h.lonLatToCartesian(new L(e[0],e[1],e[2])):h.lonLatToCartesian(e),a.push(w,w+1,w+1,w+1)}else{let e,t,i=y[y.length-1];e=i instanceof Array?h.lonLatToCartesian(new L(i[0],i[1],i[2])):h.lonLatToCartesian(i),i=y[y.length-2],i||(i=y[0]),t=i instanceof Array?h.lonLatToCartesian(new L(i[0],i[1],i[2])):h.lonLatToCartesian(i),E=new v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),a.push(g-1,g-1,g-1,g-1)}x&&x[y.length-1]&&(P=x[y.length-1]),S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1,this.__doubleToTwoFloats(E,p,m),r.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),n.push(m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z),f.push(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),l.push(0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0),A<e.length-1&&0!==e[A+1].length&&(g+=8,a.push(g,g))}}_setEqualPath3v(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new v,s=new v,r=this._verticesHigh,n=this._verticesLow,o=this._pathLonLat,a=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 v(_[0].x+_[0].x-_[1].x,_[0].y+_[0].y-_[1].y,_[0].z+_[0].z-_[1].z),this.__doubleToTwoFloats(c,i,s),r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.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,o[m][e]=g,a[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)}this.__doubleToTwoFloats(u,i,s),r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z}if(this._closedLine)d=_[0];else{var p=_.length-1;d=new v(_[p].x+_[p].x-_[p-1].x,_[p].y+_[p].y-_[p-1].y,_[p].z+_[p].z-_[p-1].z)}this.__doubleToTwoFloats(d,i,s),r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z}}_setEqualPathLonLat(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new v,s=new v,r=this._verticesHigh,n=this._verticesLow,o=this._pathLonLat,a=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 v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(d,i,s),r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z;for(let e=0;e<u.length;e++){var f=u[e],g=c.lonLatToCartesian(f);l[p][e]=g,a[p][e]=f.forwardMercator(),o[p][e]=f,this.__doubleToTwoFloats(g,i,s),r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.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 v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(_,i,s),r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z}}setPointLonLat(e,t,i){if(this._renderNode&&this._renderNode.ellipsoid){let a=this._pathLonLat,l=this._pathLonLatMerc;a[i][t]=e,l[i][t]=e.forwardMercator();var s=this._extent;s.southWest.set(180,90),s.northEast.set(-180,-90);for(let e=0;e<a.length;e++){var r=a[e];for(let e=0;e<r.length;e++){var n=r[e].lon,o=r[e].lat;n>s.northEast.lon&&(s.northEast.lon=n),o>s.northEast.lat&&(s.northEast.lat=o),n<s.southWest.lon&&(s.southWest.lon=n),o<s.southWest.lat&&(s.southWest.lat=o)}}this.setPoint3v(this._renderNode.ellipsoid.lonLatToCartesian(e),t,i,!0)}else{let s=this._pathLonLat[i];s[t].lon=e.lon,s[t].lat=e.lat,s[t].height=e.height}}setPoint3v(e,t=0,i=0,s=!1){if(this._renderNode){var r,n=new v,o=new v,a=this._verticesHigh,l=this._verticesLow,h=this._pathLonLat,c=this._pathLonLatMerc,d=0;r=12*this._pathLengths[i]+24*i;let b=this._path3v[i];b[t].x=e.x,b[t].y=e.y,b[t].z=e.z;let w=this._closedLine||1===b.length;var _;if((0===t||1===t)&&(_=w?b[b.length-1]:new v(b[0].x+b[0].x-b[1].x,b[0].y+b[0].y-b[1].y,b[0].z+b[0].z-b[1].z),d=r,this.__doubleToTwoFloats(_,n,o),a[d]=n.x,a[d+1]=n.y,a[d+2]=n.z,a[d+3]=n.x,a[d+4]=n.y,a[d+5]=n.z,a[d+6]=n.x,a[d+7]=n.y,a[d+8]=n.z,a[d+9]=n.x,a[d+10]=n.y,a[d+11]=n.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z),!s&&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,this.__doubleToTwoFloats(e,n,o),a[d]=n.x,a[d+1]=n.y,a[d+2]=n.z,a[d+3]=n.x,a[d+4]=n.y,a[d+5]=n.z,a[d+6]=n.x,a[d+7]=n.y,a[d+8]=n.z,a[d+9]=n.x,a[d+10]=n.y,a[d+11]=n.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z,t===b.length-1||t===b.length-2){var y;if(w)y=b[0];else{var x=b.length-1;y=new v(b[x].x+b[x].x-b[x-1].x,b[x].y+b[x].y-b[x-1].y,b[x].z+b[x].z-b[x-1].z)}d=r+12*b.length+12,this.__doubleToTwoFloats(y,n,o),a[d]=n.x,a[d+1]=n.y,a[d+2]=n.z,a[d+3]=n.x,a[d+4]=n.y,a[d+5]=n.z,a[d+6]=n.x,a[d+7]=n.y,a[d+8]=n.z,a[d+9]=n.x,a[d+10]=n.y,a[d+11]=n.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z}this._changedBuffers[0]=!0}else{let s=this._path3v[i];s[t].x=e.x,s[t].y=e.y,s[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,s=0){let r=[].concat(this._path3v),n=r[s];if(n){let o=[].concat(this._pathColors);if(n.splice(t,0,e),i){let e=o[s];e||(e=new Array(n.length)),e.splice(t,0,i)}this.setPath3v(r,o)}else this.addPoint3v(e,s)}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),this.__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 s=this._pathColors[i];if(!s){if(!(this._path3v[i]&&t<this._path3v[i].length))return;this._pathColors[i]=new Array(this._path3v[i].length)}s[t]?(s[t][0]=e[0],s[t][1]=e[1],s[t][2]=e[2],s[t][3]=e[3]||1):s[t]=[e[0],e[1],e[2],e[3]||1];let r=this._colors,n=16*t+16*this._pathLengths[i]+32*i;r[n]=r[n+4]=r[n+8]=r[n+12]=e[0],r[n+1]=r[n+5]=r[n+9]=r[n+13]=e[1],r[n+2]=r[n+6]=r[n+10]=r[n+14]=e[2],r[n+3]=r[n+7]=r[n+11]=r[n+15]=e[3]||1,this._changedBuffers[2]=!0}else this._pathColors[i][t]=e}setOpacity(e){this._opacity=e}getOpacity(){return this._opacity}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._texCoordArr=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._texCoordArr=[],this._path3v.length=0,this._pathLonLat.length=0,this._pathLonLatMerc.length=0,this._path3v=[],this._pathLonLat=[],this._pathLonLatMerc=[]}_createData3v(e){this._clearData(),this.__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(),this.__appendLineDataLonLat(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._texCoordArr,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._texCoordArr=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._texCoordArr=[],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(t){t&&(this._colors=[],this._pathColors=[].concat(t),e.setPathColors(this._pathLonLat,t,this._defaultColor,this._colors),this._changedBuffers[2]=!0)}setColorHTML(e){this._defaultColor=ve(e);let t=he(e),i=this._pathColors;for(let e=0,s=i.length;e<s;e++){let s=i[e];for(let e=0,i=s.length;e<i;e++)s[e][0]=t.x,s[e][1]=t.y,s[e][2]=t.z,s[e][3]=t.w}let s=this._colors;for(let e=0,i=s.length;e<i;e+=4)s[e]=t.x,s[e+1]=t.y,s[e+2]=t.z,s[e+3]=t.w;this._changedBuffers[2]=!0}setPathLonLatFast(e,t){this.setPathLonLat(e,t,!0)}setPath3vFast(e,t){this.setPath3v(e,t,!0)}setPathLonLat(e,t,i=!1){t&&(this._pathColors=[].concat(t)),this._renderNode&&this._renderNode.ellipsoid?i?(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)}getSize(e=0){return this._path3v[e].length}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.renderer,t=e.handler.programs.polyline_screen,i=t._program,s=e.handler.gl,r=i.attributes,n=i.uniforms,o=this._handler._entityCollection;t.activate(),s.disable(s.CULL_FACE),s.uniform1f(n.depthOffset,o.polygonOffsetUnits),s.uniformMatrix4fv(n.proj,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(n.view,!1,e.activeCamera.getViewMatrix()),s.uniform3fv(n.rtcEyePositionHigh,this._handler._rtcEyePositionHigh),s.uniform3fv(n.rtcEyePositionLow,this._handler._rtcEyePositionLow),s.uniform4fv(n.visibleSphere,this._visibleSphere),s.uniform2fv(n.viewport,[e.handler.canvas.width,e.handler.canvas.height]),s.uniform1f(n.thickness,.5*this.thickness),s.uniform1f(n.opacity,this._opacity*o._fadingOpacity),s.uniform1f(n.texOffset,this._texOffset),s.uniform1f(n.strokeSize,this._strokeSize),s.bindBuffer(s.ARRAY_BUFFER,this._colorsBuffer),s.vertexAttribPointer(r.color,this._colorsBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._texCoordBuffer),s.vertexAttribPointer(r.texCoord,this._texCoordBuffer.itemSize,s.FLOAT,!1,0,0);let a=this._verticesHighBuffer;s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(r.prevHigh,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(r.currentHigh,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(r.nextHigh,a.itemSize,s.FLOAT,!1,12,96),a=this._verticesLowBuffer,s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(r.prevLow,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(r.currentLow,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(r.nextLow,a.itemSize,s.FLOAT,!1,12,96),s.bindBuffer(s.ARRAY_BUFFER,this._ordersBuffer),s.vertexAttribPointer(r.order,this._ordersBuffer.itemSize,s.FLOAT,!1,4,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexesBuffer.numItems,s.UNSIGNED_INT,0),s.enable(s.CULL_FACE)}}drawPicking(){if(this.visibility&&this._path3v.length){let e=this._renderNode.renderer,t=e.handler.programs.polyline_picking,i=t._program,s=e.handler.gl,r=i.attributes,n=i.uniforms,o=this._handler._entityCollection;t.activate(),s.disable(s.CULL_FACE),s.uniform1f(n.depthOffset,o.polygonOffsetUnits),s.uniformMatrix4fv(n.proj,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(n.view,!1,e.activeCamera.getViewMatrix()),s.uniform4fv(n.color,[this._pickingColor[0],this._pickingColor[1],this._pickingColor[2],1]),s.uniform3fv(n.rtcEyePositionHigh,this._handler._rtcEyePositionHigh),s.uniform3fv(n.rtcEyePositionLow,this._handler._rtcEyePositionLow),s.uniform4fv(n.visibleSphere,this._visibleSphere),s.uniform2fv(n.viewport,[e.handler.canvas.width,e.handler.canvas.height]),s.uniform1f(n.thickness,.5*this.thickness*o.pickingScale[0]);let a=this._verticesHighBuffer;s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(r.prevHigh,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(r.currentHigh,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(r.nextHigh,a.itemSize,s.FLOAT,!1,12,96),a=this._verticesLowBuffer,s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(r.prevLow,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(r.currentLow,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(r.nextLow,a.itemSize,s.FLOAT,!1,12,96),s.bindBuffer(s.ARRAY_BUFFER,this._ordersBuffer),s.vertexAttribPointer(r.order,this._ordersBuffer.itemSize,s.FLOAT,!1,4,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexesBuffer.numItems,s.UNSIGNED_INT,0),s.enable(s.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),e.deleteBuffer(this._texCoordBuffer),this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null,this._texCoordBuffer=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=st(this._verticesHigh),this._verticesLow=st(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=st(this._orders),this._ordersBuffer=e.createArrayBuffer(this._orders,1,this._orders.length/2),this._indexes=st(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=st(this._colors),this._colorsBuffer=e.createArrayBuffer(this._colors,4,this._colors.length/4)}_createTexCoordBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordArr=st(this._texCoordArr),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,4,this._texCoordArr.length/4)}setVisibleSphere(e,t){this._handler&&(this._visibleSphere[0]=e.x-this._handler._relativeCenter.x,this._visibleSphere[1]=e.y-this._handler._relativeCenter.y,this._visibleSphere[2]=e.z-this._handler._relativeCenter.z),this._visibleSphere[3]=t}updateRTCPosition(){this._handler&&this._renderNode&&(this._visibleSphere[0]=this._visibleSphere[0]-this._handler._relativeCenter.x,this._visibleSphere[1]=this._visibleSphere[1]-this._handler._relativeCenter.y,this._visibleSphere[2]=this._visibleSphere[2]-this._handler._relativeCenter.z,this._setEqualPath3v(this._path3v)),this._changedBuffers[0]=!0}};qe.__counter__=0;let br=qe;const ms=class e{constructor(t={}){this.__id=e.__counter__++,this._thickness=t.thickness||2,this._startPosition=Yt(t.startPosition),this._startPositionHigh=new v,this._startPositionLow=new v,v.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._endPosition=Yt(t.endPosition),this._endPositionHigh=new v,this._endPositionLow=new v,v.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._startColor=le(t.startColor),this._endColor=le(t.endColor),this._visibility=null==t.visibility||t.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1,this._image=t.image||null,this._src=t.src||null,this._texOffset=t.texOffset||0,this._strokeSize=null!=t.strokeSize?t.strokeSize:32}setStartPosition(e,t,i){this._startPosition.x=e,this._startPosition.y=t,this._startPosition.z=i,v.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)}setSrc(e){this._src=e;let t=this._handler;if(t){let i=t._entityCollection.renderNode;if(i&&i.renderer){let s=i.renderer.strokeTextureAtlas;e&&e.length?s.loadImage(e,(e=>{if(null!=e.__nodeIndex&&s.get(e.__nodeIndex)){this._image=e;let i=s.get(e.__nodeIndex);t.setTexCoordArr(this._handlerIndex,i.texCoords)}else s.addImage(e),s.createTexture(),this._image=e,i.updateStrokeTexCoords()})):(t.setTextureDisabled(this._handlerIndex),i.updateStrokeTexCoords())}}}getSrc(){return this._src}setImage(e){this.setSrc(e.src)}getImage(){return this._image}setStartPosition3v(e){this._startPosition.x=e.x,this._startPosition.y=e.y,this._startPosition.z=e.z,v.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,v.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,v.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=he(e)),t&&(this._endColor=he(t)),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}get texOffset(){return this._texOffset}set texOffset(e){this._texOffset=e,this._handler&&this._handler.setTexOffsetArr(this._handlerIndex,e)}get strokeSize(){return this._strokeSize}set strokeSize(e){this._strokeSize=e,this._handler&&this._handler.setStrokeSizeArr(this._handlerIndex,e)}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)}};ms.__counter__=0;let wr=ms,ft=new v,gt=new v;const vs=class e{constructor(t={}){if(this.__id=e.__counter__++,this.visibility=null==t.visibility||t.visibility,this.color=new Float32Array([1,1,1,.5]),t.color){let e=le(t.color);this.setColor(e.x,e.y,e.z,e.w)}t.opacity&&this.setOpacity(t.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,t.path&&this.setPath(t.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(he(e))}setColor(e,t,i,s){s=s||this.color[3],this.color[0]=e,this.color[1]=t,this.color[2]=i,this.color[3]=s}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,s=i._program,r=s.attributes,n=s.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),t.uniform4fv(n.uColor,this.color),t.uniform1f(n.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,s=i._program,r=s.attributes,n=s.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),t.uniform1f(n.uOpacity,0!=this._entity._entityCollection._fadingOpacity?1:0),t.uniform4fv(n.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 s=this._path[i-1][0],r=this._path[i-1][1];this._path.push([e.clone(),t.clone()]);let n=this._verticesHigh,o=this._verticesLow,a=this._gridSize,l=a+1,h=new v,c=this._verticesHigh.length/3,d=c,_=Math.abs(s.sub(r).normal().dot(e.sub(s).normal()));for(let i=0;i<l;i++){let u=i/a,f=s.lerp(e,u),g=r.lerp(t,u);for(let u=0;u<l;u++){let p=u/a,m=s.lerp(r,p),y=e.lerp(t,p);1!==_?new Jt(f,g).intersects(new Jt(m,y),h):h=y,d=c+i*l+u,v.doubleToTwoFloats(h,ft,gt);let x=3*d;n[x]=ft.x,n[x+1]=ft.y,n[x+2]=ft.z,o[x]=gt.x,o[x+1]=gt.y,o[x+2]=gt.z,i<a&&this._indexes.push(d,d+l)}i<a&&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 s=this._gridSize,r=s+1,n=r*r,o=new v,a=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-n,_=d,u=Math.abs(h.sub(c).normal().dot(e.sub(h).normal()));for(let i=0;i<r;i++){let n=i/s,f=h.lerp(e,n),g=c.lerp(t,n);for(let n=0;n<r;n++){let p=n/s,m=h.lerp(c,p),y=e.lerp(t,p);1!==u?new Jt(f,g).intersects(new Jt(m,y),o):o=y,_=d+i*r+n,v.doubleToTwoFloats(o,ft,gt);let x=3*_;a[x]=ft.x,a[x+1]=ft.y,a[x+2]=ft.z,l[x]=gt.x,l[x+1]=gt.y,l[x+2]=gt.z}}}else if(0===i){let i=0,n=e,h=t;e=this._path[1][0],t=this._path[1][1];for(let c=0;c<r;c++){let d=c/s,_=n.lerp(e,d),u=h.lerp(t,d);for(let d=0;d<r;d++){let f=d/s,g=n.lerp(h,f),p=e.lerp(t,f);new Jt(_,u).intersects(new Jt(g,p),o),i=c*r+d,v.doubleToTwoFloats(o,ft,gt);let m=3*i;a[m]=ft.x,a[m+1]=ft.y,a[m+2]=ft.z,l[m]=gt.x,l[m+1]=gt.y,l[m+2]=gt.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*n,f=(i-1)*n,g=f;for(let i=0;i<r;i++){let n=i/s,p=h.lerp(e,n),m=t.lerp(_,n),y=e.lerp(d,n),x=c.lerp(t,n);for(let n=0;n<r;n++){let b=n/s,w=h.lerp(c,b),T=e.lerp(t,b);new Jt(p,x).intersects(new Jt(w,T),o);let C=i*r+n;g=f+C,v.doubleToTwoFloats(o,ft,gt);let E=3*g;a[E]=ft.x,a[E+1]=ft.y,a[E+2]=ft.z,l[E]=gt.x,l[E+1]=gt.y,l[E+2]=gt.z;let A=d.lerp(_,b);T=e.lerp(t,b),new Jt(y,m).intersects(new Jt(T,A),o),g=u+C,v.doubleToTwoFloats(o,ft,gt),E=3*g,a[E]=ft.x,a[E+1]=ft.y,a[E+2]=ft.z,l[E]=gt.x,l[E+1]=gt.y,l[E+2]=gt.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],s=e[t][1];i instanceof Array&&(i=new v(i[0],i[1],i[2])),s instanceof Array&&(s=new v(s[0],s[1],s[2])),this.addEdge3v(i,s)}}insertEdge3v(e,t,i){if(i<this._path.length){let s=[].concat(this._path);s.splice(i,0,[e,t]),this.setPath(s)}else i===this._path.length&&this.addEdge3v(e,t)}};vs.__counter__=0;let Tr=vs;const ys=class e{constructor(t={}){t.properties=t.properties||{},this.__id=e.__counter__++,this._name=t.name||`entity:${this.__id}`,this.properties=t.properties||{},this.childEntities=[],this.parent=null,this.forceGlobalPosition=t.forceGlobalPosition||!1,this.forceGlobalRotation=t.forceGlobalRotation||!1,this.forceGlobalScale=t.forceGlobalScale||!1,this._cartesian=Yt(t.cartesian),this._rootCartesian=new v,this._localPosition=Yt(t.localPosition),this._absoluteLocalPosition=new v,this._lonLat=vi(t.lonlat),this._lonLatMerc=new L,this._altitude=t.altitude||0,this._visibility=null==t.visibility||t.visibility,this._entityCollection=null,this._entityCollectionIndex=-1,this._layer=null,this._layerIndex=-1,this._pickingColor=new v(0,0,0),this._independentPicking=t.independentPicking||!1,this._relativePosition=t.relativePosition||!1,this._pitchRad=t.pitch||0,this._yawRad=t.yaw||0,this._rollRad=t.roll||0,this._scale=Yt(t.scale,new v(1,1,1)),this._absoluteScale=new v,this._qFrame=F.IDENTITY,this._qRot=F.IDENTITY,this._absoluteQRot=F.IDENTITY,this._useDirectQuaternion=!1,this._featureConstructorArray={billboard:[Qa,this.setBillboard],label:[el,this.setLabel],polyline:[br,this.setPolyline],pointCloud:[xr,this.setPointCloud],geometry:[vr,this.setGeometry],geoObject:[yr,this.setGeoObject],strip:[Tr,this.setStrip],ray:[wr,this.setRay]},this.billboard=this._createOptionFeature("billboard",t.billboard),this.label=this._createOptionFeature("label",t.label),this.polyline=this._createOptionFeature("polyline",t.polyline),this.ray=this._createOptionFeature("ray",t.ray),this.pointCloud=this._createOptionFeature("pointCloud",t.pointCloud),this.geometry=this._createOptionFeature("geometry",t.geometry),this.geoObject=this._createOptionFeature("geoObject",t.geoObject),this.strip=this._createOptionFeature("strip",t.strip)}get name(){return this._name}set name(e){e!==this._name&&(this._name=e)}get isEmpty(){return!(this.strip||this.polyline||this.ray||this.geoObject||this.geometry||this.billboard||this.label||this.pointCloud)}get rootEntity(){let e=this;for(;e;){if(!e.parent)return e;e=e.parent}return this}set relativePosition(e){if(e!==this._relativePosition){let t=this.getAbsoluteCartesian(),i=this.getAbsolutePitch(),s=this.getAbsoluteYaw(),r=this.getAbsoluteRoll();this._relativePosition=e,this.parent&&this._rootCartesian.copy(this.parent._rootCartesian),e?this.parent&&(this.setAbsoluteCartesian3v(t),this.setAbsolutePitch(i),this.setAbsoluteYaw(s),this.setAbsoluteRoll(r)):(this.setCartesian3v(t),this.setPitch(i),this.setYaw(s),this.setRoll(r))}}get relativePosition(){return this._relativePosition}get entityCollection(){return this._entityCollection}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){return e.add(this),this}remove(){return this._layer&&this._layer.removeEntity(this),this._entityCollection&&this._entityCollection.removeEntity(this),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.childEntities.length;t++)this.childEntities[t].setVisibility(e)}getVisibility(){return this._visibility}setCartesian3v(e){this.setCartesian(e.x,e.y,e.z)}getScale(){return this._scale}setScale3v(e){this._scale.copy(e),this._updateAbsolutePosition();for(let e=0;e<this.childEntities.length;e++){let t=this.childEntities[e];t.forceGlobalScale?t.setScale3v(this._scale):t.setScale3v(this.childEntities[e].getScale())}}setScale(e){this.setScale3v(new v(e,e,e))}getAbsoluteRotation(){return this._absoluteQRot.clone()}getRotation(){return this._qRot}setLook3v(e){let t,i=new F,s=this.getAbsoluteCartesian();if(this._entityCollection){let r=this._entityCollection.renderNode.ellipsoid.getSurfaceNormal3v(s);t=i.setLookRotation(e.sub(s),r).conjugate()}else t=i.setLookRotation(e.sub(s),v.UP).conjugate();this.setAbsoluteRotation(t)}setLookLonLat(e){if(this._entityCollection){let t=this._entityCollection.renderNode.ellipsoid.lonLatToCartesian(e);this.setLook3v(t)}}setAbsoluteRotation(e){this._absoluteQRot.copy(e),this._updatePitchYawRoll()}setRotation(e){this._useDirectQuaternion=!1,this._pitchRad=e.getPitch(),this._yawRad=e.getYaw(),this._rollRad=e.getRoll(),this._updateAbsolutePosition()}setDirectQuaternionRotation(e){this._qRot.copy(e),this._useDirectQuaternion=!0,this._pitchRad=this._qRot.getPitch(),this._yawRad=this._qRot.getYaw(),this._rollRad=this._qRot.getRoll(),this._updateAbsolutePosition()}setPitch(e){this._useDirectQuaternion=!1,this._pitchRad=e,this._updateAbsolutePosition()}setYaw(e){this._useDirectQuaternion=!1,this._yawRad=e,this._updateAbsolutePosition()}setRoll(e){this._useDirectQuaternion=!1,this._rollRad=e,this._updateAbsolutePosition()}getPitch(){return this._pitchRad}getYaw(){return this._yawRad}getRoll(){return this._rollRad}setAbsolutePitch(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(e,this.getAbsoluteYaw(),this.getAbsoluteRoll(),this._qFrame),this._updatePitchYawRoll()):this.setPitch(e)}setAbsoluteYaw(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(),e,this.getAbsoluteRoll(),this._qFrame),this._updatePitchYawRoll()):this.setYaw(e)}setAbsoluteRoll(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(),this.getAbsoluteYaw(),e,this._qFrame),this._updatePitchYawRoll()):this.setRoll(e)}getAbsolutePitch(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getPitch():this._pitchRad}getAbsoluteYaw(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getYaw():this._yawRad}getAbsoluteRoll(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getRoll():this._rollRad}_getScaleByDistance(){let e=1;if(this._entityCollection){let t=this._entityCollection.scaleByDistance,i=1;this._entityCollection.renderNode&&this._entityCollection.renderNode.renderer&&(i=this._entityCollection.renderNode.renderer.activeCamera.eye.distance(this._rootCartesian)),e=t[2]*Zi(i,t[0],t[1])/t[0]}return e}setAbsoluteCartesian(e,t,i){this.setAbsoluteCartesian3v(new v(e,t,i))}setAbsoluteCartesian3v(e){let t=e;if(this.parent&&this._relativePosition){let i=this._getScaleByDistance();t=e.sub(this.parent.getAbsoluteCartesian()).scale(1/i).divA(this.parent._absoluteScale),t=this.parent._absoluteQRot.conjugate().mulVec3(t)}this.setCartesian3v(t)}getAbsoluteCartesian(){if(this.parent&&this._relativePosition){let e=this._getScaleByDistance();return this._rootCartesian.add(this._absoluteLocalPosition.scaleTo(e))}return this._cartesian.clone()}setCartesian(e,t,i){this._cartesian.set(e,t,i),this._updateAbsolutePosition();for(let s=0;s<this.childEntities.length;s++){let r=this.childEntities[s];r._relativePosition?r.setCartesian3v(r.getCartesian()):r.forceGlobalPosition&&r.setCartesian(e,t,i)}this._updateLonLat()}_updatePitchYawRoll(){if(this.parent){this._qRot=this.parent._absoluteQRot.conjugate().mul(this._absoluteQRot),this._pitchRad=this._qRot.getPitch(),this._yawRad=this._qRot.getYaw(),this._rollRad=this._qRot.getRoll(),this.geoObject&&this.geoObject.setRotation(this._absoluteQRot);for(let e=0;e<this.childEntities.length;e++)this.childEntities[e]._updateAbsolutePosition()}}_updateAbsolutePosition(){let e=this.parent;if(e&&this._relativePosition){this._scale.mulRes(e._absoluteScale,this._absoluteScale),this._qFrame.copy(e._qFrame),this._rootCartesian.copy(e._rootCartesian),this._useDirectQuaternion||(e&&this.forceGlobalRotation?this._qRot.setPitchYawRoll(e._pitchRad,e._yawRad,e._rollRad):this._qRot.setPitchYawRoll(this._pitchRad,this._yawRad,this._rollRad)),e._absoluteQRot.mulRes(this._qRot,this._absoluteQRot);let t=e._absoluteQRot.mulVec3(this._cartesian.add(this._localPosition)).mulA(e._absoluteScale);e._absoluteLocalPosition.addRes(t,this._absoluteLocalPosition)}else this._qFrame=F.IDENTITY,this._entityCollection&&this._entityCollection.renderNode&&(this._qFrame=this._entityCollection.renderNode.getFrameRotation(this._cartesian)),this._useDirectQuaternion?this._qFrame.isEqual(F.IDENTITY)||(this._qRot=this._qRot.mul(this._qFrame)):e&&this.forceGlobalRotation?this._qRot.setPitchYawRoll(e._pitchRad,e._yawRad,e._rollRad,this._qFrame):this._qRot.setPitchYawRoll(this._pitchRad,this._yawRad,this._rollRad,this._qFrame),this._absoluteScale.copy(this._scale),this._absoluteQRot.copy(this._qRot),this._rootCartesian.copy(this._cartesian),this._absoluteLocalPosition.copy(this._localPosition);this.geoObject&&(this.geoObject.setScale3v(this._absoluteScale),this.geoObject.setRotation(this._absoluteQRot),this.geoObject.setPosition3v(this._rootCartesian),this.geoObject.setLocalPosition3v(this._absoluteLocalPosition)),this.billboard&&this.billboard.setPosition3v(this._rootCartesian),this.label&&this.label.setPosition3v(this._rootCartesian);for(let e=0,t=this.childEntities.length;e<t;e++)this.childEntities[e]._updateAbsolutePosition();this._updateLonLat()}_setCartesian3vSilent(e,t=!1){this._cartesian.copy(e),this._updateAbsolutePosition();for(let e=0;e<this.childEntities.length;e++)this.childEntities[e].setCartesian(this._cartesian.x,this._cartesian.y,this._cartesian.z);t||this._updateLonLat()}_updateLonLat(){let e=this._entityCollection;e&&e.renderNode&&e.renderNode.ellipsoid&&(this._lonLat=e.renderNode.ellipsoid.cartesianToLonLat(this.getAbsoluteCartesian()),Math.abs(this._lonLat.lat)<ct?this._lonLatMerc=this._lonLat.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=0)}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;if(i&&i.renderNode&&i.renderNode.ellipsoid){Math.abs(t.lat)<ct&&(this._lonLatMerc=t.forwardMercator());let e=new v;i.renderNode.ellipsoid.lonLatToCartesianRes(t,e),this.setAbsoluteCartesian3v(e)}}setLonLat2(e,t,i){let s=this._lonLat;s.lon=e,s.lat=t,s.height=i??s.height;let r=this._entityCollection;if(r&&r.renderNode&&r.renderNode.ellipsoid){Math.abs(s.lat)<ct?this._lonLatMerc=s.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=this._lonLatMerc.height=0;let e=new v;r.renderNode.ellipsoid.lonLatToCartesianRes(s,e),this.setAbsoluteCartesian3v(e)}}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}appendChildren(e,t){for(let i=0;i<e.length;i++)void 0!==t&&(e[i].relativePosition=t),this.appendChild(e[i])}appendChild(e){e._entityCollection=this._entityCollection,e._independentPicking||(e._pickingColor=this._pickingColor),e.parent=this,this.childEntities.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.childEntities.length;e++)this.childEntities[e].setPickingColor()}getExtent(){let e,t=this._lonLat;e=this.billboard||this.label?new U(new L(t.lon,t.lat),new L(t.lon,t.lat)):new U(new L(180,90),new L(-180,-90));let i=e.southWest,s=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>s.lon&&(s.lon=e.northEast.lon),e.northEast.lat>s.lat&&(s.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>s.lon&&(s.lon=e.northEast.lon),e.northEast.lat>s.lat&&(s.lat=e.northEast.lat)}for(let e=0;e<this.childEntities.length;e++){let t=this.childEntities[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>s.lon&&(s.lon=t.northEast.lon),t.northEast.lat>s.lat&&(s.lat=t.northEast.lat)}return e}};ys.__counter__=0;let G=ys;const xs=class e{constructor(t){this.__id=e.__counter__++,this._name=t||`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}};xs.__counter__=0;let Cr=xs;class de extends Cr{constructor(e){super(e),this.childNodes=[],this.renderer=null,this.drawMode=0,this.show=!0,this._isActive=!0,this.lightEnabled=!1,this._lightPosition=new Float32Array([100,100,100]),this._lightParams=new Float32Array(9),this._lightShininess=100,this.entityCollections=[],this._entityCollectionsByDepthOrder=[],this._pickingId=-1}getFrameRotation(e){return F.IDENTITY}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){e.renderNode||(e.renderNode=this,t||(this.entityCollections.push(e),this.updateEntityCollectionsDepthOrder()),this.ellipsoid&&e._updateGeodeticCoordinates(this.ellipsoid),e.bindRenderNode(this),e.events.dispatch(e.events.add,this))}removeEntityCollection(e){for(let t=0;t<this.entityCollections.length;t++)if(this.entityCollections[t].isEqual(e))return this.entityCollections.splice(t,1),void this.updateEntityCollectionsDepthOrder()}updateEntityCollectionsDepthOrder(){let e={0:[]};for(const t of this.entityCollections)t.getVisibility()&&(e[t.depthOrder]||(e[t.depthOrder]=[]),e[t.depthOrder].push(t));this._entityCollectionsByDepthOrder.length=0,this._entityCollectionsByDepthOrder=[],this._entityCollectionsByDepthOrder=Object.keys(e).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[Number(t)]))}addLight(e){return e.addTo(this),this}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)}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr()}updateStrokeTexCoords(){for(let e=0;e<this.entityCollections.length;e++){let t=this.entityCollections[e];t.rayHandler.refreshTexCoordsArr(),t.polylineHandler.refreshTexCoordsArr()}}frame(){}preFrame(){}_preDrawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._preDrawNodes();if(this.show){this.preFrame();for(let e=0;e<this._entityCollectionsByDepthOrder.length;e++)this.drawEntityCollections(this._entityCollectionsByDepthOrder[e],e)}}_drawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._drawNodes();this.show&&this.frame()}drawEntityCollections(e,t=0){this.renderer.enqueueEntityCollectionsToDraw(e,t)}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(){}}const ie=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 fi=["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 ht={};for(let e=0;e<fi.length;e++)ht[fi[e]]=e;const Er={};for(let e=0;e<fi.length;e++)Er[fi[e].toLowerCase()]=ht[fi[e]];const Pt={u:[],a:[]};Pt.u[ht.MAT4]=function(e,t){e.gl.uniformMatrix4fv(t._pName,!1,t.value)},Pt.u[ht.MAT3]=function(e,t){e.gl.uniformMatrix3fv(t._pName,!1,t.value)},Pt.u[ht.FLOAT]=function(e,t){e.gl.uniform1f(t._pName,t.value)},Pt.u[ht.INT]=function(e,t){e.gl.uniform1i(t._pName,t.value)},Pt.u[ht.VEC2]=function(e,t){e.gl.uniform2fv(t._pName,t.value)},Pt.u[ht.VEC3]=function(e,t){e.gl.uniform3fv(t._pName,t.value)},Pt.u[ht.VEC4]=function(e,t){e.gl.uniform4fv(t._pName,t.value)},Pt.u[ht.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++},Pt.u[ht.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++},Pt.u[ht.SAMPLER2DARRAY]=function(e,t){let i=t.value,s=e.gl,r=i.length,n=new Int32Array(r);for(let t=0;t<r;t++)s.activeTexture(s.TEXTURE0+e._textureID+t),s.bindTexture(s.TEXTURE_2D,i[t]),n[t]=t;s.uniform1iv(t._pName,n)},Pt.u[ht.INTXX]=function(e,t){e.gl.uniform1iv(t._pName,t.value)},Pt.u[ht.FLOATXX]=function(e,t){e.gl.uniform1fv(t._pName,t.value)},Pt.a[ht.FLOAT]=function(e,t){e.gl.vertexAttrib1f(t._pName,t.value)},Pt.a[ht.VEC2]=function(e,t){e.gl.vertexAttrib2fv(t._pName,t.value)},Pt.a[ht.VEC3]=function(e,t){e.gl.vertexAttrib3fv(t._pName,t.value)};const il=["BYTE","SHORT","UNSIGNED_BYTE","UNSIGNED_SHORT","FLOAT","HALF_FLOAT"];class X{constructor(e,t){this.name=e,this._programController=null,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){if(!this.gl)return!1;const i=this.gl instanceof WebGL2RenderingContext;return this.gl.shaderSource(e,function(e,t){if(!t)return e;const i=e.split("\n"),s=i.findIndex((e=>e.startsWith("#version")));return-1!==s?(i.splice(s+1,0,"#define WEBGL2"),i.join("\n")):e}(t,i)),this.gl.compileShader(e),!!this.gl.getShaderParameter(e,this.gl.COMPILE_STATUS)||(ie.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,s=t.length;i<s;i++)e.disableVertexAttribArray(t[i]),this.vertexAttribDivisor(t[i],0)}enableAttribArrays(){let e=this.gl,t=this._attribArrays,i=this._attribDivisor;for(let s=0,r=t.length;s<r;s++)e.enableVertexAttribArray(t[s]),this.vertexAttribDivisor(t[s],i[s])}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 ie.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=X.bindBuffer;let i=this._attributes[t].itemType,s=i?i.trim().toUpperCase():"FLOAT";if(-1==il.indexOf(s)?(ie.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[s],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 ie.logErr(`Shader program "${this.name}": attribute '${t}' not exists.`),void e.deleteProgram(this._p);let r=this._attributes[t].type;"string"==typeof r&&(r=Er[r.trim().toLowerCase()]);let n=this._attributes[t].divisor;if(r===ht.MAT4){let e=this._p[t];this._attribArrays.push(e,e+1,e+2,e+3),this._attribDivisor.push(n,n,n,n)}else this._attribArrays.push(this._p[t]),this._attribDivisor.push(n);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=Pt.u[Er[e.trim().toLowerCase()]]}else this._uniforms[t].func=Pt.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 ie.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 bs=class e{constructor(t){this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,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 X("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#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}attribute vec2 a_vertices;attribute vec2 a_texCoord;attribute vec3 a_positionsHigh;attribute vec3 a_positionsLow;attribute vec3 a_offset;attribute vec2 a_size;attribute float a_rotation;attribute vec4 a_rgba;varying vec2 v_texCoords;varying vec4 v_rgba;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform vec3 uScaleByDistance;uniform float opacity;uniform float planetRadius;uniform vec2 viewport;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;v_texCoords=a_texCoord;vec3 look=a_positions-cameraPos;float lookDist=length(look);v_rgba=a_rgba;if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(uScaleByDistance[0],uScaleByDistance[1],lookDist))*(1.0-step(uScaleByDistance[2],lookDist));mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 v=screenPos+rotate2d(a_rotation)*(a_vertices*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"precision highp float;uniform sampler2D u_texture;varying vec2 v_texCoords;varying vec4 v_rgba;void main(){vec4 color=texture2D(u_texture,v_texCoords);if(color.a<0.1)discard;gl_FragColor=color*v_rgba;}"})),this._renderer.handler.programs.billboardPicking||this._renderer.handler.addProgram(new X("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#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}attribute vec2 a_vertices;attribute vec3 a_positionsHigh;attribute vec3 a_positionsLow;attribute vec3 a_offset;attribute vec2 a_size;attribute float a_rotation;attribute vec4 a_rgba;varying vec3 v_rgb;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform vec3 uScaleByDistance;uniform float opacity;uniform float planetRadius;uniform vec2 viewport;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;vec3 look=a_positions-cameraPos;float lookDist=length(look);v_rgb=a_rgba.rgb;if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(uScaleByDistance[0],uScaleByDistance[1],lookDist))*(1.0-step(uScaleByDistance[2],lookDist));mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 v=screenPos+rotate2d(a_rotation)*(a_vertices*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"precision highp float;varying vec3 v_rgb;void main(){gl_FragColor=vec4(v_rgb,1.0);}"})))}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=-1}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,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection;n.disable(n.CULL_FACE),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.uniform1i(r.u_texture,0),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform3fv(r.uScaleByDistance,o.scaleByDistance),n.uniform1f(r.opacity,o._fadingOpacity),n.bindBuffer(n.ARRAY_BUFFER,this._texCoordBuffer),n.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionHighBuffer),n.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionLowBuffer),n.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._rgbaBuffer),n.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._sizeBuffer),n.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._offsetBuffer),n.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,n.FLOAT,!1,0,0),n.uniform1f(r.planetRadius,o.renderNode._planetRadius2||0),n.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),n.bindBuffer(n.ARRAY_BUFFER,this._rotationBuffer),n.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.enable(n.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.billboardPicking.activate();let i=t.programs.billboardPicking._program,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection;n.disable(n.CULL_FACE),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform3fv(r.uScaleByDistance,o.scaleByDistance),n.uniform1f(r.opacity,o._fadingOpacity),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionHighBuffer),n.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionLowBuffer),n.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._pickingColorBuffer),n.vertexAttribPointer(s.a_rgba,this._pickingColorBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._sizeBuffer),n.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._offsetBuffer),n.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,n.FLOAT,!1,0,0),n.uniform1f(r.planetRadius,o.renderNode._planetRadius2||0),n.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),n.bindBuffer(n.ARRAY_BUFFER,this._rotationBuffer),n.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.enable(n.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=ot(this._rgbaArr,i,24),i=18*t,this._positionHighArr=ot(this._positionHighArr,i,18),this._positionLowArr=ot(this._positionLowArr,i,18),this._offsetArr=ot(this._offsetArr,i,18),this._pickingColorArr=ot(this._pickingColorArr,i,18),i=12*t,this._vertexArr=ot(this._vertexArr,i,12),this._sizeArr=ot(this._sizeArr,i,12),this._texCoordArr=ot(this._texCoordArr,i,12),i=6*t,this._rotationArr=ot(this._rotationArr,i,6),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1,e._lockId=-1}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 s=18*e,r=this._positionHighArr,n=t.x,o=t.y,a=t.z;r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,r=this._positionLowArr,n=i.x,o=i.y,a=i.z,r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e,s=this._pickingColorArr,r=t.x/255,n=t.y/255,o=t.z/255;s[i]=r,s[i+1]=n,s[i+2]=o,s[i+3]=r,s[i+4]=n,s[i+5]=o,s[i+6]=r,s[i+7]=n,s[i+8]=o,s[i+9]=r,s[i+10]=n,s[i+11]=o,s[i+12]=r,s[i+13]=n,s[i+14]=o,s[i+15]=r,s[i+16]=n,s[i+17]=o,this._changedBuffers[0]=!0}setSizeArr(e,t,i){let s=12*e,r=this._sizeArr,n=t,o=i;r[s]=n,r[s+1]=o,r[s+2]=n,r[s+3]=o,r[s+4]=n,r[s+5]=o,r[s+6]=n,r[s+7]=o,r[s+8]=n,r[s+9]=o,r[s+10]=n,r[s+11]=o,this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e,s=this._offsetArr,r=t.x,n=t.y,o=t.z;s[i]=r,s[i+1]=n,s[i+2]=o,s[i+3]=r,s[i+4]=n,s[i+5]=o,s[i+6]=r,s[i+7]=n,s[i+8]=o,s[i+9]=r,s[i+10]=n,s[i+11]=o,s[i+12]=r,s[i+13]=n,s[i+14]=o,s[i+15]=r,s[i+16]=n,s[i+17]=o,this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e,s=this._rgbaArr,r=t.x,n=t.y,o=t.z,a=t.w;s[i]=r,s[i+1]=n,s[i+2]=o,s[i+3]=a,s[i+4]=r,s[i+5]=n,s[i+6]=o,s[i+7]=a,s[i+8]=r,s[i+9]=n,s[i+10]=o,s[i+11]=a,s[i+12]=r,s[i+13]=n,s[i+14]=o,s[i+15]=a,s[i+16]=r,s[i+17]=n,s[i+18]=o,s[i+19]=a,s[i+20]=r,s[i+21]=n,s[i+22]=o,s[i+23]=a,this._changedBuffers[4]=!0}setRotationArr(e,t){let i=6*e,s=this._rotationArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[5]=!0}setTexCoordArr(e,t){let i=12*e,s=this._texCoordArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[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,s=this._vertexArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[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(){}};bs.__counter__=0;let ns=bs;class sl extends ns{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=it(this._vertexArr,[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]):this._vertexArr=it(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]),this._texCoordArr=it(this._texCoordArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t,i=e._positionHigh.x,s=e._positionHigh.y,r=e._positionHigh.z;this._positionHighArr=it(this._positionHighArr,[i,s,r,i,s,r,i,s,r,i,s,r,i,s,r,i,s,r]),i=e._positionLow.x,s=e._positionLow.y,r=e._positionLow.z,this._positionLowArr=it(this._positionLowArr,[i,s,r,i,s,r,i,s,r,i,s,r,i,s,r,i,s,r]),i=e._width,s=e._height,this._sizeArr=it(this._sizeArr,[i,s,i,s,i,s,i,s,i,s,i,s]),i=e._offset.x,s=e._offset.y,r=e._offset.z,this._offsetArr=it(this._offsetArr,[i,s,r,i,s,r,i,s,r,i,s,r,i,s,r,i,s,r]),i=e._color.x,s=e._color.y,r=e._color.z,t=e._color.w,this._rgbaArr=it(this._rgbaArr,[i,s,r,t,i,s,r,t,i,s,r,t,i,s,r,t,i,s,r,t,i,s,r,t]),i=e._rotation,this._rotationArr=it(this._rotationArr,[i,i,i,i,i,i]),i=e._entity._pickingColor.x/255,s=e._entity._pickingColor.y/255,r=e._entity._pickingColor.z/255,this._pickingColorArr=it(this._pickingColorArr,[i,s,r,i,s,r,i,s,r,i,s,r,i,s,r,i,s,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],s=i.getImage();if(s){let t=e.get(s.__nodeIndex);t&&this.setTexCoordArr(i._handlerIndex,t.texCoords)}}}}}class rl{constructor(e){this.isFree=!0,this._geoObjectHandler=e,this.geoObjects=[],this.numInstances=0,this._colorTexture=null,this._colorTextureSrc=null,this._colorTextureImage=null,this._normalTexture=null,this._normalTextureSrc=null,this._normalTextureImage=null,this._metallicRoughnessTexture=null,this._metallicRoughnessTextureSrc=null,this._metallicRoughnessTextureImage=null,this._sizeArr=[],this._translateArr=[],this._vertexArr=[],this._rtcPositionHighArr=[],this._rtcPositionLowArr=[],this._qRotArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._localPositionArr=[],this._sizeBuffer=null,this._translateBuffer=null,this._vertexBuffer=null,this._rtcPositionHighBuffer=null,this._rtcPositionLowBuffer=null,this._qRotBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._localPositionBuffer=null,this._materialParams=new Float32Array(9),this._materialShininess=0,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[Jo]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[Xo]=this.createNormalsBuffer,this._buffersUpdateCallbacks[$o]=this.createRgbaBuffer,this._buffersUpdateCallbacks[Zo]=this.createIndicesBuffer,this._buffersUpdateCallbacks[Yo]=this.createVertexBuffer,this._buffersUpdateCallbacks[Qo]=this.createSizeBuffer,this._buffersUpdateCallbacks[ta]=this.createVisibleBuffer,this._buffersUpdateCallbacks[ea]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[Ko]=this.createQRotBuffer,this._buffersUpdateCallbacks[ia]=this.createTranslateBuffer,this._buffersUpdateCallbacks[Wo]=this.createRTCPositionBuffer,this._buffersUpdateCallbacks[sa]=this.createLocalPositionBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}setMaterialAmbient(e,t,i){this._materialParams[0]=e,this._materialParams[1]=t,this._materialParams[2]=i}setMaterialDiffuse(e,t,i){this._materialParams[3]=e,this._materialParams[4]=t,this._materialParams[5]=i}setMaterialSpecular(e,t,i){this._materialParams[6]=e,this._materialParams[7]=t,this._materialParams[8]=i}setMaterialShininess(e){this._materialShininess=e}setMaterialParams(e,t,i,s){this.setMaterialAmbient(e[0],e[1],e[2]),this.setMaterialDiffuse(t[0],t[1],t[2]),this.setMaterialSpecular(i[0],i[1],i[2]),this.setMaterialShininess(s)}drawOpaque(e){let t=e.gl,i=e.uniforms,s=e.attributes;t.bindBuffer(t.ARRAY_BUFFER,this._qRotBuffer),t.vertexAttribPointer(s.qRot,this._qRotBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._sizeBuffer),t.vertexAttribPointer(s.aScale,this._sizeBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._translateBuffer),t.vertexAttribPointer(s.aTranslate,this._translateBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._localPositionBuffer),t.vertexAttribPointer(s.aLocalPosition,this._localPositionBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._visibleBuffer),t.vertexAttribPointer(s.aDispose,this._visibleBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(i.uUseTexture,this._colorTexture?1:0),t.bindBuffer(t.ARRAY_BUFFER,this._rgbaBuffer),t.vertexAttribPointer(s.aColor,this._rgbaBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform3fv(i.materialParams,this._materialParams),t.uniform1f(i.materialShininess,this._materialShininess),this._drawElementsInstanced(e)}drawTransparent(e){let t=e.gl,i=e.uniforms,s=e.attributes;t.bindBuffer(t.ARRAY_BUFFER,this._qRotBuffer),t.vertexAttribPointer(s.qRot,this._qRotBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._sizeBuffer),t.vertexAttribPointer(s.aScale,this._sizeBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._translateBuffer),t.vertexAttribPointer(s.aTranslate,this._translateBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._localPositionBuffer),t.vertexAttribPointer(s.aLocalPosition,this._localPositionBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._visibleBuffer),t.vertexAttribPointer(s.aDispose,this._visibleBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(i.uUseTexture,this._colorTexture?1:0),t.uniform3fv(i.materialParams,this._materialParams),t.uniform1f(i.materialShininess,this._materialShininess),t.bindBuffer(t.ARRAY_BUFFER,this._rgbaBuffer),t.vertexAttribPointer(s.aColor,this._rgbaBuffer.itemSize,t.FLOAT,!1,0,0),this._drawElementsInstanced(e)}_drawElementsInstanced(e){let t=e.gl,i=e.uniforms,s=e.attributes,r=this._geoObjectHandler._renderer;t.bindBuffer(t.ARRAY_BUFFER,this._rtcPositionHighBuffer),t.vertexAttribPointer(s.aRTCPositionHigh,this._rtcPositionHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._rtcPositionLowBuffer),t.vertexAttribPointer(s.aRTCPositionLow,this._rtcPositionLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._normalsBuffer),t.vertexAttribPointer(s.aVertexNormal,this._normalsBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._vertexBuffer),t.vertexAttribPointer(s.aVertexPosition,this._vertexBuffer.itemSize,t.FLOAT,!1,0,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._colorTexture||r.handler.defaultTexture),t.uniform1i(i.uTexture,0),t.bindBuffer(t.ARRAY_BUFFER,this._texCoordBuffer),t.vertexAttribPointer(s.aTexCoord,this._texCoordBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indicesBuffer),e.drawElementsInstanced(t.TRIANGLES,this._indicesBuffer.numItems,t.UNSIGNED_INT,0,this.numInstances)}async loadColorTexture(){if(this._geoObjectHandler._renderer){if(!this._colorTextureSrc)return this._colorTextureImage?(await this._colorTextureImage.decode(),void this._createColorTexture(this._colorTextureImage)):void 0;{const e=await Ui(this._colorTextureSrc);this._createColorTexture(e)}}}async loadNormalTexture(){if(this._geoObjectHandler._renderer){if(!this._normalTextureSrc)return this._normalTextureImage?(await this._normalTextureImage.decode(),void this._createNormalTexture(this._normalTextureImage)):void 0;{const e=await Ui(this._normalTextureSrc);this._createNormalTexture(e)}}}async loadMetallicRoughnessTexture(){if(this._geoObjectHandler._renderer){if(!this._metallicRoughnessTextureSrc)return this._metallicRoughnessTextureImage?(await this._metallicRoughnessTextureImage.decode(),void this._createMetallicRoughnessTexture(this._metallicRoughnessTextureImage)):void 0;{const e=await Ui(this._metallicRoughnessTextureSrc);this._createMetallicRoughnessTexture(e)}}}clear(){this.numInstances=0,this.geoObjects=[],this._sizeArr=[],this._translateArr=[],this._vertexArr=[],this._rtcPositionHighArr=[],this._rtcPositionLowArr=[],this._qRotArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._localPositionArr=[],this._deleteBuffers(),this.isFree=!1}_deleteBuffers(){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let e=this._geoObjectHandler._renderer.handler;if(e){e.deleteTexture(this._colorTexture),e.deleteTexture(this._normalTexture),e.deleteTexture(this._metallicRoughnessTexture);let t=e.gl;t&&(t.deleteBuffer(this._sizeBuffer),t.deleteBuffer(this._translateBuffer),t.deleteBuffer(this._vertexBuffer),t.deleteBuffer(this._rtcPositionHighBuffer),t.deleteBuffer(this._rtcPositionLowBuffer),t.deleteBuffer(this._qRotBuffer),t.deleteBuffer(this._rgbaBuffer),t.deleteBuffer(this._normalsBuffer),t.deleteBuffer(this._indicesBuffer),t.deleteBuffer(this._pickingColorBuffer),t.deleteBuffer(this._visibleBuffer),t.deleteBuffer(this._texCoordBuffer),t.deleteBuffer(this._localPositionBuffer))}this._colorTexture=null,this._normalTexture=null,this._metallicRoughnessTexture=null}this._sizeBuffer=null,this._translateBuffer=null,this._vertexBuffer=null,this._rtcPositionHighBuffer=null,this._rtcPositionLowBuffer=null,this._qRotBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._localPositionBuffer=null}createVertexBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=st(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,3,this._vertexArr.length/3)}createVisibleBuffer(){const e=this._geoObjectHandler._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=st(this._visibleArr),e.setStreamArrayBuffer(this._visibleBuffer,this._visibleArr)}createSizeBuffer(){let e=this._geoObjectHandler._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=st(this._sizeArr),e.setStreamArrayBuffer(this._sizeBuffer,this._sizeArr)}createTranslateBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._translateArr.length/3;this._translateBuffer&&this._translateBuffer.numItems===t||(e.gl.deleteBuffer(this._translateBuffer),this._translateBuffer=e.createStreamArrayBuffer(3,t)),this._translateArr=st(this._translateArr),e.setStreamArrayBuffer(this._translateBuffer,this._translateArr)}createLocalPositionBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._localPositionArr.length/3;this._localPositionBuffer&&this._localPositionBuffer.numItems===t||(e.gl.deleteBuffer(this._localPositionBuffer),this._localPositionBuffer=e.createStreamArrayBuffer(3,t)),this._localPositionArr=st(this._localPositionArr),e.setStreamArrayBuffer(this._localPositionBuffer,this._localPositionArr)}createTexCoordBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordArr=st(this._texCoordArr),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createRTCPositionBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._rtcPositionHighArr.length/3;this._rtcPositionHighBuffer&&this._rtcPositionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._rtcPositionHighBuffer),e.gl.deleteBuffer(this._rtcPositionLowBuffer),this._rtcPositionHighBuffer=e.createStreamArrayBuffer(3,t),this._rtcPositionLowBuffer=e.createStreamArrayBuffer(3,t)),this._rtcPositionHighArr=st(this._rtcPositionHighArr),this._rtcPositionLowArr=st(this._rtcPositionLowArr),e.setStreamArrayBuffer(this._rtcPositionHighBuffer,this._rtcPositionHighArr),e.setStreamArrayBuffer(this._rtcPositionLowBuffer,this._rtcPositionLowArr)}createRgbaBuffer(){let e=this._geoObjectHandler._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=st(this._rgbaArr),e.setStreamArrayBuffer(this._rgbaBuffer,this._rgbaArr)}createQRotBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._qRotArr.length/4;this._qRotBuffer&&this._qRotBuffer.numItems===t||(e.gl.deleteBuffer(this._qRotBuffer),this._qRotBuffer=e.createStreamArrayBuffer(4,t)),this._qRotArr=st(this._qRotArr),e.setStreamArrayBuffer(this._qRotBuffer,this._qRotArr)}createNormalsBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._normalsBuffer),this._normalsArr=st(this._normalsArr),this._normalsBuffer=e.createArrayBuffer(this._normalsArr,3,this._normalsArr.length/3)}createIndicesBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._indicesBuffer),this._indicesArr=st(this._indicesArr,Uint32Array),this._indicesBuffer=e.createElementArrayBuffer(this._indicesArr,1,this._indicesArr.length)}createPickingColorBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=st(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._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1);this.isFree=!0}}_createColorTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._colorTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}_createNormalTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._normalTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}_createMetallicRoughnessTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._metallicRoughnessTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}}const Yo=0,Wo=1,$o=2,Xo=3,Zo=4,Ko=5,Qo=6,Jo=7,ta=8,ea=9,ia=10,sa=11;function Tt(e,t=0,i=0,s=1,...r){const n=t*i;for(let t=n,o=n+i;t<o;t++)e[t]=r[t%s];return e}const ws=class e{constructor(t){this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,this._renderNode=null,this._renderer=null,this._geoObjects=[],this._instanceDataMap=new Map,this._instanceDataMapValues=[],this._dataTagUpdateQueue=[],this._relativeCenter=new v,this._rtcEyePositionHigh=new Float32Array([0,0,0]),this._rtcEyePositionLow=new Float32Array([0,0,0])}initProgram(){this._renderer&&(this._renderer.handler.programs.geo_object||this._renderer.handler.addProgram(new X("geo_object",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",eyePositionHigh:"vec3",eyePositionLow:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",sunPosition:"vec3",materialParams:"vec3",materialShininess:"float",uTexture:"sampler2d",uUseTexture:"float",useLighting:"float"},attributes:{aVertexPosition:"vec3",aVertexNormal:"vec3",aTexCoord:"vec2",aLocalPosition:{type:"vec3",divisor:1},aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aColor:{type:"vec4",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1}},vertexShader:"precision highp float;vec3 qRotate(vec4 q,vec3 v){return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}attribute vec3 aVertexPosition;attribute vec3 aVertexNormal;attribute vec3 aRTCPositionHigh;attribute vec3 aRTCPositionLow;attribute vec4 aColor;attribute vec3 aScale;attribute vec3 aTranslate;attribute float aDispose;attribute float aUseTexture;attribute vec2 aTexCoord;attribute vec4 qRot;attribute vec3 aLocalPosition;uniform vec3 uScaleByDistance;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;varying vec3 cameraPosition;varying vec3 vNormal;varying vec3 v_vertex;varying vec4 vColor;varying float vDispose;varying vec2 vTexCoords;void main(void){if(aDispose==0.0){return;}vColor=aColor;vTexCoords=aTexCoord;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=aRTCPositionHigh-rtcEyePositionHigh;vec3 lowDiff=aRTCPositionLow-rtcEyePositionLow;cameraPosition=eyePositionHigh+eyePositionLow;highDiff=highDiff*step(1.0,length(highDiff));vec4 positionInViewSpace=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);float lookLength=length(positionInViewSpace.xyz);vNormal=normalize(qRotate(qRot,aVertexNormal));float scd=uScaleByDistance[2]*clamp(lookLength,uScaleByDistance[0],uScaleByDistance[1])/uScaleByDistance[0];vec3 vert=qRotate(qRot,scd*(aVertexPosition*aScale+aTranslate))+scd*aLocalPosition;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff+lowDiff+vert,1.0);v_vertex=positionInViewSpace.xyz+vert;}",fragmentShader:"precision highp float;uniform vec3 sunPosition;uniform vec3 materialParams[3];uniform float materialShininess;uniform sampler2D uTexture;uniform float uUseTexture;uniform float useLighting;varying vec3 cameraPosition;varying vec3 v_vertex;varying vec4 vColor;varying vec3 vNormal;varying vec2 vTexCoords;void main(void){vec3 lightWeighting=vec3(1.0);if(useLighting!=0.0){vec3 normal=normalize(vNormal);vec3 light_dir=normalize(sunPosition);vec3 look_dir=normalize(cameraPosition-v_vertex);float diffuse=max(dot(normal,light_dir),0.0);vec3 refl_dir=reflect(-light_dir,normal);float refl=max(dot(refl_dir,look_dir),0.0);float specular=pow(refl,materialShininess)*step(1e-4,diffuse);lightWeighting=vColor.rgb*materialParams[0]+materialParams[1]*diffuse+materialParams[2]*specular;}else{lightWeighting=vColor.rgb;}if(uUseTexture>0.0){vec4 texColor=texture2D(uTexture,vTexCoords);gl_FragColor=vec4(texColor.rgb*lightWeighting,texColor.a);}else{gl_FragColor=vec4(lightWeighting,vColor.a);}}"})),this._renderer.handler.programs.geo_object_picking||this._renderer.handler.addProgram(new X("geo_object_picking",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",pickingScale:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3"},attributes:{aVertexPosition:"vec3",aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aPickingColor:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aLocalPosition:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1}},vertexShader:"precision highp float;vec3 qRotate(vec4 q,vec3 v){return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}attribute vec3 aVertexPosition;attribute vec3 aRTCPositionHigh;attribute vec3 aRTCPositionLow;attribute vec3 aPickingColor;attribute vec3 aScale;attribute vec3 aTranslate;attribute float aDispose;attribute vec4 qRot;attribute vec3 aLocalPosition;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;uniform vec3 uScaleByDistance;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 pickingScale;varying vec3 vColor;void main(void){if(aDispose==0.0){return;}vColor=aPickingColor;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=aRTCPositionHigh-rtcEyePositionHigh;vec3 lowDiff=aRTCPositionLow-rtcEyePositionLow;highDiff=highDiff*step(1.0,length(highDiff));vec4 positionInViewSpace=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);float lookLength=length(positionInViewSpace.xyz);float scd=uScaleByDistance[2]*clamp(lookLength,uScaleByDistance[0],uScaleByDistance[1])/uScaleByDistance[0];vec3 vert=qRotate(qRot,scd*pickingScale*(aVertexPosition*aScale+aTranslate))+scd*aLocalPosition;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff+lowDiff+vert,1.0);}",fragmentShader:"precision highp float;varying vec3 vColor;void main(){gl_FragColor=vec4(vColor,1.0);}"})),this._renderer.handler.programs.geo_object_depth||this._renderer.handler.addProgram(new X("geo_object_depth",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",frustumPickingColor:"float"},attributes:{aVertexPosition:"vec3",aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1},aLocalPosition:{type:"vec3",divisor:1}},vertexShader:"#version 300 es\nprecision highp float;vec3 qRotate(vec4 q,vec3 v){return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}in vec3 aVertexPosition;in vec3 aRTCPositionHigh;in vec3 aRTCPositionLow;in vec3 aScale;in vec3 aTranslate;in float aDispose;in vec4 qRot;in vec3 aLocalPosition;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;uniform vec3 uScaleByDistance;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;void main(void){if(aDispose==0.0){return;}mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=aRTCPositionHigh-rtcEyePositionHigh;vec3 lowDiff=aRTCPositionLow-rtcEyePositionLow;highDiff=highDiff*step(1.0,length(highDiff));vec4 positionInViewSpace=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);float lookLength=length(positionInViewSpace.xyz);float scd=uScaleByDistance[2]*clamp(lookLength,uScaleByDistance[0],uScaleByDistance[1])/uScaleByDistance[0];vec3 vert=qRotate(qRot,scd*(aVertexPosition*aScale+aTranslate))+scd*aLocalPosition;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff+lowDiff+vert,1.0);}",fragmentShader:"#version 300 es\nprecision highp float;uniform float frustumPickingColor;layout(location=0)out vec4 frustumColor;layout(location=1)out vec4 depthColor;void main(){frustumColor=vec4(frustumPickingColor,frustumPickingColor,frustumPickingColor,1.0);depthColor=vec4(gl_FragCoord.z,gl_FragCoord.z,gl_FragCoord.z,1.0);}"})))}setRenderNode(e){this._renderNode=e,this._renderer=e.renderer,this.initProgram();for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].loadColorTexture(),this._instanceDataMapValues[e].loadNormalTexture(),this._instanceDataMapValues[e].loadMetallicRoughnessTexture();for(let e=0;e<this._geoObjects.length;e++)this._geoObjects[e].updateRotation();this.update()}setColorTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&("string"==typeof e&&(i._colorTextureSrc=e,i._colorTextureImage=null),e instanceof HTMLImageElement&&(i._colorTextureSrc=null,i._colorTextureImage=e),this._instanceDataMap.set(t,i),i.loadColorTexture())}setNormalTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&("string"==typeof e&&(i._normalTextureSrc=e,i._normalTextureImage=null),e instanceof HTMLImageElement&&(i._normalTextureSrc=null,i._normalTextureImage=e),this._instanceDataMap.set(t,i),i.loadNormalTexture())}setMetallicRoughnessTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&("string"==typeof e&&(i._metallicRoughnessTextureSrc=e,i._metallicRoughnessTextureImage=null),e instanceof HTMLImageElement&&(i._metallicRoughnessTextureSrc=null,i._metallicRoughnessTextureImage=e),this._instanceDataMap.set(t,i),i.loadMetallicRoughnessTexture())}setObjectSrc(e,t){const i=this._instanceDataMap.get(t);e&&i&&i._objectSrc!==e&&(i._objectSrc=e,$.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[Yo]=!0),e.normals.length!==i._normalsArr.length&&(i._normalsArr=e.normals,i._changedBuffers[Xo]=!0),e.indices.length!==i._indicesArr.length&&(i._indicesArr=e.indices,i._changedBuffers[Zo]=!0),e.texCoords.length!==i._texCoordArr.length&&(i._texCoordArr=e.texCoords,i._changedBuffers[ea]=!0),i._colorTextureSrc=e.colorTextureSrc,i._normalTextureSrc=e.normalTextureSrc,i._metallicRoughnessTexture=e.metallicRoughnessTextureSrc,i._colorTextureImage=e.colorTextureImage,i._normalTextureImage=e.normalTextureImage,i._metallicRoughnessTextureImage=e.metallicRoughnessTextureImage,i.loadColorTexture(),i.loadNormalTexture(),i.loadMetallicRoughnessTexture(),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 rl(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._colorTextureSrc=e.object3d.colorTextureSrc,i._normalTextureSrc=e.object3d.normalTextureSrc,i._metallicRoughnessTextureSrc=e.object3d.metallicRoughnessTextureSrc,i._colorTextureImage=e.object3d.colorTextureImage,i._normalTextureImage=e.object3d.normalTextureImage,i._metallicRoughnessTextureImage=e.object3d.metallicRoughnessTextureImage,i.setMaterialParams(e.object3d.ambient,e.object3d.diffuse,e.object3d.specular,e.object3d.shininess),i.loadColorTexture(),i.loadNormalTexture(),i.loadMetallicRoughnessTexture()),e._tagDataIndex=i.numInstances++,e._tagData=i,i.geoObjects.push(e);let s=3;i._visibleArr=bt(i._visibleArr,Tt([],0,1,1,e.getVisibility()?1:0)),this.getRTCPosition(e.getPosition(),e._rtcPositionHigh,e._rtcPositionLow);let r,n=e._rtcPositionHigh.x,o=e._rtcPositionHigh.y,a=e._rtcPositionHigh.z;i._rtcPositionHighArr=bt(i._rtcPositionHighArr,Tt([],0,s,s,n,o,a)),n=e._rtcPositionLow.x,o=e._rtcPositionLow.y,a=e._rtcPositionLow.z,i._rtcPositionLowArr=bt(i._rtcPositionLowArr,Tt([],0,s,s,n,o,a)),n=e._entity._pickingColor.x/255,o=e._entity._pickingColor.y/255,a=e._entity._pickingColor.z/255,i._pickingColorArr=bt(i._pickingColorArr,Tt([],0,s,s,n,o,a)),s=4,n=e._qRot.x,o=e._qRot.y,a=e._qRot.z,r=e._qRot.w,i._qRotArr=bt(i._qRotArr,Tt([],0,s,s,n,o,a,r)),n=e._color.x,o=e._color.y,a=e._color.z,r=e._color.w,i._rgbaArr=bt(i._rgbaArr,Tt([],0,s,s,n,o,a,r)),s=3;let l=e.getScale();n=l.x,o=l.y,a=l.z,i._sizeArr=bt(i._sizeArr,Tt([],0,s,s,n,o,a));let h=e.getTranslate();n=h.x,o=h.y,a=h.z,i._translateArr=bt(i._translateArr,Tt([],0,s,s,n,o,a));let c=e.getLocalPosition();n=c.x,o=c.y,a=c.z,i._localPositionArr=bt(i._localPositionArr,Tt([],0,s,s,n,o,a))}_bindCommon(){let e=this._renderer,t=e.handler.programs.geo_object._program.uniforms,i=e.handler.gl,s=this._entityCollection;i.uniform3fv(t.uScaleByDistance,s.scaleByDistance),i.uniform1f(t.useLighting,s._useLighting),i.uniform3fv(t.eyePositionHigh,e.activeCamera.eyeHigh),i.uniform3fv(t.eyePositionLow,e.activeCamera.eyeLow),i.uniform3fv(t.rtcEyePositionHigh,this._rtcEyePositionHigh),i.uniform3fv(t.rtcEyePositionLow,this._rtcEyePositionLow),i.uniformMatrix4fv(t.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),i.uniformMatrix4fv(t.viewMatrix,!1,e.activeCamera.getViewMatrix()),i.uniform3fv(t.sunPosition,this._renderNode._lightPosition)}_displayOpaquePASS(){let e=this._renderer.handler.programs.geo_object,t=e._program;e.activate(),this._bindCommon();for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].drawOpaque(t)}_displayTransparentPASS(){let e=this._renderer.handler.programs.geo_object,t=e._program;e.activate(),this._bindCommon();for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].drawTransparent(t)}_depthPASS(){let e=this._renderer,t=e.handler.programs.geo_object_depth,i=t._program,s=i.uniforms,r=i.attributes,n=e.handler.gl,o=this._entityCollection,a=e.activeCamera;t.activate(),n.uniform3fv(s.uScaleByDistance,o.scaleByDistance),n.uniform3fv(s.rtcEyePositionHigh,this._rtcEyePositionHigh),n.uniform3fv(s.rtcEyePositionLow,this._rtcEyePositionLow),n.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniform1f(s.frustumPickingColor,a.frustumColorIndex);for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];n.bindBuffer(n.ARRAY_BUFFER,t._qRotBuffer),n.vertexAttribPointer(r.qRot,t._qRotBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._sizeBuffer),n.vertexAttribPointer(r.aScale,t._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._translateBuffer),n.vertexAttribPointer(r.aTranslate,t._translateBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._localPositionBuffer),n.vertexAttribPointer(r.aLocalPosition,t._localPositionBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._rtcPositionHighBuffer),n.vertexAttribPointer(r.aRTCPositionHigh,t._rtcPositionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._rtcPositionLowBuffer),n.vertexAttribPointer(r.aRTCPositionLow,t._rtcPositionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._visibleBuffer),n.vertexAttribPointer(r.aDispose,t._visibleBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._vertexBuffer),n.vertexAttribPointer(r.aVertexPosition,t._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(n.TRIANGLES,t._indicesBuffer.numItems,n.UNSIGNED_INT,0,t.numInstances)}}drawDepth(){this._geoObjects.length&&this._depthPASS()}drawPicking(){this._geoObjects.length&&this.pickingEnabled&&this._pickingPASS()}_pickingPASS(){let e=this._renderer,t=e.handler.programs.geo_object_picking,i=t._program,s=i.uniforms,r=i.attributes,n=e.handler.gl,o=this._entityCollection;t.activate(),n.uniform3fv(s.uScaleByDistance,o.scaleByDistance),n.uniform3fv(s.pickingScale,o.pickingScale),n.uniform3fv(s.rtcEyePositionHigh,this._rtcEyePositionHigh),n.uniform3fv(s.rtcEyePositionLow,this._rtcEyePositionLow),n.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix());for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];n.bindBuffer(n.ARRAY_BUFFER,t._qRotBuffer),n.vertexAttribPointer(r.qRot,t._qRotBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._sizeBuffer),n.vertexAttribPointer(r.aScale,t._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._translateBuffer),n.vertexAttribPointer(r.aTranslate,t._translateBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._localPositionBuffer),n.vertexAttribPointer(r.aLocalPosition,t._localPositionBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._pickingColorBuffer),n.vertexAttribPointer(r.aPickingColor,t._pickingColorBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._rtcPositionHighBuffer),n.vertexAttribPointer(r.aRTCPositionHigh,t._rtcPositionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._rtcPositionLowBuffer),n.vertexAttribPointer(r.aRTCPositionLow,t._rtcPositionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._visibleBuffer),n.vertexAttribPointer(r.aDispose,t._visibleBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._vertexBuffer),n.vertexAttribPointer(r.aVertexPosition,t._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(n.TRIANGLES,t._indicesBuffer.numItems,n.UNSIGNED_INT,0,t.numInstances)}}setQRotArr(e,t,i){Tt(e._qRotArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[Ko]=!0,this._updateTag(e)}setVisibility(e,t,i){Tt(e._visibleArr,t,1,1,i?1:0),e._changedBuffers[ta]=!0,this._updateTag(e)}setRTCPositionArr(e,t,i,s){Tt(e._rtcPositionHighArr,t,3,3,i.x,i.y,i.z),Tt(e._rtcPositionLowArr,t,3,3,s.x,s.y,s.z),e._changedBuffers[Wo]=!0,this._updateTag(e)}setRgbaArr(e,t,i){Tt(e._rgbaArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[$o]=!0,this._updateTag(e)}setPickingColorArr(e,t,i){Tt(e._pickingColorArr,t,3,3,i.x/255,i.y/255,i.z/255),e._changedBuffers[Jo]=!0,this._updateTag(e)}setScaleArr(e,t,i){Tt(e._sizeArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[Qo]=!0,this._updateTag(e)}setTranslateArr(e,t,i){Tt(e._translateArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[ia]=!0,this._updateTag(e)}setLocalPositionArr(e,t,i){Tt(e._localPositionArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[sa]=!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()}getRTCPosition(e,t,i){let s=e.sub(this._relativeCenter);v.doubleToTwoFloats(s,t,i)}setRelativeCenter(e){this._relativeCenter.copy(e);for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e].geoObjects;for(let e=0;e<t.length;e++)t[e].updateRTCPosition()}}_updateRTCEyePosition(){let e=this._renderer;if(e.activeCamera.isFirstPass){let t=e.activeCamera.eye.sub(this._relativeCenter);v.doubleToTwoFloat32Array(t,this._rtcEyePositionHigh,this._rtcEyePositionLow)}}draw(){this._geoObjects.length&&(this._updateRTCEyePosition(),this.update(),this._displayOpaquePASS())}drawTransparent(){this._geoObjects.length&&this._displayTransparentPASS()}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._geoObjects.length,this._geoObjects.push(e),this._addGeoObjectToArray(e),e.updateRotation(),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 s=!1;if(0===t.numInstances){t.clear(),this._instanceDataMap.delete(i);for(let e=0;this._instanceDataMapValues.length;e++)if(0===this._instanceDataMapValues[e].numInstances){this._instanceDataMapValues.splice(e,1);break}this._clearDataTagQueue(),s=!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,s=t.geoObjects.length;i<s;i++){let e=t.geoObjects[i];e._tagDataIndex=e._tagDataIndex-1}t._rgbaArr=Et(t._rgbaArr,4*r,4),t._rtcPositionHighArr=Et(t._rtcPositionHighArr,3*r,3),t._rtcPositionLowArr=Et(t._rtcPositionLowArr,3*r,3),t._qRotArr=Et(t._qRotArr,4*r,4),t._pickingColorArr=Et(t._pickingColorArr,3*r,3),t._sizeArr=Et(t._sizeArr,3*r,3),t._translateArr=Et(t._translateArr,3*r,3),t._localPositionArr=Et(t._localPositionArr,3*r,3),t._visibleArr=Et(t._visibleArr,r,1),e._handlerIndex=-1,e._handler=null,e._tagDataIndex=-1,e._tagData=null,s||(t.refresh(),this._updateTag(t))}};ws.__counter__=0;let Ar=ws;const ze=-1;class nl extends ns{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 X("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#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}in float a_outline;in vec4 a_gliphParam;in vec2 a_vertices;in vec4 a_texCoord;in vec3 a_positionsHigh;in vec3 a_positionsLow;in vec3 a_offset;in float a_size;in float a_rotation;in vec4 a_rgba;in float a_fontIndex;out vec2 v_uv;out vec4 v_rgba;flat out int v_fontIndex;out vec4 v_outlineColor;flat out float v_outline;uniform vec2 viewport;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float planetRadius;uniform vec3 scaleByDistance;uniform float opacity;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){if(a_texCoord.w==EMPTY){gl_Position=vec4(0.0);v_fontIndex=-1;return;}vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;v_outline=a_outline;v_fontIndex=int(a_fontIndex);v_uv=a_texCoord.xy;vec3 look=a_positions-cameraPos;float lookDist=length(look);v_rgba=a_rgba;if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(scaleByDistance[0],scaleByDistance[1],lookDist))*(1.0-step(scaleByDistance[2],lookDist));v_rgba.a*=opacity;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 vert=a_vertices;vec4 gp=a_gliphParam;if(a_texCoord.w==RTL){vert.x=step(vert.x*0.5+1.0,1.0);gp.x=-a_gliphParam.x;gp.z=-(a_gliphParam.z+a_texCoord.z);}else{gp.z=a_gliphParam.z+a_texCoord.z;}vec2 v=screenPos+rotate2d(a_rotation)*((vert*gp.xy+gp.zw)*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"#version 300 es\nuniform int isOutlinePass;precision highp float;const int MAX_SIZE=11;uniform sampler2D fontTextureArr[MAX_SIZE];uniform vec4 sdfParamsArr[MAX_SIZE];flat in int v_fontIndex;in vec2 v_uv;in vec4 v_rgba;flat in float v_outline;in vec3 v_pickingColor;layout(location=0)out vec4 outScreen;float median(float r,float g,float b){return max(min(r,g),min(max(r,g),b));}float getDistance(){vec3 msdf;if(v_fontIndex==0){msdf=texture(fontTextureArr[0],v_uv).rgb;}else if(v_fontIndex==1){msdf=texture(fontTextureArr[1],v_uv).rgb;}else if(v_fontIndex==2){msdf=texture(fontTextureArr[2],v_uv).rgb;}else if(v_fontIndex==3){msdf=texture(fontTextureArr[3],v_uv).rgb;}else if(v_fontIndex==4){msdf=texture(fontTextureArr[4],v_uv).rgb;}else if(v_fontIndex==5){msdf=texture(fontTextureArr[5],v_uv).rgb;}else if(v_fontIndex==6){msdf=texture(fontTextureArr[6],v_uv).rgb;}else if(v_fontIndex==7){msdf=texture(fontTextureArr[7],v_uv).rgb;}else if(v_fontIndex==8){msdf=texture(fontTextureArr[8],v_uv).rgb;}else if(v_fontIndex==9){msdf=texture(fontTextureArr[9],v_uv).rgb;}else if(v_fontIndex==10){msdf=texture(fontTextureArr[10],v_uv).rgb;}return median(msdf.r,msdf.g,msdf.b);}void main(){if(v_fontIndex==-1){return;}vec4 sdfParams=sdfParamsArr[v_fontIndex];float sd=getDistance();vec2 dxdy=fwidth(v_uv)*sdfParams.xy;if(isOutlinePass==0){float dist=sd+min(0.001,0.5-1.0/sdfParams.w)-0.5;float opacity=clamp(dist*sdfParams.w/length(dxdy)+0.5,0.0,1.0);if(opacity<=0.1){discard;}outScreen=vec4(v_rgba.rgb,opacity*v_rgba.a);}else{float dist=sd+min(v_outline,0.5-1.0/sdfParams.w)-0.5;float opacity=clamp(dist*sdfParams.w/length(dxdy)+0.5,0.0,1.0);if(opacity<=0.1){discard;}outScreen=vec4(v_rgba.rgb,opacity*v_rgba.a);}}"})):this._renderer.handler.addProgram(new X("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:"#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}attribute float a_outline;attribute vec4 a_gliphParam;attribute vec2 a_vertices;attribute vec4 a_texCoord;attribute vec3 a_positionsHigh;attribute vec3 a_positionsLow;attribute vec3 a_offset;attribute float a_size;attribute float a_rotation;attribute vec4 a_rgba;attribute float a_fontIndex;varying float v_outline;varying vec2 v_uv;varying vec4 v_rgba;varying float v_fontIndex;uniform vec2 viewport;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float planetRadius;uniform vec3 scaleByDistance;uniform float opacity;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){if(a_texCoord.w==EMPTY){gl_Position=vec4(0.0);v_fontIndex=-1.0;return;}vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;v_outline=a_outline;v_uv=vec2(a_texCoord.xy);v_rgba=a_rgba;v_fontIndex=a_fontIndex;vec3 look=a_positions-cameraPos;float lookDist=length(look);if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(scaleByDistance[0],scaleByDistance[1],lookDist))*(1.0-step(scaleByDistance[2],lookDist));v_rgba.a*=opacity;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 vert=a_vertices;vec4 gp=a_gliphParam;if(a_texCoord.w==RTL){vert.x=step(vert.x*0.5+1.0,1.0);gp.x=-a_gliphParam.x;gp.z=-(a_gliphParam.z+a_texCoord.z);}else{gp.z=a_gliphParam.z+a_texCoord.z;}vec2 v=screenPos+rotate2d(a_rotation)*((vert*gp.xy+gp.zw)*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"#extension GL_OES_standard_derivatives: enable\nprecision highp float;precision highp int;const int MAX_SIZE=11;uniform sampler2D fontTextureArr[MAX_SIZE];uniform vec4 sdfParamsArr[MAX_SIZE];uniform int isOutlinePass;varying float v_outline;varying vec2 v_uv;varying vec4 v_rgba;varying float v_fontIndex;float fontIndex;float median(float r,float g,float b){return max(min(r,g),min(max(r,g),b));}float getDistance(){vec3 msdf;if(fontIndex>=0.0&&fontIndex<1.0){msdf=texture2D(fontTextureArr[0],v_uv).rgb;}else if(fontIndex>=1.0&&fontIndex<2.0){msdf=texture2D(fontTextureArr[1],v_uv).rgb;}else if(fontIndex>=2.0&&fontIndex<3.0){msdf=texture2D(fontTextureArr[2],v_uv).rgb;}else if(fontIndex>=3.0&&fontIndex<4.0){msdf=texture2D(fontTextureArr[3],v_uv).rgb;}else if(fontIndex>=4.0&&fontIndex<5.0){msdf=texture2D(fontTextureArr[4],v_uv).rgb;}else if(fontIndex>=5.0&&fontIndex<6.0){msdf=texture2D(fontTextureArr[5],v_uv).rgb;}else if(fontIndex>=6.0&&fontIndex<7.0){msdf=texture2D(fontTextureArr[6],v_uv).rgb;}else if(fontIndex>=7.0&&fontIndex<8.0){msdf=texture2D(fontTextureArr[7],v_uv).rgb;}else if(fontIndex>=8.0&&fontIndex<9.0){msdf=texture2D(fontTextureArr[8],v_uv).rgb;}else if(fontIndex>=9.0&&fontIndex<10.0){msdf=texture2D(fontTextureArr[9],v_uv).rgb;}else if(fontIndex>=10.0&&fontIndex<11.0){msdf=texture2D(fontTextureArr[10],v_uv).rgb;}return median(msdf.r,msdf.g,msdf.b);}vec4 getSDFParams(){if(fontIndex>=0.0&&fontIndex<1.0){return sdfParamsArr[0];}else if(fontIndex>=1.0&&fontIndex<2.0){return sdfParamsArr[1];}else if(fontIndex>=2.0&&fontIndex<3.0){return sdfParamsArr[2];}else if(fontIndex>=3.0&&fontIndex<4.0){return sdfParamsArr[3];}else if(fontIndex>=4.0&&fontIndex<5.0){return sdfParamsArr[4];}else if(fontIndex>=5.0&&fontIndex<6.0){return sdfParamsArr[5];}else if(fontIndex>=6.0&&fontIndex<7.0){return sdfParamsArr[6];}else if(fontIndex>=7.0&&fontIndex<8.0){return sdfParamsArr[7];}else if(fontIndex>=8.0&&fontIndex<9.0){return sdfParamsArr[8];}else if(fontIndex>=9.0&&fontIndex<10.0){return sdfParamsArr[9];}else if(fontIndex>=10.0&&fontIndex<11.0){return sdfParamsArr[10];}}void main(){fontIndex=v_fontIndex+0.1;if(v_fontIndex<0.0){return;}vec4 sdfParams=getSDFParams();float sd=getDistance();vec2 dxdy=fwidth(v_uv)*sdfParams.xy;float dist=sd+min(0.001,0.5-1.0/sdfParams.w)-0.5;float opacity=clamp(dist*sdfParams.w/length(dxdy)+0.5,0.0,1.0);if(isOutlinePass==0){}else{float strokeDist=sd+min(v_outline,0.5-1.0/sdfParams.w)-0.5;float strokeAlpha=v_rgba.a*clamp(strokeDist*sdfParams.w/length(dxdy)+0.5,0.0,1.0);if(strokeAlpha<0.1){discard;}}}"}))),this._renderer.handler.programs.labelPicking||this._renderer.handler.addProgram(new X("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:"#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}attribute vec4 a_gliphParam;attribute vec2 a_vertices;attribute vec4 a_texCoord;attribute vec3 a_positionsHigh;attribute vec3 a_positionsLow;attribute vec3 a_offset;attribute float a_size;attribute float a_rotation;attribute vec4 a_rgba;varying vec4 v_rgba;uniform vec2 viewport;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float planetRadius;uniform vec3 scaleByDistance;uniform float opacity;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;v_rgba=a_rgba;if(a_texCoord.w==EMPTY){v_rgba.a=0.0;gl_Position=vec4(0.0);return;}vec3 look=a_positions-cameraPos;float lookDist=length(look);if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(scaleByDistance[0],scaleByDistance[1],lookDist))*(1.0-step(scaleByDistance[2],lookDist));v_rgba.a*=opacity;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 vert=a_vertices;vec4 gp=a_gliphParam;if(a_texCoord.w==RTL){vert.x=step(vert.x*0.5+1.0,1.0);gp.x=-a_gliphParam.x;gp.z=-(a_gliphParam.z+a_texCoord.z);}else{gp.z=a_gliphParam.z+a_texCoord.z;}vec2 v=screenPos+rotate2d(a_rotation)*((vert*gp.xy+gp.zw)*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"precision highp float;varying vec4 v_rgba;varying vec3 v_pickingColor;void main(){vec4 color=v_rgba;if(color.a<0.05){return;}gl_FragColor=vec4(v_rgba.rgb,v_rgba.a);}"})))}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){-1!==t._lockId&&t._handler&&this.isEqual(t._handler)&&(t._isReady=!0,t._lockId=-1,t._handlerIndex=this._billboards.length,this._billboards.push(t),this._vertexArr=it(this._vertexArr,e.vertexArr),this._texCoordArr=it(this._texCoordArr,e.texCoordArr),this._gliphParamArr=it(this._gliphParamArr,e.gliphParamArr),this._positionHighArr=it(this._positionHighArr,e.positionHighArr),this._positionLowArr=it(this._positionLowArr,e.positionLowArr),this._sizeArr=it(this._sizeArr,e.sizeArr),this._offsetArr=it(this._offsetArr,e.offsetArr),this._rgbaArr=it(this._rgbaArr,e.rgbaArr),this._rotationArr=it(this._rotationArr,e.rotationArr),this._fontIndexArr=it(this._fontIndexArr,e.fontIndexArr),this._outlineArr=it(this._outlineArr,e.outlineArr),this._outlineColorArr=it(this._outlineColorArr,e.outlineColorArr),this._pickingColorArr=it(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,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection;n.disable(n.CULL_FACE),n.uniform1iv(r.fontTextureArr,e.fontAtlas.samplerArr),n.uniform4fv(r.sdfParamsArr,e.fontAtlas.sdfParamsArr),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform3fv(r.scaleByDistance,o.scaleByDistance),n.uniform1f(r.opacity,o._fadingOpacity),n.uniform1f(r.planetRadius,o.renderNode._planetRadius2||0),n.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),n.bindBuffer(n.ARRAY_BUFFER,this._texCoordBuffer),n.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._gliphParamBuffer),n.vertexAttribPointer(s.a_gliphParam,this._gliphParamBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionHighBuffer),n.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionLowBuffer),n.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._sizeBuffer),n.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._rotationBuffer),n.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._offsetBuffer),n.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._fontIndexBuffer),n.vertexAttribPointer(s.a_fontIndex,this._fontIndexBuffer.itemSize,n.FLOAT,!1,0,0),n.uniform1i(r.isOutlinePass,1),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.bindBuffer(n.ARRAY_BUFFER,this._outlineColorBuffer),n.vertexAttribPointer(s.a_rgba,this._outlineColorBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._outlineBuffer),n.vertexAttribPointer(s.a_outline,this._outlineBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.depthFunc(n.EQUAL),n.uniform1i(r.isOutlinePass,0),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.bindBuffer(n.ARRAY_BUFFER,this._rgbaBuffer),n.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.depthFunc(n.LESS),n.enable(n.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.labelPicking.activate();let i=t.programs.labelPicking._program,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection,a=o.renderNode;n.disable(n.CULL_FACE),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform3fv(r.scaleByDistance,o.scaleByDistance),n.uniform1f(r.opacity,o._fadingOpacity),n.uniform1f(r.planetRadius,a._planetRadius2||0),n.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),n.bindBuffer(n.ARRAY_BUFFER,this._texCoordBuffer),n.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._gliphParamBuffer),n.vertexAttribPointer(s.a_gliphParam,this._gliphParamBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionHighBuffer),n.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionLowBuffer),n.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._sizeBuffer),n.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._rotationBuffer),n.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._offsetBuffer),n.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._pickingColorBuffer),n.vertexAttribPointer(s.a_rgba,this._pickingColorBuffer.itemSize,n.FLOAT,!1,0,0),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.enable(n.CULL_FACE)}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*this._maxLetters,s=t*i;this._rgbaArr=ot(this._rgbaArr,s,i),this._outlineColorArr=ot(this._outlineColorArr,s,i),this._texCoordArr=ot(this._texCoordArr,s,i),this._gliphParamArr=ot(this._gliphParamArr,s,i),i=18*this._maxLetters,s=t*i,this._positionHighArr=ot(this._positionHighArr,s,i),this._positionLowArr=ot(this._positionLowArr,s,i),this._offsetArr=ot(this._offsetArr,s,i),this._pickingColorArr=ot(this._pickingColorArr,s,i),i=12*this._maxLetters,s=t*i,this._vertexArr=ot(this._vertexArr,s,i),i=6*this._maxLetters,s=t*i,this._sizeArr=ot(this._sizeArr,s,i),this._rotationArr=ot(this._rotationArr,s,i),this._fontIndexArr=ot(this._fontIndexArr,s,i),this._outlineArr=ot(this._outlineArr,s,i),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1}setText(e,t,i,s,r=0,n=!1){t=t.normalize("NFKC");let o=this._renderer.fontAtlas.atlasesArr[i];if(!o)return;let a=24*e*this._maxLetters,l=this._texCoordArr,h=this._gliphParamArr,c=0,d=Math.min(this._maxLetters,t.length),_=0;n&&(_=1);let u=0,f=o.kernings;for(c=0;c<d;c++){let e=a+24*c,i=t[c],s=o.get(i.charCodeAt(0))||o.get(32);if(!s)continue;let n=s.texCoords,d=s.metrics;l[e]=n[0],l[e+1]=n[1],l[e+2]=u,l[e+3]=_,l[e+4]=n[2],l[e+5]=n[3],l[e+6]=u,l[e+7]=_,l[e+8]=n[4],l[e+9]=n[5],l[e+10]=u,l[e+11]=_,l[e+12]=n[6],l[e+13]=n[7],l[e+14]=u,l[e+15]=_,l[e+16]=n[8],l[e+17]=n[9],l[e+18]=u,l[e+19]=_,l[e+20]=n[10],l[e+21]=n[11],l[e+22]=u,l[e+23]=_,h[e]=d.nWidth,h[e+1]=d.nHeight,h[e+2]=d.nXOffset,h[e+3]=d.nYOffset,h[e+4]=d.nWidth,h[e+5]=d.nHeight,h[e+6]=d.nXOffset,h[e+7]=d.nYOffset,h[e+8]=d.nWidth,h[e+9]=d.nHeight,h[e+10]=d.nXOffset,h[e+11]=d.nYOffset,h[e+12]=d.nWidth,h[e+13]=d.nHeight,h[e+14]=d.nXOffset,h[e+15]=d.nYOffset,h[e+16]=d.nWidth,h[e+17]=d.nHeight,h[e+18]=d.nXOffset,h[e+19]=d.nYOffset,h[e+20]=d.nWidth,h[e+21]=d.nHeight,h[e+22]=d.nXOffset,h[e+23]=d.nYOffset;let g=f[i.charCodeAt(0)];if(g&&t[c+1]){let e=g[t[c+1].charCodeAt(0)];u+=e?d.nAdvance+e+r:d.nAdvance+r}else u+=d.nAdvance+r}if(s===_i.CENTER)for(u*=-.5,c=0;c<d;c++){let e=a+24*c;l[e+2]+=u,l[e+6]+=u,l[e+10]+=u,l[e+14]+=u,l[e+18]+=u,l[e+22]+=u}for(;c<this._maxLetters;c++){let e=a+24*c;l[e+3]=-1,l[e+7]=-1,l[e+11]=-1,l[e+15]=-1,l[e+19]=-1,l[e+23]=-1}this._changedBuffers[6]=!0}setPositionArr(e,t,i){let s=18*e*this._maxLetters,r=this._positionHighArr,n=t.x,o=t.y,a=t.z,l=this._positionLowArr,h=i.x,c=i.y,d=i.z;for(let e=0;e<this._maxLetters;e++){let t=s+18*e;r[t]=n,r[t+1]=o,r[t+2]=a,r[t+3]=n,r[t+4]=o,r[t+5]=a,r[t+6]=n,r[t+7]=o,r[t+8]=a,r[t+9]=n,r[t+10]=o,r[t+11]=a,r[t+12]=n,r[t+13]=o,r[t+14]=a,r[t+15]=n,r[t+16]=o,r[t+17]=a,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,s=this._pickingColorArr,r=t.x/255,n=t.y/255,o=t.z/255;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;s[t]=r,s[t+1]=n,s[t+2]=o,s[t+3]=r,s[t+4]=n,s[t+5]=o,s[t+6]=r,s[t+7]=n,s[t+8]=o,s[t+9]=r,s[t+10]=n,s[t+11]=o,s[t+12]=r,s[t+13]=n,s[t+14]=o,s[t+15]=r,s[t+16]=n,s[t+17]=o}this._changedBuffers[0]=!0}setSizeArr(e,t){let i=6*e*this._maxLetters,s=this._sizeArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;s[r]=t,s[r+1]=t,s[r+2]=t,s[r+3]=t,s[r+4]=t,s[r+5]=t}this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e*this._maxLetters,s=this._offsetArr,r=t.x,n=t.y,o=t.z;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;s[t]=r,s[t+1]=n,s[t+2]=o,s[t+3]=r,s[t+4]=n,s[t+5]=o,s[t+6]=r,s[t+7]=n,s[t+8]=o,s[t+9]=r,s[t+10]=n,s[t+11]=o,s[t+12]=r,s[t+13]=n,s[t+14]=o,s[t+15]=r,s[t+16]=n,s[t+17]=o}this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e*this._maxLetters,s=this._rgbaArr,r=t.x,n=t.y,o=t.z,a=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;s[t]=r,s[t+1]=n,s[t+2]=o,s[t+3]=a,s[t+4]=r,s[t+5]=n,s[t+6]=o,s[t+7]=a,s[t+8]=r,s[t+9]=n,s[t+10]=o,s[t+11]=a,s[t+12]=r,s[t+13]=n,s[t+14]=o,s[t+15]=a,s[t+16]=r,s[t+17]=n,s[t+18]=o,s[t+19]=a,s[t+20]=r,s[t+21]=n,s[t+22]=o,s[t+23]=a}this._changedBuffers[4]=!0}setOutlineColorArr(e,t){let i=24*e*this._maxLetters,s=this._outlineColorArr,r=t.x,n=t.y,o=t.z,a=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;s[t]=r,s[t+1]=n,s[t+2]=o,s[t+3]=a,s[t+4]=r,s[t+5]=n,s[t+6]=o,s[t+7]=a,s[t+8]=r,s[t+9]=n,s[t+10]=o,s[t+11]=a,s[t+12]=r,s[t+13]=n,s[t+14]=o,s[t+15]=a,s[t+16]=r,s[t+17]=n,s[t+18]=o,s[t+19]=a,s[t+20]=r,s[t+21]=n,s[t+22]=o,s[t+23]=a}this._changedBuffers[10]=!0}setOutlineArr(e,t){let i=6*e*this._maxLetters,s=this._outlineArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;s[r]=t,s[r+1]=t,s[r+2]=t,s[r+3]=t,s[r+4]=t,s[r+5]=t}this._changedBuffers[9]=!0}setRotationArr(e,t){let i=6*e*this._maxLetters,s=this._rotationArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;s[r]=t,s[r+1]=t,s[r+2]=t,s[r+3]=t,s[r+4]=t,s[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,s=this._vertexArr;for(let e=0;e<this._maxLetters;e++){let r=i+12*e;s[r]=t[0],s[r+1]=t[1],s[r+2]=t[2],s[r+3]=t[3],s[r+4]=t[4],s[r+5]=t[5],s[r+6]=t[6],s[r+7]=t[7],s[r+8]=t[8],s[r+9]=t[9],s[r+10]=t[10],s[r+11]=t[11]}this._changedBuffers[7]=!0}setFontIndexArr(e,t){let i=6*e*this._maxLetters,s=this._fontIndexArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;s[r]=t,s[r+1]=t,s[r+2]=t,s[r+3]=t,s[r+4]=t,s[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}}const Ts=class e{constructor(t){this.pickingEnabled=!0,this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,this._renderer=null,this._pointClouds=[]}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.pointCloud||this._renderer.handler.addProgram(new X("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=[]}};Ts.__counter__=0;let Lr=Ts;const Cs=class e{constructor(t){this.__id=e.__counter__++,this._entityCollection=t,this._renderer=null,this._polylines=[],this.pickingEnabled=!0,this._relativeCenter=new v,this._rtcEyePositionHigh=new Float32Array([0,0,0]),this._rtcEyePositionLow=new Float32Array([0,0,0])}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.polyline_screen||this._renderer.handler.addProgram(new X("polyline_screen",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",thickness:"float",opacity:"float",depthOffset:"float",visibleSphere:"vec4",texAtlas:"sampler2d",strokeSize:"float",texOffset:"float"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float",color:"vec4",texCoord:"vec4"},vertexShader:"#version 300 es\nprecision highp float;in vec3 prevHigh;in vec3 currentHigh;in vec3 nextHigh;in vec3 prevLow;in vec3 currentLow;in vec3 nextLow;in vec4 texCoord;in float order;in vec4 color;uniform float thickness;uniform mat4 proj;uniform mat4 view;uniform vec2 viewport;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;uniform float opacity;uniform float depthOffset;uniform float strokeSize;uniform float texOffset;out vec4 v_rgba;out vec3 vPos;out vec3 uCamPos;out vec4 vTexCoord;flat out float repeat;flat out float v_texOffset;const float NEAR=-1.0;vec2 getIntersection(vec2 start1,vec2 end1,vec2 start2,vec2 end2){vec2 dir=end2-start2;vec2 perp=vec2(-dir.y,dir.x);float d2=dot(perp,start2);float seg=dot(perp,start1)-d2;float prl=seg-dot(perp,end1)+d2;if(prl>-1.0&&prl<1.0){return start1;}float u=seg/prl;return start1+u*(end1-start1);}vec2 project(vec4 p){return(0.5*p.xyz/p.w+0.5).xy*viewport;}void main(){uCamPos=rtcEyePositionHigh+rtcEyePositionLow;vPos=currentHigh+currentLow;v_rgba=vec4(color.rgb,color.a*opacity);mat4 viewMatrixRTE=view;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff,lowDiff;highDiff=currentHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=currentLow-rtcEyePositionLow;vec4 vCurrent=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=prevHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=prevLow-rtcEyePositionLow;vec4 vPrev=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=nextHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=nextLow-rtcEyePositionLow;vec4 vNext=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);if(vCurrent.z>NEAR){if(vPrev.z<NEAR&&abs(order)==1.0){vCurrent=vPrev+(vCurrent-vPrev)*(NEAR-vPrev.z)/(vCurrent.z-vPrev.z);}else if(vNext.z<NEAR&&abs(order)==2.0){vCurrent=vNext+(vCurrent-vNext)*(NEAR-vNext.z)/(vCurrent.z-vNext.z);}}vec4 dCurrent=proj*vCurrent;vec2 _next=project(proj*vNext);vec2 _prev=project(proj*vPrev);vec2 _current=project(dCurrent);if(_prev==_current){if(_next==_current){_next=_current+vec2(1.0,0.0);_prev=_current-_next;}else{_prev=_current+normalize(_current-_next);}}if(_next==_current){_next=_current+normalize(_current-_prev);}vec2 sNext=_next,sCurrent=_current,sPrev=_prev;vec2 dirNext=normalize(sNext-sCurrent);vec2 dirPrev=normalize(sPrev-sCurrent);float dotNP=dot(dirNext,dirPrev);vec2 normalNext=normalize(vec2(-dirNext.y,dirNext.x));vec2 normalPrev=normalize(vec2(dirPrev.y,-dirPrev.x));float d=thickness*sign(order);vTexCoord=texCoord;vec2 m;if(dotNP>=0.99991){m=sCurrent-normalPrev*d;}else{m=getIntersection(sCurrent+normalPrev*d,sPrev+normalPrev*d,sCurrent+normalNext*d,sNext+normalNext*d);if(dotNP>0.5&&dot(dirNext+dirPrev,m-sCurrent)<0.0){float occw=order*sign(dirNext.x*dirPrev.y-dirNext.y*dirPrev.x);if(occw==-1.0){m=sCurrent+normalPrev*d;}else if(occw==1.0){m=sCurrent+normalNext*d;}else if(occw==-2.0){m=sCurrent+normalNext*d;}else if(occw==2.0){m=sCurrent+normalPrev*d;}}else if(distance(sCurrent,m)>min(distance(sCurrent,sNext),distance(sCurrent,sPrev))){m=sCurrent+normalNext*d;}}repeat=min(distance(sCurrent,sPrev),viewport.y)/strokeSize;v_texOffset=texOffset;gl_Position=vec4((2.0*m/viewport-1.0)*dCurrent.w,dCurrent.z+depthOffset,dCurrent.w);}",fragmentShader:"#version 300 es\nprecision highp float;uniform sampler2D texAtlas;uniform vec4 visibleSphere;in vec3 uCamPos;in vec4 v_rgba;in vec3 vPos;in vec4 vTexCoord;flat in float repeat;flat in float v_texOffset;out vec4 fragColor;void main(){if(visibleSphere.w!=0.0){vec3 cam_dir=normalize(vPos-uCamPos);vec3 sph_dir=normalize(vPos-visibleSphere.xyz);if(dot(cam_dir,sph_dir)>0.11){discard;}}float height=vTexCoord.w;if(height==0.0){fragColor=vec4(v_rgba.rgb,v_rgba.a);}else{vec2 uv=vTexCoord.xy;float min=vTexCoord.z;float EPS=0.5/1024.0;float localY=fract((uv.y+v_texOffset-min)/height*repeat);uv.y=clamp(min+localY*height,min+EPS,min+height-EPS);vec4 color=texture(texAtlas,uv);color.a*=v_rgba.a;fragColor=color;}}"})),this._renderer.handler.programs.polyline_picking||this._renderer.handler.addProgram(new X("polyline_picking",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",color:"vec4",thickness:"float",depthOffset:"float",visibleSphere:"vec4"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float"},vertexShader:"precision highp float;attribute vec3 prevHigh;attribute vec3 currentHigh;attribute vec3 nextHigh;attribute vec3 prevLow;attribute vec3 currentLow;attribute vec3 nextLow;attribute float order;uniform float thickness;uniform vec4 color;uniform mat4 proj;uniform mat4 view;uniform vec2 viewport;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;uniform float depthOffset;varying vec4 vColor;varying vec3 vPos;varying vec3 uCamPos;const float NEAR=-1.0;vec2 getIntersection(vec2 start1,vec2 end1,vec2 start2,vec2 end2){vec2 dir=end2-start2;vec2 perp=vec2(-dir.y,dir.x);float d2=dot(perp,start2);float seg=dot(perp,start1)-d2;float prl=seg-dot(perp,end1)+d2;if(prl>-1.0&&prl<1.0){return start1;}float u=seg/prl;return start1+u*(end1-start1);}vec2 project(vec4 p){return(0.5*p.xyz/p.w+0.5).xy*viewport;}void main(){uCamPos=rtcEyePositionHigh+rtcEyePositionLow;vPos=currentHigh+currentLow;vColor=color;vec3 highDiff,lowDiff;mat4 viewMatrixRTE=view;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);highDiff=currentHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=currentLow-rtcEyePositionLow;vec4 vCurrent=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=prevHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=prevLow-rtcEyePositionLow;vec4 vPrev=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=nextHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=nextLow-rtcEyePositionLow;vec4 vNext=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);if(vCurrent.z>NEAR){if(vPrev.z<NEAR&&abs(order)==1.0){vCurrent=vPrev+(vCurrent-vPrev)*(NEAR-vPrev.z)/(vCurrent.z-vPrev.z);}else if(vNext.z<NEAR&&abs(order)==2.0){vCurrent=vNext+(vCurrent-vNext)*(NEAR-vNext.z)/(vCurrent.z-vNext.z);}}vec4 dCurrent=proj*vCurrent;vec2 _next=project(proj*vNext);vec2 _prev=project(proj*vPrev);vec2 _current=project(dCurrent);if(_prev==_current){if(_next==_current){_next=_current+vec2(1.0,0.0);_prev=_current-_next;}else{_prev=_current+normalize(_current-_next);}}if(_next==_current){_next=_current+normalize(_current-_prev);}vec2 sNext=_next,sCurrent=_current,sPrev=_prev;vec2 dirNext=normalize(sNext-sCurrent);vec2 dirPrev=normalize(sPrev-sCurrent);float dotNP=dot(dirNext,dirPrev);vec2 normalNext=normalize(vec2(-dirNext.y,dirNext.x));vec2 normalPrev=normalize(vec2(dirPrev.y,-dirPrev.x));float d=thickness*sign(order);vec2 m;if(dotNP>=0.99991){m=sCurrent-normalPrev*d;}else{m=getIntersection(sCurrent+normalPrev*d,sPrev+normalPrev*d,sCurrent+normalNext*d,sNext+normalNext*d);if(dotNP>0.5&&dot(dirNext+dirPrev,m-sCurrent)<0.0){float occw=order*sign(dirNext.x*dirPrev.y-dirNext.y*dirPrev.x);if(occw==-1.0){m=sCurrent+normalPrev*d;}else if(occw==1.0){m=sCurrent+normalNext*d;}else if(occw==-2.0){m=sCurrent+normalNext*d;}else if(occw==2.0){m=sCurrent+normalPrev*d;}}else if(distance(sCurrent,m)>min(distance(sCurrent,sNext),distance(sCurrent,sPrev))){m=sCurrent+normalNext*d;}}gl_Position=vec4((2.0*m/viewport-1.0)*dCurrent.w,dCurrent.z+depthOffset,dCurrent.w);}",fragmentShader:"precision highp float;uniform vec4 visibleSphere;varying vec3 uCamPos;varying vec4 vColor;varying vec3 vPos;void main(){if(visibleSphere.w!=0.0){vec3 cam_dir=normalize(vPos-uCamPos);vec3 sph_dir=normalize(vPos-visibleSphere.xyz);if(dot(cam_dir,sph_dir)>0.11){discard;}}gl_FragColor=vec4(vColor.rgb,vColor.a);}"})))}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,e.__doubleToTwoFloats=this.getRTCPosition.bind(this),this._polylines.push(e),this._entityCollection&&this._entityCollection.renderNode&&(e.setRenderNode(this._entityCollection.renderNode),e.updateRTCPosition()))}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(){this._updateRTCEyePosition();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=[]}getRTCPosition(e,t,i){let s=e.sub(this._relativeCenter);v.doubleToTwoFloats(s,t,i)}setRelativeCenter(e){this._relativeCenter.copy(e);for(let e=0;e<this._polylines.length;e++)this._polylines[e].updateRTCPosition()}_updateRTCEyePosition(){let e=this._renderer;if(e.activeCamera.isFirstPass){let t=e.activeCamera.eye.sub(this._relativeCenter);v.doubleToTwoFloat32Array(t,this._rtcEyePositionHigh,this._rtcEyePositionLow)}}reloadTextures(){for(let e=0;e<this._polylines.length;e++){let t=this._polylines[e];t.setSrc(t.getSrc())}}get polylines(){return[...this._polylines]}refreshTexCoordsArr(){if(this._entityCollection&&this._renderer){let e=this._renderer.strokeTextureAtlas;for(let t=0;t<this._polylines.length;t++){let i=this._polylines[t],s=i.getImage();if(s){let t=e.get(s.__nodeIndex);t&&i._setTexCoordArr(t.texCoords)}}}}};Cs.__counter__=0;let Pr=Cs;const Es=class e{constructor(t){this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,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._texCoordBuffer=null,this._texOffsetBuffer=null,this._strokeSizeBuffer=null,this._vertexArr=[],this._startPositionHighArr=[],this._startPositionLowArr=[],this._endPositionHighArr=[],this._endPositionLowArr=[],this._thicknessArr=[],this._rgbaArr=[],this._pickingColorArr=[],this._texCoordArr=new Float32Array([]),this._texOffsetArr=new Float32Array([]),this._strokeSizeArr=new Float32Array([]),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._buffersUpdateCallbacks[6]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[7]=this.createTexOffsetBuffer,this._buffersUpdateCallbacks[8]=this.createStrokeSizeBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}reloadTextures(){for(let e=0;e<this._rays.length;e++){let t=this._rays[e];t.setSrc(t.getSrc())}}get rays(){return[...this._rays]}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.rayScreen||this._renderer.handler.addProgram(new X("rayScreen",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",resolution:"float",uOpacity:"float",texAtlas:"sampler2d",viewport:"vec2"},attributes:{a_vertices:"vec2",a_texCoord:"vec4",a_startPosHigh:"vec3",a_startPosLow:"vec3",a_endPosHigh:"vec3",a_endPosLow:"vec3",a_thickness:"float",a_rgba:"vec4",a_texOffset:"float",a_strokeSize:"float"},vertexShader:"#version 300 es\nprecision highp float;in vec4 a_rgba;in vec3 a_startPosHigh;in vec3 a_startPosLow;in vec3 a_endPosHigh;in vec3 a_endPosLow;in vec2 a_vertices;in float a_thickness;in vec4 a_texCoord;in float a_texOffset;in float a_strokeSize;out vec4 v_rgba;out vec4 v_texCoord;out float v_texOffset;flat out float repeat;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float resolution;uniform float uOpacity;uniform vec2 viewport;vec2 project(vec4 p){return(0.5*p.xyz/p.w+0.5).xy*viewport;}void main(){v_texOffset=a_texOffset;v_rgba=vec4(a_rgba.rgb,a_rgba.a*uOpacity);v_texCoord=a_texCoord;vec3 v=(a_endPosHigh-a_startPosHigh)+(a_endPosLow-a_startPosLow);vec3 look=(a_startPosHigh-eyePositionHigh)+(a_startPosLow-eyePositionLow)+v*a_vertices.y;vec3 up=normalize(v);vec3 right=normalize(cross(look,up));float dist=abs(dot(look,vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2])));float focalSize=2.0*dist*resolution;vec3 vert=right*a_thickness*focalSize*a_vertices.x;vec3 highDiff;if(a_vertices.y==0.0){highDiff=a_startPosHigh-eyePositionHigh;vert+=a_startPosLow-eyePositionLow;}else{highDiff=a_endPosHigh-eyePositionHigh;vert+=a_endPosLow-eyePositionLow;}mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff*step(1.0,length(highDiff))+vert,1.0);highDiff=a_startPosHigh-eyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));vec3 lowDiff=a_startPosLow-eyePositionLow;vec4 vStart=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=a_endPosHigh-eyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=a_endPosLow-eyePositionLow;vec4 vEnd=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec2 nStart=project(projectionMatrix*vStart);vec2 nEnd=project(projectionMatrix*vEnd);repeat=min(distance(nStart,nEnd),viewport.y)/a_strokeSize;}",fragmentShader:"#version 300 es\nprecision highp float;uniform sampler2D texAtlas;in vec4 v_rgba;in vec4 v_texCoord;in float v_texOffset;flat in float repeat;out vec4 fragColor;void main(){float height=v_texCoord.w;if(height==0.0){fragColor=v_rgba;}else{vec2 uv=v_texCoord.xy;float min=v_texCoord.z;float EPS=0.5/1024.0;float localY=fract((uv.y+v_texOffset-min)/height*repeat);uv.y=clamp(min+localY*height,min+EPS,min+height-EPS);vec4 color=texture(texAtlas,uv);fragColor=v_rgba*color;}}"})))}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._texCoordArr=null,this._texOffsetArr=null,this._strokeSizeArr=null,this._vertexArr=new Float32Array([]),this._texCoordArr=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._texOffsetArr=new Float32Array([]),this._strokeSizeArr=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),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._texOffsetBuffer),e.deleteBuffer(this._strokeSizeBuffer)),this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._texOffsetBuffer=null,this._strokeSizeBuffer=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=bt(this._vertexArr,[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]):this._vertexArr=bt(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t=e.texOffset;this._texOffsetArr=it(this._texOffsetArr,[t,t,t,t,t,t]),t=e.strokeSize,this._strokeSizeArr=it(this._strokeSizeArr,[t,t,t,t,t,t]),this._texCoordArr=it(this._texCoordArr,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),t=e._startPositionHigh.x;let i=e._startPositionHigh.y,s=e._startPositionHigh.z;this._startPositionHighArr=bt(this._startPositionHighArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._startPositionLow.x,i=e._startPositionLow.y,s=e._startPositionLow.z,this._startPositionLowArr=bt(this._startPositionLowArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._endPositionHigh.x,i=e._endPositionHigh.y,s=e._endPositionHigh.z,this._endPositionHighArr=bt(this._endPositionHighArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._endPositionLow.x,i=e._endPositionLow.y,s=e._endPositionLow.z,this._endPositionLowArr=bt(this._endPositionLowArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._thickness,this._thicknessArr=bt(this._thicknessArr,[t,t,t,t,t,t]);let r=e._startColor.x,n=e._startColor.y,o=e._startColor.z,a=e._startColor.w,l=e._endColor.x,h=e._endColor.y,c=e._endColor.z,d=e._endColor.w;this._rgbaArr=bt(this._rgbaArr,[l,h,c,d,r,n,o,a,r,n,o,a,r,n,o,a,l,h,c,d,l,h,c,d]),t=e._entity._pickingColor.x/255,i=e._entity._pickingColor.y/255,s=e._entity._pickingColor.z/255,this._pickingColorArr=bt(this._pickingColorArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s])}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.rayScreen.activate();let i=t.programs.rayScreen._program,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection;n.disable(n.CULL_FACE),n.uniform1f(r.uOpacity,o._fadingOpacity),n.uniform1i(r.u_texAtlas,0),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform1f(r.resolution,e.activeCamera._tanViewAngle_hradOneByHeight),n.uniform2fv(r.viewport,[e.handler.canvas.width,e.handler.canvas.height]),n.bindBuffer(n.ARRAY_BUFFER,this._startPositionHighBuffer),n.vertexAttribPointer(s.a_startPosHigh,this._startPositionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._startPositionLowBuffer),n.vertexAttribPointer(s.a_startPosLow,this._startPositionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._endPositionHighBuffer),n.vertexAttribPointer(s.a_endPosHigh,this._endPositionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._endPositionLowBuffer),n.vertexAttribPointer(s.a_endPosLow,this._endPositionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._rgbaBuffer),n.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._thicknessBuffer),n.vertexAttribPointer(s.a_thickness,this._thicknessBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._texCoordBuffer),n.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._texOffsetBuffer),n.vertexAttribPointer(s.a_texOffset,this._texOffsetBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._strokeSizeBuffer),n.vertexAttribPointer(s.a_strokeSize,this._strokeSizeBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.enable(n.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=Et(this._rgbaArr,i,24),this._texCoordArr=ot(this._texCoordArr,i,24),i=18*t,this._startPositionHighArr=Et(this._startPositionHighArr,i,18),this._startPositionLowArr=Et(this._startPositionLowArr,i,18),this._endPositionHighArr=Et(this._endPositionHighArr,i,18),this._endPositionLowArr=Et(this._endPositionLowArr,i,18),this._pickingColorArr=Et(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Et(this._vertexArr,i,12),i=6*t,this._thicknessArr=Et(this._thicknessArr,i,6),this._texOffsetArr=ot(this._texOffsetArr,i,6),this._strokeSizeArr=ot(this._strokeSizeArr,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 s=18*e,r=this._startPositionHighArr,n=t.x,o=t.y,a=t.z;r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,r=this._startPositionLowArr,n=i.x,o=i.y,a=i.z,r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,this._changedBuffers[1]=!0}setEndPositionArr(e,t,i){let s=18*e,r=this._endPositionHighArr,n=t.x,o=t.y,a=t.z;r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,r=this._endPositionLowArr,n=i.x,o=i.y,a=i.z,r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,this._changedBuffers[2]=!0}setPickingColorArr(e,t){let i=18*e,s=this._pickingColorArr,r=t.x/255,n=t.y/255,o=t.z/255;s[i]=r,s[i+1]=n,s[i+2]=o,s[i+3]=r,s[i+4]=n,s[i+5]=o,s[i+6]=r,s[i+7]=n,s[i+8]=o,s[i+9]=r,s[i+10]=n,s[i+11]=o,s[i+12]=r,s[i+13]=n,s[i+14]=o,s[i+15]=r,s[i+16]=n,s[i+17]=o,this._changedBuffers[0]=!0}setRgbaArr(e,t,i){let s=24*e,r=this._rgbaArr,n=t.x,o=t.y,a=t.z,l=t.w,h=i.x,c=i.y,d=i.z,_=i.w;r[s]=h,r[s+1]=c,r[s+2]=d,r[s+3]=_,r[s+4]=n,r[s+5]=o,r[s+6]=a,r[s+7]=l,r[s+8]=n,r[s+9]=o,r[s+10]=a,r[s+11]=l,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=l,r[s+16]=h,r[s+17]=c,r[s+18]=d,r[s+19]=_,r[s+20]=h,r[s+21]=c,r[s+22]=d,r[s+23]=_,this._changedBuffers[3]=!0}setThicknessArr(e,t){let i=6*e,s=this._thicknessArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[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,s=this._vertexArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[i+11]=t[11],this._changedBuffers[5]=!0}createStartPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._startPositionHighBuffer),this._startPositionHighArr=st(this._startPositionHighArr),this._startPositionHighBuffer=e.createArrayBuffer(this._startPositionHighArr,3,this._startPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._startPositionLowBuffer),this._startPositionLowArr=st(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=st(this._endPositionHighArr),this._endPositionHighBuffer=e.createArrayBuffer(this._endPositionHighArr,3,this._endPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._endPositionLowBuffer),this._endPositionLowArr=st(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=st(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=st(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=st(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2,e.gl.DYNAMIC_DRAW)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,4,this._texCoordArr.length/4)}createTexOffsetBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texOffsetBuffer),this._texOffsetBuffer=e.createArrayBuffer(this._texOffsetArr,1,this._texOffsetArr.length)}createStrokeSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._strokeSizeBuffer),this._strokeSizeBuffer=e.createArrayBuffer(this._strokeSizeArr,1,this._strokeSizeArr.length)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=st(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}setTexCoordArr(e,t){let i=t[1],s=t[3]-i,r=24*e,n=this._texCoordArr;n[r]=t[0],n[r+1]=t[1],n[r+2]=i,n[r+3]=s,n[r+4]=t[2],n[r+5]=t[3],n[r+6]=i,n[r+7]=s,n[r+8]=t[4],n[r+9]=t[5],n[r+10]=i,n[r+11]=s,n[r+12]=t[6],n[r+13]=t[7],n[r+14]=i,n[r+15]=s,n[r+16]=t[8],n[r+17]=t[9],n[r+18]=i,n[r+19]=s,n[r+20]=t[10],n[r+21]=t[11],n[r+22]=i,n[r+23]=s,this._changedBuffers[6]=!0}setTextureDisabled(e){let t=24*e,i=this._texCoordArr;i[t+3]=0,i[t+7]=0,i[t+11]=0,i[t+15]=0,i[t+19]=0,i[t+23]=0,this._changedBuffers[6]=!0}setTexOffsetArr(e,t){let i=6*e,s=this._texOffsetArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[7]=!0}setStrokeSizeArr(e,t){let i=6*e,s=this._strokeSizeArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[8]=!0}refreshTexCoordsArr(){if(this._entityCollection&&this._renderer){let e=this._renderer.strokeTextureAtlas;for(let t=0;t<this._rays.length;t++){let i=this._rays[t],s=i.getImage();if(s){let t=e.get(s.__nodeIndex);t&&this.setTexCoordArr(i._handlerIndex,t.texCoords)}}}}};Es.__counter__=0;let Sr=Es;const As=class e{constructor(t){this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,this._renderer=null,this._strips=[]}_initProgram(){this._renderer&&this._renderer.handler&&!this._renderer.handler.programs.strip&&this._renderer.handler.addProgram(new X("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=[]}};As.__counter__=0;let Rr=As;const Ls=class e{constructor(t={}){this._onChangeRelativeCenter=e=>{this.geoObjectHandler.setRelativeCenter(e),this.polylineHandler.setRelativeCenter(e)},this.__id=e.__counter__++,this.renderNode=null,this._visibility=null==t.visibility||t.visibility,this.polygonOffsetUnits=null!=t.polygonOffsetUnits?t.polygonOffsetUnits:0,this.billboardHandler=new sl(this),this.labelHandler=new nl(this,t.labelMaxLetters),this.polylineHandler=new Pr(this),this.rayHandler=new Sr(this),this.pointCloudHandler=new Lr(this),this.stripHandler=new Rr(this),this.geoObjectHandler=new Ar(this),null!=t.pickingEnabled&&this.setPickingEnabled(t.pickingEnabled),this._entities=[],this.scaleByDistance=t.scaleByDistance||[1,1,1];let i=new Float32Array([1,1,1]);void 0!==t.pickingScale&&(t.pickingScale instanceof Array?(i[0]=t.pickingScale[0]||i[0],i[1]=t.pickingScale[1]||i[1],i[2]=t.pickingScale[2]||i[2]):"number"==typeof t.pickingScale&&(i[0]=t.pickingScale,i[1]=t.pickingScale,i[2]=t.pickingScale)),this._depthOrder=t.depthOrder||0,this.pickingScale=i,this._opacity=null==t.opacity?1:t.opacity,this._fadingOpacity=this._opacity,this.events=this.rendererEvents=lt(ol,this),this._useLighting=null!=t.useLighting?t.useLighting?1:0:1,t.entities&&this.addEntities(t.entities)}get depthOrder(){return this._depthOrder}set depthOrder(e){this._depthOrder=e,this.renderNode&&this.renderNode.updateEntityCollectionsDepthOrder()}isEmpty(){return 0==this._entities.length}get id(){return this.__id}get useLighting(){return!!this._useLighting}set useLighting(e){this._useLighting=Number(e)}isEqual(e){return null!==e&&this.__id===e.__id}setVisibility(e){var t;this._visibility=e,this._fadingOpacity=this._opacity*(e?1:0),null==(t=this.renderNode)||t.updateEntityCollectionsDepthOrder(),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||Ae}appendChildEntity(e){this._addRecursively(e)}_addRecursively(e){let t=this.renderNode;t&&t.ellipsoid&&e._cartesian.isZero()&&!e.relativePosition&&e.setCartesian3v(t.ellipsoid.lonLatToCartesian(e._lonLat)),this._setPickingColor(e),e._updateAbsolutePosition(),e.setScale3v(e.getScale()),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.childEntities.length;t++)e.childEntities[t]._entityCollection=this,this._addRecursively(e.childEntities[t])}add(e){return e._entityCollection||(e._entityCollection=this,e._entityCollectionIndex=this._entities.length,this._entities.push(e),this._addRecursively(e)),this}addEntities(e){for(let t=0,i=e.length;t<i;t++)this.add(e[t]);return this}belongs(e){return this.isEqual(e._entityCollection)}_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.childEntities.length;t++)this._removeRecursively(e.childEntities[t])}_removeEntity(e){if(e.parent){let t=e.parent.childEntities;for(let i=0,s=t.length;i<s;i++)if(t[i].isEqual(e)){t.splice(i,1);break}e.parent=null}else this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex);this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this._removeRecursively(e)}removeEntity(e){this.belongs(e)&&(this._removeEntity(e),this.events.dispatch(this.events.entityremove,e))}_removeEntitySilent(e){this.belongs(e)&&this._removeEntity(e)}createPickingColors(e=this._entities){if(this.renderNode&&this.renderNode.renderer)for(let t=0;t<e.length;t++){let i=e[t];this._setPickingColor(i),this.createPickingColors(i.childEntities)}}_setPickingColor(e){this.renderNode&&this.renderNode.renderer&&(e._independentPicking||!e.parent?this.renderNode.renderer.assignPickingColor(e):e._pickingColor=e.parent._pickingColor,this.renderNode.renderer.assignPickingColor(e),e.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||e.addEntityCollection(this,t),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),e.renderer.events.on("changerelativecenter",this._onChangeRelativeCenter),this.updateBillboardsTextureAtlas(),this.updateLabelsFontAtlas(),this.updateStrokeTextureAtlas(),this.createPickingColors())}_updateGeodeticCoordinates(e){let t=this._entities,i=t.length;for(;i--;){let s=t[i];s._lonLat&&s.setCartesian3v(e.lonLatToCartesian(s._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()}updateStrokeTextureAtlas(){this.rayHandler.reloadTextures(),this.polylineHandler.reloadTextures()}remove(){var e;this.renderNode&&(this.renderNode.removeEntityCollection(this),null==(e=this.renderNode.renderer)||e.events.off("changerelativecenter",this._onChangeRelativeCenter),this.renderNode=null,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.childEntities.length;t++)this._clearEntity(e.childEntities[t])}};Ls.__counter__=0;let se=Ls;const ol=["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"];function ae(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 An(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 Ln(e,t,i){i=i||2;var s,r,n,o,a,l,h,c=t&&t.length,d=c?t[0]*i:e.length,_=Pn(e,0,d,i,!0),u=[];if(!_)return u;if(c&&(_=function(e,t,i,s){var r,n,o,a=[];for(r=0,n=t.length;r<n;r++)(o=Pn(e,t[r]*s,r<n-1?t[r+1]*s:e.length,s,!1))===o.next&&(o.steiner=!0),a.push(_l(o));for(a.sort(dl),r=0;r<a.length;r++)ul(a[r],i),i=wi(i,i.next);return i}(e,t,_,i)),e.length>80*i){s=n=e[0],r=o=e[1];for(let t=i;t<d;t+=i)(a=e[t])<s&&(s=a),(l=e[t+1])<r&&(r=l),a>n&&(n=a),l>o&&(o=l);h=Math.max(n-s,o-r)}return Ti(_,u,i,s,r,h),u}function Pn(e,t,i,s,r){var n,o;if(r===function(e,t,i,s){var r=0;for(let n=t,o=i-s;n<i;n+=s)r+=(e[o]-e[n])*(e[n+1]+e[o+1]),o=n;return r}(e,t,i,s)>0)for(n=t;n<i;n+=s)o=Sn(n,e[n],e[n+1],o);else for(n=i-s;n>=t;n-=s)o=Sn(n,e[n],e[n+1],o);return o&&Te(o,o.next)&&(Ei(o),o=o.next),o}function wi(e,t){if(!e)return e;t||(t=e);var i,s=e;do{if(i=!1,s.steiner||!Te(s,s.next)&&0!==It(s.prev,s,s.next))s=s.next;else{if(Ei(s),(s=t=s.prev)===s.next)return null;i=!0}}while(i||s!==t);return t}function Ti(e,t,i,s,r,n,o){if(e){!o&&n&&function(e,t,i,s){var r=e;do{null===r.z&&(r.z=Mr(r.x,r.y,t,i,s)),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,s,r,n,o,a,l,h=1;do{for(i=e,e=null,n=null,o=0;i;){for(o++,s=i,a=0,t=0;t<h&&(a++,s=s.nextZ);t++);for(l=h;a>0||l>0&&s;)0!==a&&(0===l||!s||i.z<=s.z)?(r=i,i=i.nextZ,a--):(r=s,s=s.nextZ,l--),n?n.nextZ=r:e=r,r.prevZ=n,n=r;i=s}n.nextZ=null,h*=2}while(o>1)}(r)}(e,s,r,n);for(var a,l,h=e;e.prev!==e.next;)if(a=e.prev,l=e.next,n?ll(e,s,r,n):al(e))t.push(a.i/i),t.push(e.i/i),t.push(l.i/i),Ei(e),e=l.next,h=l.next;else if((e=l)===h){o?1===o?Ti(e=hl(e,t,i),t,i,s,r,n,2):2===o&&cl(e,t,i,s,r,n):Ti(wi(e),t,i,s,r,n,1);break}}}function al(e){var t=e.prev,i=e,s=e.next;if(It(t,i,s)>=0)return!1;for(var r=e.next.next;r!==e.prev;){if(os(t.x,t.y,i.x,i.y,s.x,s.y,r.x,r.y)&&It(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function ll(e,t,i,s){var r=e.prev,n=e,o=e.next;if(It(r,n,o)>=0)return!1;for(var a=r.x<n.x?r.x<o.x?r.x:o.x:n.x<o.x?n.x:o.x,l=r.y<n.y?r.y<o.y?r.y:o.y:n.y<o.y?n.y:o.y,h=r.x>n.x?r.x>o.x?r.x:o.x:n.x>o.x?n.x:o.x,c=r.y>n.y?r.y>o.y?r.y:o.y:n.y>o.y?n.y:o.y,d=Mr(a,l,t,i,s),_=Mr(h,c,t,i,s),u=e.nextZ;u&&u.z<=_;){if(u!==e.prev&&u!==e.next&&os(r.x,r.y,n.x,n.y,o.x,o.y,u.x,u.y)&&It(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&&os(r.x,r.y,n.x,n.y,o.x,o.y,u.x,u.y)&&It(u.prev,u,u.next)>=0)return!1;u=u.prevZ}return!0}function hl(e,t,i){var s=e;do{var r=s.prev,n=s.next.next;!Te(r,n)&&ra(r,s,s.next,n)&&Ci(r,n)&&Ci(n,r)&&(t.push(r.i/i),t.push(s.i/i),t.push(n.i/i),Ei(s),Ei(s.next),s=e=n),s=s.next}while(s!==e);return s}function cl(e,t,i,s,r,n){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&fl(o,a)){var l=na(o,a);return o=wi(o,o.next),l=wi(l,l.next),Ti(o,t,i,s,r,n),void Ti(l,t,i,s,r,n)}a=a.next}o=o.next}while(o!==e)}function dl(e,t){return e.x-t.x}function ul(e,t){if(t=function(e,t){var i,s=t,r=e.x,n=e.y,o=-1/0;do{if(n<=s.y&&n>=s.next.y&&s.next.y!==s.y){var a=s.x+(n-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=r&&a>o){if(o=a,a===r){if(n===s.y)return s;if(n===s.next.y)return s.next}i=s.x<s.next.x?s:s.next}}s=s.next}while(s!==t);if(!i)return null;if(r===o)return i.prev;var l,h=i,c=i.x,d=i.y,_=1/0;for(s=i.next;s!==h;)r>=s.x&&s.x>=c&&r!==s.x&&os(n<d?r:o,n,c,d,n<d?o:r,n,s.x,s.y)&&((l=Math.abs(n-s.y)/(r-s.x))<_||l===_&&s.x>i.x)&&Ci(s,e)&&(i=s,_=l),s=s.next;return i}(e,t)){var i=na(t,e);wi(i,i.next)}}function Mr(e,t,i,s,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-s)/r)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function _l(e){var t=e,i=e;do{t.x<i.x&&(i=t),t=t.next}while(t!==e);return i}function os(e,t,i,s,r,n,o,a){return(r-o)*(t-a)-(e-o)*(n-a)>=0&&(e-o)*(s-a)-(i-o)*(t-a)>=0&&(i-o)*(n-a)-(r-o)*(s-a)>=0}function fl(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&&ra(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&Ci(e,t)&&Ci(t,e)&&function(e,t){var i=e,s=!1,r=(e.x+t.x)/2,n=(e.y+t.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&r<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)}function It(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function Te(e,t){return e.x===t.x&&e.y===t.y}function ra(e,t,i,s){return!!(Te(e,t)&&Te(i,s)||Te(e,s)&&Te(i,t))||It(e,t,i)>0!=It(e,t,s)>0&&It(i,s,e)>0!=It(i,s,t)>0}function Ci(e,t){return It(e.prev,e,e.next)<0?It(e,t,e.next)>=0&&It(e,e.prev,t)>=0:It(e,t,e.prev)<0||It(e,e.next,t)<0}function na(e,t){var i=new Br(e.i,e.x,e.y),s=new Br(t.i,t.x,t.y),r=e.next,n=t.prev;return e.next=t,t.prev=e,i.next=r,r.prev=i,s.next=i,i.prev=s,n.next=s,s.prev=n,s}function Sn(e,t,i,s){var r=new Br(e,t,i);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function Ei(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 Br(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 Rn(e){var t=e[0][0].length,i={vertices:[],holes:[],dimensions:t},s=0;for(let r=0;r<e.length;r++){for(let s=0;s<e[r].length;s++)for(let n=0;n<t;n++)i.vertices.push(e[r][s][n]);r>0&&(s+=e[r-1].length,i.holes.push(s))}return i}function qs(e,t,i){let s=e[0],r=e[1];if(s>=0){let e=65536*Math.floor(s/65536);t.x=Math.fround(e),i.x=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.x=Math.fround(-e),i.x=Math.fround(s+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 q=new H,Y=new H,De=new H;const ge=class e{constructor(t){this.__id=e.__counter__++,this._layer=t,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,s,r,n,o,a,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=o,w=[n.x,n.y,n.z,n.w],T=[s.x,s.y,s.z,1];for(let i=0;i<e.length;i++){var C=e[i];if(0===C.length)continue;let s,r,n=v;if(t)s=C[C.length-1];else{let e=C[0],t=C[1];t||(t=e),s=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]]}qs(s,q,Y),a.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),l.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.y),p.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),m.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.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++)qs(C[e],q,Y),a.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),l.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.y),p.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),m.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.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(n,n+1,n+1,n+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)}qs(r,q,Y),a.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),l.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.y),p.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),m.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.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(t){if(-1===t._handlerIndex){t._handler=this,t._handlerIndex=this._geometries.length,this._geometries.push(t);let i=t._entity._pickingColor.scaleTo(1/255);if(t._polyVerticesHighMerc=[],t._polyVerticesLowMerc=[],t._lineVerticesHighMerc=[],t._lineVerticesLowMerc=[],t._coordinates[0].length)if(t.type===ai.POLYGON){let s=t._coordinates,r=[];for(let e=0;e<s.length;e++){r[e]=[];for(let t=0;t<s[e].length;t++)r[e][t]=[ni(s[e][t][0]),oi(s[e][t][1])]}let n=Rn(r),o=Ln(n.vertices,n.holes,2);t._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,t._polyIndexesHandlerIndex=this._polyIndexes.length;for(let e=0;e<o.length;e++)this._polyIndexes.push(o[e]+.5*t._polyVerticesHandlerIndex);let a=t._style.fillColor,l=[],h=[];for(let e=0;e<.5*n.vertices.length;e++)this._polyColors.push(a.x,a.y,a.z,a.w),this._polyPickingColors.push(i.x,i.y,i.z,1);for(let e=0;e<n.vertices.length;e++)An(n.vertices[e],De),l[e]=De.x,h[e]=De.y;t._polyVerticesHighMerc=l,t._polyVerticesLowMerc=h,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,l),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,h),t._polyVerticesLength=n.vertices.length,t._polyIndexesLength=o.length,t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,e.appendLineData(r,!0,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===ai.MULTIPOLYGON){let s=t._coordinates,r=[],n=[];t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length;for(let o=0;o<s.length;o++){let a=s[o],l=[];for(let e=0;e<a.length;e++){l[e]=[];for(let t=0;t<s[o][e].length;t++)l[e][t]=[ni(a[e][t][0]),oi(a[e][t][1])]}let h=Rn(l),c=Ln(h.vertices,h.holes,2);for(let e=0;e<c.length;e++)n.push(c[e]+.5*r.length);r.push.apply(r,h.vertices),e.appendLineData(l,!0,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc)}t._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,t._polyIndexesHandlerIndex=this._polyIndexes.length;for(let e=0;e<n.length;e++)this._polyIndexes.push(n[e]+.5*t._polyVerticesHandlerIndex);let o=t._style.fillColor,a=[],l=[];for(let e=0;e<.5*r.length;e++)this._polyColors.push(o.x,o.y,o.z,o.w),this._polyPickingColors.push(i.x,i.y,i.z,1);for(let e=0;e<r.length;e++)An(r[e],De),a[e]=De.x,l[e]=De.y;t._polyVerticesHighMerc=a,t._polyVerticesLowMerc=l,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,a),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,l),t._polyVerticesLength=r.length,t._polyIndexesLength=n.length,t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===ai.LINESTRING){let s=t._coordinates,r=new Array(s.length);for(let e=0;e<s.length;e++)r[e]=[ni(s[e][0]),oi(s[e][1])];t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,e.appendLineData([r],!1,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===ai.MULTILINESTRING){let s=t._coordinates,r=[];for(let e=0;e<s.length;e++){r[e]=[];for(let t=0;t<s[e].length;t++)r[e][t]=[ni(s[e][t][0]),oi(s[e][t][1])]}t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,e.appendLineData(r,!1,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}this.setGeometryVisibility(t),!this._updatedGeometry[t.__id]&&this._updatedGeometryArr.push(t),this._updatedGeometry[t.__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 s=this._geometries;for(let i=t;i<s.length;i++){let t=s[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 s=0;s<t.nodes.length;s++){let r=t.nodes[s];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 s=0;s<t.nodes.length;s++){let r=t.nodes[s];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 s=this._updatedGeometryArr;for(t=0;t<s.length;t++)this._refreshRecursevely(s[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,s=this._polyVerticesLowMerc,r=e._polyVerticesLength,n=e._polyVerticesHandlerIndex;for(let o=0;o<r;o++)i[n+o]=e._polyVerticesHighMerc[o]*t,s[n+o]=e._polyVerticesLowMerc[o]*t;i=this._lineVerticesHighMerc,s=this._lineVerticesLowMerc,r=e._lineVerticesLength,n=e._lineVerticesHandlerIndex;for(let o=0;o<r;o++)i[n+o]=e._lineVerticesHighMerc[o]*t,s[n+o]=e._lineVerticesLowMerc[o]*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,s=i+2*e._polyVerticesLength,r=this._polyColors;for(let e=i;e<s;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,s=i+e._lineColorsLength,r=this._lineStrokeColors;for(let e=i;e<s;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,s=i+e._lineColorsLength,r=this._lineColors;for(let e=i;e<s;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,s=i+e._lineThicknessLength,r=this._lineThickness;for(let e=i;e<s;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 s=this._geometries;for(let t=e._handlerIndex;t<s.length;t++){let i=s[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)}clear(){this._geometries=[],this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyIndexes=[],this._polyColors=[],this._polyPickingColors=[],this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineOrders=[],this._lineIndexes=[],this._lineColors=[],this._linePickingColors=[],this._lineThickness=[],this._lineStrokeColors=[],this._lineStrokes=[],this._deleteBuffers(),this._polyVerticesHighBufferMerc=null,this._polyVerticesLowBufferMerc=null,this._polyIndexesBuffer=null,this._polyColorsBuffer=null,this._polyPickingColorsBuffer=null,this._lineVerticesHighBufferMerc=null,this._lineVerticesLowBufferMerc=null,this._lineIndexesBuffer=null,this._lineOrdersBuffer=null,this._lineColorsBuffer=null,this._linePickingColorsBuffer=null,this._lineThicknessBuffer=null,this._lineStrokeColorsBuffer=null,this._lineStrokesBuffer=null,this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr=[],this._removeGeometryExtents={},this.refresh()}_deleteBuffers(){if(this._layer._planet&&this._layer._planet.renderer){let e=this._layer._planet.renderer.handler.gl;e&&(e.deleteBuffer(this._polyVerticesHighBufferMerc),e.deleteBuffer(this._polyVerticesLowBufferMerc),e.deleteBuffer(this._polyIndexesBuffer),e.deleteBuffer(this._polyColorsBuffer),e.deleteBuffer(this._polyPickingColorsBuffer),e.deleteBuffer(this._lineVerticesHighBufferMerc),e.deleteBuffer(this._lineVerticesLowBufferMerc),e.deleteBuffer(this._lineIndexesBuffer),e.deleteBuffer(this._lineOrdersBuffer),e.deleteBuffer(this._lineColorsBuffer),e.deleteBuffer(this._linePickingColorsBuffer),e.deleteBuffer(this._lineThicknessBuffer),e.deleteBuffer(this._lineStrokeColorsBuffer),e.deleteBuffer(this._lineStrokesBuffer))}}};ge.__counter__=0;let kr=ge;class _t extends zt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(gl),this.isVector=!0,this._hasImageryTiles=!1,this.scaleByDistance=t.scaleByDistance||[Ae,Ae,Ae],this._useLighting=void 0===t.useLighting||t.useLighting;let i=new Float32Array([1,1,1]);void 0!==t.pickingScale&&(t.pickingScale instanceof Array?(i[0]=t.pickingScale[0]||i[0],i[1]=t.pickingScale[1]||i[1],i[2]=t.pickingScale[2]||i[2]):"number"==typeof t.pickingScale&&(i[0]=t.pickingScale,i[1]=t.pickingScale,i[2]=t.pickingScale)),this.pickingScale=i,this.async=void 0===t.async||t.async,this.clampToGround=t.clampToGround||!1,this.relativeToGround=t.relativeToGround||!1,this._entities=function(e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];"Entity"===s.instanceName?t.push(s):t.push(new G(s))}return t}(t.entities||[]),this._labelMaxLetters=t.labelMaxLetters||24,this._stripEntityCollection=new se({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._stripEntityCollection),this._polylineEntityCollection=new se({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._polylineEntityCollection),this._geoObjectEntityCollection=new se({pickingEnabled:this.pickingEnabled,useLighting:this._useLighting}),this._bindEventsDefault(this._geoObjectEntityCollection),this._geometryHandler=new kr(this),this._nodeCapacity=t.nodeCapacity||60,this._entityCollectionsTreeStrategy=null,this.setEntities(this._entities),this.polygonOffsetUnits=null!=t.polygonOffsetUnits?t.polygonOffsetUnits:0,this.pickingEnabled=this._pickingEnabled,this._depthOrder=t.depthOrder||0}get depthOrder(){return this._depthOrder}set depthOrder(e){e!==this._depthOrder&&(this._depthOrder=e,this._planet&&this._planet.updateVisibleLayers())}get useLighting(){return this._useLighting}set useLighting(e){e!==this._useLighting&&(this._geoObjectEntityCollection.useLighting=e,this._useLighting=e)}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._polylineEntityCollection._layer=this,this._stripEntityCollection._layer=this,this._geoObjectEntityCollection._layer=this,this.setEntities(this._entities))}remove(){return super.remove(),this._polylineEntityCollection.remove(),this._stripEntityCollection.remove(),this._geoObjectEntityCollection.remove(),this._polylineEntityCollection._layer=void 0,this._stripEntityCollection._layer=void 0,this._geoObjectEntityCollection._layer=void 0,this}getEntities(){return[].concat(this._entities)}add(e){return e._layer||e._entityCollection||(e._layer=this,e._layerIndex=this._entities.length,this._entities.push(e),this._proceedEntity(e)),this}insert(e,t){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)}return this}_proceedEntity(e){var t;let i=this._hasImageryTiles;e.strip&&this._stripEntityCollection.add(e),(e.polyline||e.ray)&&this._polylineEntityCollection.add(e),(e.geoObject||e.isEmpty)&&this._geoObjectEntityCollection.add(e),e.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(e),this._geometryHandler.add(e.geometry))),this._planet&&((e.billboard||e.label||e.geoObject||e.isEmpty)&&(e._cartesian.isZero()&&!e._lonLat.isZero()?e._setCartesian3vSilent(this._planet.ellipsoid.lonLatToCartesian(e._lonLat)):(e._lonLat=this._planet.ellipsoid.cartesianToLonLat(e._cartesian),Math.abs(e._lonLat.lat)<ct?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc.lon=e._lonLatMerc.lat=e._lonLatMerc.height=0)),(e.billboard||e.label)&&(null==(t=this._entityCollectionsTreeStrategy)||t.insertEntity(e))),this._planet&&this._hasImageryTiles!==i&&this._planet.updateVisibleLayers(),this.events.dispatch(this.events.entityadd,e)}addEntities(e){let t=e.length;for(;t--;)this.add(e[t]);return this}removeEntity(e){if(e._layer&&this.isEqual(e._layer)){if(e.parent||(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 s=e._nodePtr;for(;s;)s.count--,s=s.parentNode;break}}this._planet&&e.geometry&&(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){var t;this._pickingEnabled=e,this._stripEntityCollection.setPickingEnabled(e),this._polylineEntityCollection.setPickingEnabled(e),this._geoObjectEntityCollection.setPickingEnabled(e),null==(t=this._entityCollectionsTreeStrategy)||t.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(){var e;super.clear();let t=new Array(this._entities.length);for(let e=0;e<t.length;e++)t[e]=this._entities[e];let i=this._entities.length;for(;i--;)this._entities[i].remove();this._entities.length=0,this._entities=[];for(let e=0;e<t.length;e++)this._entities[e]=t[e];null==(e=this._entityCollectionsTreeStrategy)||e.dispose(),this._entityCollectionsTreeStrategy=null,this._geometryHandler.clear()}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,s=e.length;i<s;i++)t[i]=e[i];this.clear(),this._entities=new Array(t.length);let i=[];for(let e=0;e<t.length;e++){let s=t[e];s._layer=this,s._layerIndex=e;let r=!(s.strip||s.polyline||s.ray||s.geoObject||s.billboard||s.label);s.strip?this._stripEntityCollection.add(s):s.polyline||s.ray?this._polylineEntityCollection.add(s):s.geoObject||r?this._geoObjectEntityCollection.add(s):(s.billboard||s.label)&&i.push(s),s.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(s),this._geometryHandler.add(s.geometry))),this._entities[e]=s}return this._createEntityCollectionsTree(i),this}_createEntityCollectionsTree(e){this._planet&&(this._entityCollectionsTreeStrategy=this._planet.quadTreeStrategy.createEntityCollectionsTreeStrategy(this,this._nodeCapacity),this._entityCollectionsTreeStrategy.insertEntities(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.quadTreeStrategy._renderedNodes,s=this._planet.getViewExtent();let r=t._entities,n=r.length,o=new v;for(;n--;){let t=r[n]._altitude||0,a=r[n].polyline;if(a&&s.overlaps(a._extent)){let s=a._pathLonLatMerc,r=s.length;for(;r--;){let n=s[r].length;for(;n--;){let l=s[r][n],h=i.length;for(;h--;){let s=i[h].segment;if(s._extent.isInside(l)){let i=a._path3v[r][n];s.getTerrainPoint(i,l,o);let h=e&&a.altitude||t;if(h){let e=this._planet.ellipsoid.getSurfaceNormal3v(o);a.setPoint3v(o.addA(e.scale(h)),n,r,!0)}else a.setPoint3v(o,n,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;(this._fading&&this._fadingOpacity>0||this.minZoom<=t.quadTreeStrategy.maxCurrZoom&&this.maxZoom>=t.quadTreeStrategy.maxCurrZoom)&&(this._collectStripCollectionPASS(e),this._collectPolylineCollectionPASS(e),this._collectGeoObjectCollectionPASS(e),this._entityCollectionsTreeStrategy&&this._entityCollectionsTreeStrategy.collectVisibleEntityCollections(e))}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){if(e.isReady)return[0,0,1,1];{!e.isLoading&&this.loadMaterial(e);const t=e.segment;let i=t.node,s=!1,r=this.__id,n=e;for(;i.parentNode;){if(n&&n.isReady){s=!0;break}i=i.parentNode,n=i.segment.materials[r]}if(s){e.appliedNodeId=i.nodeId,e.texture=n.texture,e.pickingMask=n.pickingMask;const s=1/(2<<t.tileZoom-i.segment.tileZoom-1);return[t.tileX*s-i.segment.tileX,t.tileY*s-i.segment.tileY,s,s]}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 gl=["draw","entityadd","entityremove"],pl=["change","startpoint"],Mn=$.createCylinder(1,1,2,20,1,!0,!1,0,-.5,0),kt=200,gi=.3;class oa extends de{constructor(e){super(e.name),this._cornerDblClick=!1,this._onChange=e=>{if("POLYGON"===e.geometryType){let t=this.getCoordinates(),i=new G({geometry:{type:e.geometryType,coordinates:[t],style:this._fillStyle}});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=lt(pl),this._planet=null,this._initCoordinates=e.coordinates||[],this._pickedCorner=null,this._pickedCenter=null,this._startPos=null,this._startClick=new H,this._geometryLayer=new _t,this._cornerStyle={scale:.5,tag:"corners",color:"rgb(350, 350, 0)",object3d:Mn,...e.cornerStyle||{}},this._centerStyle={scale:.4,tag:"centers",color:"rgb(0, 350, 50)",object3d:Mn,...e.centerStyle||{}},this._outlineStyle={thickness:3.5,color:"rgb(0, 350, 50)",...e.outlineStyle||{}},this._fillStyle={fillColor:"rgba(0,146,247,0.2)",...e.fillStyle||{}},this._cornerLayer=new _t("corners",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._centerLayer=new _t("centers",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._outlineLayer=new _t("outline",{entities:[new G({polyline:{path3v:[],isClosed:!1,...this._outlineStyle}})],pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0}),this._outlineLayer.getEntities()[0].polyline.altitude=gi,this._ghostCorner=new G({geoObject:this._cornerStyle}),this._ghostOutlineLayer=new _t("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._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 s=this._outlineLayer.getEntities();for(t=s.length;t--;)s[t].polyline.clear(),t>0&&s[t].remove();this._clearGhostPointer()}setCoordinates(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],s=this._planet.ellipsoid.lonLatToCartesian(new L(i[0],i[1],i[2]));this._appendCart(s)}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 v,i=this._planet.quadTreeStrategy._renderedNodes;for(let s=0;s<i.length;s++){let r=i[s].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(),s=[i.lon,i.lat,i.height];e.splice(t,0,s),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,s=this._planet.ellipsoid.cartesianToLonLat(e),r=[s.lon,s.lat,s.height];t.splice(i,0,r),this.clear(),this.setCoordinates(t)}}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],s=new G({geoObject:this._cornerStyle});if(s.setCartesian3v(e),s.addTo(this._cornerLayer),this._checkTerrainCollision(s),i){let e=t[0].getCartesian(),r=i.getCartesian(),n=s.getCartesian().sub(r),o=s.getCartesian().sub(e),a=n.length(),l=o.length();n.normalize(),o.normalize();let h=[],c=[];for(let t=0;t<=kt;t++){let i=n.scaleTo(t*a/kt).addA(r);h.push(i);let s=o.scaleTo(t*l/kt).addA(e);c.push(s)}this._outlineLayer.getEntities()[0].polyline.setPath3v([c]);let d=new G({polyline:{path3v:[h],isClosed:!1,...this._outlineStyle}});d.polyline.altitude=gi,this._outlineLayer.add(d);let _=this._centerLayer.getEntities(),u=_[_.length-1],f=n.scaleTo(.5*a).addA(r),g=o.scaleTo(.5*l).addA(e),p=new G({geoObject:this._centerStyle});p.setCartesian3v(f),p.addTo(this._centerLayer),this._checkTerrainCollision(p),u.remove(),u.addTo(this._centerLayer),u.setCartesian3v(g)}else new G({geoObject:this._centerStyle}).addTo(this._centerLayer)}_clearGhostPointer(){const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.clear(),e.getEntities()[1].polyline.clear()}_moveCornerPoint(e){let t=new H(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);if(s){this._pickedCorner.setCartesian3v(s);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex,i=e.length,s=e[0===t?i-1:t-1].getCartesian(),r=e[(t+1)%i].getCartesian(),n=this._pickedCorner.getCartesian().sub(s),o=this._pickedCorner.getCartesian().sub(r),a=n.length(),l=o.length();n.normalize(),o.normalize();let h=[],c=[];for(let e=0;e<=kt;e++){let t=n.scaleTo(e*a/kt).addA(s);h.push(t);let i=o.scaleTo(e*l/kt).addA(r);c.push(i)}let d=this._outlineLayer.getEntities(),_=d[t].polyline,u=d[(t+1)%i].polyline;null==_||_.setPath3v([h]),null==u||u.setPath3v([c]);let f=this._centerLayer.getEntities(),g=f[0===t?i-1:t-1],p=f[t],m=n.scaleTo(.5*a).addA(s),v=o.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 s=0,r=xt;for(let n=0;n<i;n++){let i=t[n].getCartesian().distance(e);i<r&&(r=i,s=n)}let n=t[s].getCartesian(),o=t[(s+1)%i].getCartesian(),a=t[0===s?i-1:s-1].getCartesian().sub(n).normalize(),l=o.sub(n).normalize(),h=e.sub(n).normalize(),c=a.add(l).normalize(),d=h.cross(c),_=a.cross(l);d.dot(_)>0&&(s--,s<0&&(s=i-1));let u=new v;for(let n=0;n<i;n++)if(new Jt(t[n].getCartesian(),t[(n+1)%i].getCartesian()).getNearestDistancePoint(e,u)){let t=u.distance(e);t<r&&(r=t,s=n)}this._insertCornerIndex=(s+1)%i;let f=t[s%i].getCartesian(),g=t[(s+1)%i].getCartesian(),p=this._ghostCorner.getCartesian().sub(f),m=this._ghostCorner.getCartesian().sub(g),y=p.length(),x=m.length();p.normalize(),m.normalize();let b=[],w=[];for(let e=0;e<=kt;e++){let t=p.scaleTo(e*y/kt).addA(f);b.push(t);let i=m.scaleTo(e*x/kt).addA(g);w.push(i)}let T=this._ghostOutlineLayer.getEntities(),C=T[0].polyline,E=T[1].polyline;null==C||C.setPath3v([b]),null==E||E.setPath3v([w])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new G({polyline:{path3v:[],isClosed:!1,...this._outlineStyle}}),new G({polyline:{path3v:[],isClosed:!1,...this._outlineStyle}}),this._ghostCorner]);const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.altitude=e.getEntities()[1].polyline.altitude=gi}}class Bn extends oa{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],s=new G({geoObject:this._cornerStyle});if(s.setCartesian3v(e),s.addTo(this._cornerLayer),this._checkTerrainCollision(s),i){let e=i.getCartesian(),t=s.getCartesian().sub(e),r=t.length();t.normalize();let n=[];for(let i=0;i<=kt;i++){let s=t.scaleTo(i*r/kt).addA(e);n.push(s)}let o=new G({polyline:{path3v:[n],isClosed:!1,...this._outlineStyle}});o.polyline.altitude=gi,this._outlineLayer.add(o);let a=t.scaleTo(.5*r).addA(e),l=new G({geoObject:this._centerStyle});l.setCartesian3v(a),l.addTo(this._centerLayer),this._checkTerrainCollision(l)}}_clearGhostPointer(){this._ghostOutlineLayer.getEntities()[0].polyline.clear()}_moveCorner(e,t,i){let s=this._cornerLayer.getEntities();if(0==s.length)return;1==s.length&&(e=t=i=0);let r=s[e].getCartesian(),n=this._pickedCorner.getCartesian().sub(r),o=n.length();n.normalize();let a=[];for(let e=0;e<=kt;e++){let t=n.scaleTo(e*o/kt).addA(r);a.push(t)}let l=this._outlineLayer.getEntities()[t].polyline;null==l||l.setPath3v([a]);let h=this._centerLayer.getEntities()[i];if(h){let e=n.scaleTo(.5*o).addA(r);h.setCartesian3v(e),this._checkTerrainCollision(h)}}_moveCornerPoint(e){let t=new H(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);if(s){this._pickedCorner.setCartesian3v(s);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 s=t[e].getCartesian(),r=this._ghostCorner.getCartesian().sub(s),n=r.length();r.normalize();let o=[];for(let e=0;e<=kt;e++){let t=r.scaleTo(e*n/kt).addA(s);o.push(t)}this._ghostOutlineLayer.getEntities()[0].polyline.setPath3v([o])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new G({polyline:{path3v:[],isClosed:!1,...this._outlineStyle}}),this._ghostCorner]),this._ghostOutlineLayer.getEntities()[0].polyline.altitude=gi}}class kn extends Q{constructor(e={}){super(e),this._drawingScene=new Bn({name:`drawingScene:${this.__id}`,cornerStyle:e.cornerStyle||{},centerStyle:e.centerStyle||{},outlineStyle:e.outlineStyle||{},fillStyle:e.fillStyle||{}})}activatePolygonDrawing(){this.deactivate(),this._drawingScene=new oa({name:`polygonDrawingScene:${this.__id}`,cornerStyle:this._drawingScene._cornerStyle,centerStyle:this._drawingScene._centerStyle,outlineStyle:this._drawingScene._outlineStyle,fillStyle:this._drawingScene._fillStyle}),this.activate()}activateLineStringDrawing(){this.deactivate(),this._drawingScene=new Bn({name:`linestringDrawingScene:${this.__id}`,cornerStyle:this._drawingScene._cornerStyle,centerStyle:this._drawingScene._centerStyle,outlineStyle:this._drawingScene._outlineStyle,fillStyle:this._drawingScene._fillStyle}),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 li={ell:0,msl:1,gnd:2},sn=.3048,ml=1/sn,vl=1/3.6,aa=.001*sn,yl=1/aa,xl=["m","km","ft","s","h","m/s","km/h","ft/s"],la=[0,2,0,0,0,0,0,0];let pt=[];function ha(e,t,i){return pt[e][t](i)}function Ir(e,t,i,s,r){return e?ha(t,i,s).toFixed(r||la[i]):"--"}function ca(e){return xl[e]}pt[0]=[],pt[0][0]=e=>e,pt[0][1]=e=>.001*e,pt[0][2]=e=>e*ml,pt[2]=[],pt[2][0]=e=>e*sn,pt[2][1]=e=>e*aa,pt[2][2]=e=>e,pt[1]=[],pt[1][0]=e=>1e3*e,pt[1][1]=e=>e,pt[1][2]=e=>e*yl,pt[5]=[],pt[5][5]=e=>e,pt[5][6]=e=>3.6*e,pt[5][7]=e=>3.28084*e,pt[6]=[],pt[6][5]=e=>e*vl,pt[6][6]=e=>e;const In=Object.freeze(Object.defineProperty({__proto__:null,ELL:0,GND:2,MSL:1,_tenth:la,convert:ha,convertExt:Ir,ft:2,fts:7,h:4,heightMode:li,km:1,kmh:6,m:0,ms:5,s:3,toString:ca},Symbol.toStringTag,{value:"Module"})),bl=['<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 da extends Q{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=In[this._altUnitVal],this._heightMode=li[this._heightModeVal],this._lonLat=null,this._centerMode=!1}_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 s=0,r=t<0?Math.ceil(t):Math.floor(t),n=Math.floor(s=60*Math.abs(t-r)),o=Math.floor(6e3*(s-n))/100;this._latValEl.innerHTML=Math.abs(r)+"°"+n+"'"+o.toFixed(0)+'"',r=i<0?Math.ceil(i):Math.floor(i),n=Math.floor(s=60*Math.abs(i-r)),o=Math.floor(6e3*(s-n))/100,this._lonValEl.innerHTML=Math.abs(r)+"°"+n+"'"+o.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=li[this._heightModeVal],this._altUnit=In[this._altUnitVal],this._el.querySelector(".og-units-height").innerHTML=ca(this._altUnit),this._showHeight()}_refreshCoordinates(){this._type>=this._TYPE_FUNC.length&&(this._type=0);let e=this._el;e.innerHTML=bl[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",yi((()=>this._showHeight()),400,!0),this)):(this.renderer.events.on("mousemove",this._grabCoordinates,this),this.renderer.events.on("mousestop",yi((()=>this._showHeight()),400,!0),this)),this._refreshCoordinates(),this._updateUnits()}_grabCoordinates(e){let t,i=e.pos,s=this.renderer;t=this._centerMode?s.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===li.ell?(e=await this.planet.getHeightAboveELL(this._lonLat),e=Number(Ir(!0,0,this._altUnit,e))):this._heightMode===li.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()}}}const wl=["loadend"];class Ai extends zt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(wl),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 U,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 L(e[0].lon,e[0].lat),new L(e[1].lon,e[1].lat),new L(e[2].lon,e[2].lat),new L(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(L.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>ct||t.northEast.lat<Ot?(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 U(this._extentWgs84.southWest.forwardMercatorEPS01(),this._extentWgs84.northEast.forwardMercatorEPS01());let e=new Float32Array(2);if(0===this._projType?(ae(this._extentWgs84.southWest.lon,e),this._extentWgs84ParamsHigh[0]=e[0],this._extentWgs84ParamsLow[0]=e[1],ae(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()):(ae(this._extentMerc.southWest.lon,e),this._extentMercParamsHigh[0]=e[0],this._extentMercParamsLow[0]=e[1],ae(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,s=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=s._extent):(t=this._extentMerc,i=s.getExtentMerc());let r=t.northEast.lon-t.southWest.lon,n=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/r,(t.northEast.lat-i.northEast.lat)/n,(i.northEast.lon-i.southWest.lon)/r,(i.northEast.lat-i.southWest.lat)/n]}get getFrameWidth(){return this._frameWidth}get getFrameHeight(){return this._frameHeight}_createSourceTexture(){}_renderingProjType1(){let e=this._planet,t=e.renderer.handler,i=t.gl,s=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let r=s._framebuffer;r.setSize(this._frameWidth,this._frameHeight),r.activate(),t.programs.geoImageTransform.activate();let n=t.programs.geoImageTransform._program,o=n.attributes,a=n.uniforms;i.disable(i.CULL_FACE),r.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.uniform1i(a.isFullExtent,this._isFullExtent),i.bindBuffer(i.ARRAY_BUFFER,s._texCoordsBuffer),i.vertexAttribPointer(o.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(o.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(o.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(a.extentParamsHigh,this._extentMercParamsHigh),i.uniform4fv(a.extentParamsLow,this._extentMercParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(a.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,s._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,s=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let r=s._framebuffer;r.setSize(this._frameWidth,this._frameHeight),r.activate(),t.programs.geoImageTransform.activate();let n=t.programs.geoImageTransform._program,o=n.attributes,a=n.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,s._texCoordsBuffer),i.vertexAttribPointer(o.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(o.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(o.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(a.extentParamsHigh,this._extentWgs84ParamsHigh),i.uniform4fv(a.extentParamsLow,this._extentWgs84ParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(a.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,s._indexBuffer.numItems,i.UNSIGNED_INT,0),r.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}}const W={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},Tl=["change","idle","play","pause","stop"];class Cl extends ut{constructor(e){super({template:Dt('<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 El=["change"];class Z extends ut{constructor(e={}){super({template:Dt('<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=Zi(e.clientX,t.left,t.right),s=this._startPosX-i;this._startPosX=i,this.value=this._value-s*(this._max-this._min)/this.$panel.clientWidth},this._onMouseUp=()=>{document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(El),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=Zi(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()}set max(t){this._max=t,this.events.stopPropagation(),this.value=this._value+Math.sign(e.wheelDelta)*(this._max-this._min)/100}get max(){return this._max}}const Al=["input"];let Ll=0;class zn extends ut{constructor(e={}){super({template:Dt('<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-"+Ll++,label:e.label||"",value:e.value||"#000000"})}),this._onInput=e=>{this.value=e.target.value},this.events=this.events.registerNames(Al),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 zr{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}}const Ps=class e{constructor(){this.__id=e.__counter__++}get id(){return this.__id}};Ps.__counter__=0;let Me=Ps;class rn extends Q{constructor(e={}){super(e),this._deactivate=!1,this._shiftBusy=!1,this._name="mouseNavigation",this.grabbedPoint=new v,this._eye0=new v,this.pointOnEarth=new v,this.earthUp=new v,this.inertia=.007,this.grabbedSpheroid=new Ft,this.qRot=new F,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 Me}static getMovePointsFromPixelTerrain(e,t,i,s,r,n,o){const a=[];let l=e.eye.clone(),h=e.getBackward(),c=e.getRight(),d=e.getUp(),_=t.getCartesianFromPixelTerrain(r);if(_||(_=t.getCartesianFromPixelTerrain(t.renderer.handler.getCenter())),_){o||(o=v.sub(_,e.eye).normalize());let t=s*e.eye.distance(_)/i;t*=n?-1.25:2;const r=h.scaleTo(t);if(o.dot(e.eye.normal().negate())>=.1){const t=new Ft;t.radius=_.length();let s=[],n=[],u=!1;for(let e=0;e<i;e++){l.addA(r);const i=new V(l,o).hitSphere(t);if(n[e]=l.clone(),!i){u=!0;break}s[e]=(new tt).rotateBetweenVectors(_.normal(),i.normal())}if(u){l=e.eye.clone();for(let e=0;e<i;e++)a[e]={eye:l.addA(r).clone(),v:d,u:c,n:h}}else for(let e=0;e<i;e++){let t=s[e];a[e]={eye:t.mulVec3(n[e]),v:t.mulVec3(d),u:t.mulVec3(c),n:t.mulVec3(h)}}}else for(let e=0;e<i;e++)a[e]={eye:l.addA(o.scaleTo(-t)).clone(),v:d,u:c,n:h};return a}}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(W.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=rn.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",W.KEY_ALT,this.onShiftFree,this),this.renderer.events.on("keyfree",W.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,s=e.minAltitude+this.planet.ellipsoid.polarSize;const r=e.eye.length(),n=this.planet.ellipsoid.cartesianToLonLat(t);if(r>i||r<s)return void this.planet.flyLonLat(new L(n.lon,n.lat));this.renderer.events.isKeyPressed(W.KEY_ALT)?this.planet.flyLonLat(new L(n.lon,n.lat,2*e.eye.distance(t))):this.planet.flyLonLat(new L(n.lon,n.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 V(t.eye,e.direction).hitSphere(this.grabbedSpheroid);if(i){this.scaleRot=1,this.qRot=F.getRotationBetweenVectors(i.normal(),this.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t.rotate(e)}}else{let i=this.grabbedPoint,s=v.add(i,t.getRight()),r=v.add(i,i.normal()),n=new v;new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,s,r),n)===V.INSIDE&&(t.eye=this._eye0.addA(n.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*j;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(W.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,t._f.set(-t._b.x,-t._b.y,-t._b.z)}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(F.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.rotate(i)}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 Pl=["drag","zoom","rotate"],zi=.96;class Yi extends Q{constructor(e={}){super({name:"navigation",autoActivate:!0,...e}),this._freeMode=!1,this._shiftBusy=!1,this._hold=!1,this._onShiftFree=()=>{this._shiftBusy=!1},this._onCameraFly=()=>{this.stop()},this._onMouseMove=e=>{this._active&&this.renderer.events.isKeyPressed(W.KEY_ALT)&&(this._shiftBusy||(this._shiftBusy=!0,this._onRHold(e)),this._onRDown(e))},this._onMouseEnter=e=>{const t=this.renderer.events;t.isKeyPressed(W.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")},this._onMouseLeave=()=>{this.renderer.events.mouseState.leftButtonDown&&this.vel.scale(0),this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this._onRHold=e=>{if((!this.disableRotation||!this.disableTilt)&&this._targetRotationPoint){this._velInertia=.6,this.disableRotation||(this.force_h=.5*(e.x-e.prev_x)),this.disableTilt||(this.force_v=.5*(e.y-e.prev_y));let t=this.planet.camera.getHeading();this._freeMode=!1,!isNaN(t)&&t>45&&t<340&&(this._freeMode=!0)}},this._onRDown=e=>{if((!this.disableRotation||!this.disableTilt)&&this.planet){this.planet.stopFlying();const t=this._getTargetPoint(e.pos);this._targetRotationPoint=t||null,t&&(this._targetZoomPoint=null,this._targetDragPoint=null,this.vel.set(0,0,0),this._tUp=t.getNormal(),this._tRad=this.planet.camera.eye.distance(t))}},this._onMouseWheel=e=>{if(this.planet){this._targetRotationPoint=null,this._targetDragPoint=null;let t=e.x,i=e.y,s=this.planet.camera;if(s.isOrthographic){t=.5*this.renderer.handler.getWidth(),i=.5*this.renderer.handler.getHeight();let e=this._getTargetPoint(new H(t,i));if(!e)return;this._targetZoomPoint=e,this._grabbedSphere.radius=this._targetZoomPoint.length();let r=s.eye.distance(e),n=new v,o=s.unproject(t,i,r,n);const a=n.sub(o.scaleTo(r));if(e=new V(a,o).hitSphere(this._grabbedSphere),!e)return;this._targetZoomPoint=e}else{let e=this._getTargetPoint(new H(t,i));if(!e)return;this._targetZoomPoint=e,this._grabbedSphere.radius=this._targetZoomPoint.length()}if(this._curPitch=s.getPitch(),this._curYaw=s.getYaw(),this._curRoll=s.getRoll(),Math.sign(e.wheelDelta)!==this._wheelDirection)return this.vel.scale(.3),this._currScreenPos.set(t,i),void(this._wheelDirection=Math.sign(e.wheelDelta));this._currScreenPos.set(t,i),this._wheelDirection=Math.sign(e.wheelDelta);let r=20;this._velInertia=.83,this._isTouchPad=e.isTouchPad,e.isTouchPad&&(this._velInertia=.63,r=17);let n=this._targetZoomPoint.sub(s.eye);n.length()>6e3&&this._wheelDirection>0&&s.eye.getNormal().negate().dot(n.normalize())<.3&&(r=4.3);let o=this.planet.camera.eye.distance(this._targetZoomPoint)*r;this.force=e.direction.scale(this._wheelDirection).normalize().scale(this._wheelDirection<0?1.3*o:o).scale(this.zoomSpeed),this.vel.set(0,0,0),this.force_roll=this._curRoll}},this._onLDown=e=>{this.stop(),this._targetRotationPoint=null,this._targetZoomPoint=null,this.planet&&(this.planet.stopFlying(),this._grabbedPoint=this._getTargetPoint(e.pos),this._grabbedPoint&&(this._targetDragPoint=this._grabbedPoint,this.planet.camera.isOrthographic?this._grabbedDist=this.renderer.getDistanceFromPixel(e.pos):this._grabbedDist=this.renderer.activeCamera.eye.distance(this._grabbedPoint),this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this._grabbedSphere.radius=this._grabbedPoint.length(),this._eye0=this.planet.camera.eye.clone(),this._grabbedCameraHeight=this._eye0.length(),this._curPitch=this.planet.camera.getPitch(),this._curYaw=this.planet.camera.getYaw(),this._curRoll=this.planet.camera.getRoll(),this._currScreenPos.copy(e.pos)))},this._onLHold=e=>{if(this._grabbedPoint&&this.planet){let t=this.planet.camera;if(t.isOrthographic){const i=this._grabbedDist,s=new v,r=t.unproject(e.x,e.y,i,s),n=s.sub(r.scaleTo(i)),o=new V(n,r).hitSphere(this._grabbedSphere);if(!o)return;this._targetDragPoint=o;let a=F.getRotationBetweenVectors(this._targetDragPoint.getNormal(),this._grabbedPoint.getNormal()).mulVec3(t.eye);this.force=a.sub(t.eye).scale(this.dragInertia)}else if(t.slope>this.minSlope){this._grabbedDist=t.eye.distance(this._grabbedPoint);let i,s=t.unproject(e.x,e.y,this._grabbedDist),r=new V(t.eye,s).hitSphere(this._grabbedSphere);if(!r)return;if(this._targetDragPoint=r,this.freeMode)i=F.getRotationBetweenVectors(this._targetDragPoint.getNormal(),this._grabbedPoint.getNormal());else{let e=v.NORTH,s=Math.acos(r.dot(e)/this._grabbedSphere.radius)-Math.acos(this._grabbedPoint.dot(e)/this._grabbedSphere.radius),n=t.eyeNorm.dot(v.NORTH);(s>0&&n>=this.poleThreshold||s<0&&n<=-this.poleThreshold)&&(s=0);let o=F.axisAngleToQuat(e.cross(t.eyeNorm).normalize(),-s),a=v.proj_b_to_plane(r,e),l=v.proj_b_to_plane(this._grabbedPoint,e);i=F.getRotationBetweenVectors(a.getNormal(),l.getNormal()).mul(o)}let n=i.mulVec3(t.eye);this.force=n.sub(t.eye).scale(this.dragInertia)}else{let i=this._grabbedPoint,s=v.add(i,t.getRight()),r=v.add(i,i.getNormal()),n=new v;new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,s,r),n);let o=t.eye.add(n.subA(i).negate());this.force=o.sub(t.eye).scale(this.dragInertia),this._targetDragPoint=n}this.vel.set(0,0,0),this._currScreenPos.equal(e.pos)||this._currScreenPos.copy(e.pos),this._hold=!0}},this._onLUp=e=>{this._hold=!1,this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this.events=lt(Pl,this),this.force=new v,this.force_h=0,this.force_v=0,this.vel=new v,this.vel_h=0,this.vel_v=0,this.vel_roll=0,this.force_roll=0,this.mass=null!=e.mass?e.mass:1,this.inertia=null!=e.inertia?e.inertia:1,this._velInertia=zi,this.minSlope=null!=e.minSlope?e.minSlope:.35,this.dragInertia=null!=e.dragInertia?e.dragInertia:170,this.zoomSpeed=null!=e.zoomSpeed?e.zoomSpeed:1,this.poleThreshold=null!=e.poleThreshold?e.poleThreshold:.999,this.disableRotation=null!=e.disableRotation&&e.disableRotation,this.disableTilt=null!=e.disableTilt&&e.disableTilt,this._lookPos=void 0,this._grabbedPoint=null,this._grabbedDist=0,this._targetZoomPoint=null,this._targetDragPoint=null,this._targetRotationPoint=null,this._tUp=new v,this._tRad=0,this._rotHDir=0,this._rotVDir=0,this._wheelDirection=1,this._currScreenPos=new H,this._grabbedSphere=new Ft,this._rot=new F,this._curPitch=0,this._curYaw=0,this._curRoll=0,this._eye0=new v,this._newEye=new v,this._grabbedCameraHeight=0,this._isTouchPad=!1,this._freeMode=!1,this.mode=this._modeToNumber(e.mode||"adaptive")}oninit(){this.renderer&&(this.renderer.events.on("keyfree",W.KEY_ALT,this._onShiftFree),this.renderer.events.on("keyfree",W.KEY_PRINTSCREEN,this._onShiftFree))}onadd(){var e;null!=(e=this.planet)&&e.camera&&this.planet.camera.events.on("flystart",this._onCameraFly)}onremove(){var e;null!=(e=this.planet)&&e.camera&&this.planet.camera.events.off("flystart",this._onCameraFly)}onactivate(){super.onactivate();let e=this.renderer;e.events.on("mousewheel",this._onMouseWheel),e.events.on("rhold",this._onRHold),e.events.on("rdown",this._onRDown),e.events.on("lhold",this._onLHold),e.events.on("ldown",this._onLDown),e.events.on("lup",this._onLUp),e.events.on("draw",this.onDraw,this,-1e3),e.events.on("mousemove",this._onMouseMove),e.events.on("mouseleave",this._onMouseLeave),e.events.on("mouseenter",this._onMouseEnter)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("mousewheel",this._onMouseWheel),e.events.off("rhold",this._onRHold),e.events.off("rdown",this._onRDown),e.events.off("lhold",this._onLHold),e.events.off("ldown",this._onLDown),e.events.off("lup",this._onLUp),e.events.off("draw",this.onDraw),e.events.off("mousemove",this._onMouseMove),e.events.off("mouseleave",this._onMouseLeave),e.events.off("mouseenter",this._onMouseEnter)}onDraw(){this._updateVel(),this._handleZoom(),this._handleDrag(),this._handleRotation()}_handleRotation(){if((!this.disableRotation||!this.disableTilt)&&this.planet&&this._targetRotationPoint){let e=this.planet.camera;if((this.disableRotation||0===this.vel_h)&&(this.disableTilt||0===this.vel_v))return;if(!this.disableRotation){let t=this.vel_h*this.dt;e.rotateHorizontal(t,!1,this._targetRotationPoint,this._tUp)}if(!this.disableTilt){let t=this.vel_v*this.dt;e.rotateVertical(t,this._targetRotationPoint,.1)}this.events.dispatch(this.events.rotate,this),this._curPitch=e.getPitch(),this._curYaw=e.getYaw(),this._curRoll=e.getRoll(),this._velInertia=zi}}_getTargetPoint(e){return this.planet?this.planet.camera.isOrthographic?this.renderer.getCartesianFromPixel(e)||null:this.planet.camera.getAltitude()>8e4?this.planet.getCartesianFromPixelEllipsoid(e)||null:this.planet.getCartesianFromPixelTerrain(e)||null:null}get freeMode(){return 1!==this.mode&&(0===this.mode||this._freeMode)}setMode(e){this.mode=this._modeToNumber(e)}_modeToNumber(e){switch(e){case"lockNorth":return 1;case"free":return 0;default:return 2}}_handleDrag(){if(this.planet&&this._targetDragPoint&&this._grabbedPoint&&this.vel.length()>.1){this._velInertia=zi;let e=this.planet.camera;if(e.slope>this.minSlope){let t=this.vel.scaleTo(this.dt),i=v.proj_b_to_plane(t,e.eyeNorm),s=e.eye.add(i).normalize().scale(this._grabbedCameraHeight);if(this.freeMode){let t=F.getRotationBetweenVectors(e.eye.getNormal(),s.getNormal());e.rotate(t),e.eye.copy(s)}else{let t=s.getNormal().dot(v.NORTH),i=e.eyeNorm.dot(v.NORTH);(t>i&&t>=this.poleThreshold||t<i&&t<=-this.poleThreshold)&&this.vel.scale(.8),e.eye.copy(s),this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll)}}else{let t=this.vel.scaleTo(this.dt),i=e.eye.add(t);e.eye.copy(i),e.checkTerrainCollision(),this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll)}this.events.dispatch(this.events.drag,this)}}_corrRoll(){this.planet.camera.slope<.5&&(this._curRoll-=this.vel_roll*this.dt,this._curRoll<.01*Math.PI/180&&(this._curRoll=.01*Math.PI/180))}_handleZoom(){if(this._targetZoomPoint&&this.vel.length()>.1){let e=this.planet.camera,t=this._targetZoomPoint,i=e.eye.clone(),s=t.sub(e.eye).normalize(),r=this.vel.getNormal(),n=Math.sign(r.dot(e.getForward())),o=this.vel.scaleTo(this.dt);this._grabbedSphere.radius>i.length()&&(n*=-1);let a=e.getForward().scaleTo(n*o.length());i.addA(a),this.events.dispatch(this.events.zoom,this);let l=e.maxAltitude+this.planet.ellipsoid.getEquatorialSize();if(i.length()>l)return void i.copy(i.getNormal().scale(l));let h=new V(i,s).hitSphere(this._grabbedSphere);if(!h)return void this.vel.set(0,0,0);let c=F.getRotationBetweenVectors(h.getNormal(),t.getNormal());if(e.eye=c.mulVec3(i),e.rotate(c),!this.freeMode){this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll),e.update();let i=e.unproject2v(this._currScreenPos,e.eye.distance(this._targetZoomPoint)),s=t.sub(e.eye).normalize(),r=new v,n=new v,o=vt.fromPoints(t,t.add(e.getUp()),t.add(e.getRight()));new V(e.eye,i).hitPlaneRes(o,r),new V(e.eye,s).hitPlaneRes(o,n);let a=n.sub(r);e.eye=e.eye.add(a),this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll)}if(e.checkTerrainCollision(),e.isOrthographic){let t=e.getAltitude();t&&(e.focusDistance=Math.abs(t))}}}_updateVel(){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(this.velocityInertia),this.vel.length()<.001&&this.vel.set(0,0,0),this.force.set(0,0,0),this._updateVel_h(),this._updateVel_v(),this._updateVel_roll()}_updateVel_h(){let e=this.force_h/this.mass;this.vel_h+=e,this.vel_h*=this.velocityInertia,Math.abs(this.vel_h)<.001&&(this.vel_h=0),this.force_h=0}_updateVel_v(){let e=this.force_v/this.mass;this.vel_v+=e,this.vel_v*=this.velocityInertia,Math.abs(this.vel_v)<.001&&(this.vel_v=0),this.force_v=0}_updateVel_roll(){let e=this.force_roll/this.mass;this.vel_roll+=e,this.vel_roll*=this.velocityInertia,this.force_roll=0}get dt(){return.001*this.renderer.handler.deltaTime}get velocityInertia(){return this._velInertia*this.inertia}stop(){this.vel.set(0,0,0),this.vel_h=0,this.vel_v=0,this._velInertia=zi,this._targetZoomPoint=null,this._grabbedPoint=null,this._targetRotationPoint=null,this._targetDragPoint=null}}const Dn=e=>e>1e3?`${(e/1e3).toFixed(1)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`;let Sl=$.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);const Rl={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]},Fn={scale:1,instanced:!0,tag:"ruler",color:"rgb(0,305,0)",object3d:Sl};class ua extends de{constructor(e={}){super(e.name),this._onCornerLdown=e=>{var t,i;if(!this._startLonLat){null==(i=null==(t=this.renderer)?void 0:t.controls.navigation)||i.deactivate(),this._startClick.set(e.x,e.y);let s=e.pickingObject.getCartesian();this._startPos=this._planet.getPixelFromCartesian(s),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=()=>{var e;this._pickedCorner&&(null==(e=this.renderer.controls.navigation)||e.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=lt(Ml),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 H,this._anchorLonLat=null,this._heading=0,this._trackLayer=new _t("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._labelLayer=new _t("ruler-label",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-100,relativeToGround:!0,hideInLayerSwitcher:!0}),this._cornersLayer=new _t("corners",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[100,4e6,1],pickingScale:2}),this._propsLabel=new G({name:"propsLabel",label:Rl}),this._trackEntity=new G({polyline:{path3v:[],thickness:4.8,color:"rgb(255,131,0)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01,this._cornerEntity=[new G({geoObject:Fn,properties:{name:"start"}}),new G({geoObject:Fn,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 s=this._planet.ellipsoid.lonLatToCartesian(t),r=this._planet.ellipsoid.inverse(e,t),n=r.distance;this._heading=r.initialAzimuth;let o=[],a=s.sub(i),l=a.length();a.normalize();for(let e=0;e<120;e++){let t=a.scaleTo(e*l/120).addA(i);o.push(t)}o.push(s),this._trackEntity.polyline.setPath3v([o]),this._ignoreTerrain&&(this._propsLabel.setCartesian3v(o[Math.floor(o.length/2)]),this._propsLabel.label.setText(`${Dn(n)}, ${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,s=e.length-1;i<s;i++)t+=e[i+1].distance(e[i]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label.setText(`${Dn(t)}, ${Math.round(this._heading)} deg`)}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Ml=["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 _a extends Q{constructor(e={}){super(e),this._rulerScene=new ua({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 Bl=$.createCylinder(1.1,0,2,6,1,!0,!0,0,0,0);const On={startColor:"rgb(255,131,0)",endColor:"rgb(255,131,0)",thickness:5},Ys={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]},Nn={scale:1,instanced:!0,tag:"height-ruler",color:"rgb(255,131,0)",object3d:Bl};class kl extends ua{constructor(e={}){super(e),this._geoRulerLayer=new _t("rayHeightRuler",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-2,relativeToGround:!1,hideInLayerSwitcher:!0}),this._rayV=new G({name:"verticalRay",ray:On}),this._rayH=new G({name:"heightRay",ray:On}),this._heightLabels=[new G({name:"startCornerLabel",label:{...Ys}}),new G({name:"endCornerLabel",label:{...Ys}}),new G({name:"deltaLabel",label:{...Ys}})]}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 G({geoObject:Nn,properties:{name:"start"}}),new G({geoObject:Nn,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 Hn extends _a{constructor(e={}){super(e),this._rulerScene=new kl({name:`heightRulerScene:${this.__id}`,ignoreTerrain:!1})}}const Ws=[.001,.005,.01,.05,.1,.2,.5,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 fa extends Q{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 Wr(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,s=this.planet.getDistanceFromPixel(i)||0;0===s&&(i=t.project3v(v.ZERO),s=this.planet.getDistanceFromPixel(i)||0);let r=t.getForward().scaleTo(s).addA(t.eye),n=s*Math.tan(t.viewAngle*j),o=r.add(t.getRight().scaleTo(n)),a=t.project3v(o);this._mPx=n/a.distance(i);let l=this._mPx*this._minWidth,h=Re(Ws,l,((e,t)=>e-t));h<0&&(h=~h);let c=Ws[h],d=(c-l)/(Ws[h+1]-c);this.currWidth=this._minWidth+d*(this._maxWidth-this._minWidth),this._scaleLabelEl.innerText=c>=1e3?c/1e3+" km":c>=1?`${c} m`:c>=.01?100*c+" cm":1e3*c+" mm",this._metersInMinSize=l,this.el.style.width=this.currWidth+"px"}}class ga extends Q{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 cr([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}get colorTwo(){let e=this._colorTwo;return cr([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}set colorOne(e){let t=ts(e);this._colorOne[0]=t.x,this._colorOne[1]=t.y,this._colorOne[2]=t.z}set colorTwo(e){let t=ts(e);this._colorTwo[0]=t.x,this._colorTwo[1]=t.y,this._colorTwo[2]=t.z}oninit(){this.renderer.handler.addProgram(new X("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,s=i.uniforms,r=e.gl,n=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(s.camPos,[n.eye.x,n.eye.y,n.eye.z]),r.uniform2fv(s.iResolution,[e.getWidth(),e.getHeight()]),r.uniform1f(s.fov,n.getViewAngle()),r.uniform1f(s.earthRadius,this.planet.ellipsoid.getPolarSize()+1),r.uniform3fv(s.colorOne,this._colorOne),r.uniform3fv(s.colorTwo,this._colorTwo),r.uniformMatrix4fv(s.viewMatrix,!1,n.getViewMatrix()),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}}const $s=14959787e4;function Xs(e){var t=e-es,i=282.9404+470935e-10*t,s=.016709-1.151e-9*t,r=hr(356.047+.9856002585*t),n=23.4392911-3.563e-7*t,o=r+J*s*Math.sin(r*j)*(1+s*Math.cos(r*j)),a=Math.cos(o*j)-s,l=Math.sin(o*j)*Math.sqrt(1-s*s),h=Math.sqrt(a*a+l*l),c=hr(Math.atan2(l,a)*J+i),d=a=h*Math.cos(c*j),_=(l=h*Math.sin(c*j))*Math.cos(n*j),u=l*Math.sin(n*j),f=Xi*(24*t/23.9344694-259.853/360);return F.zRotation(-f).mulVec3(new v(-d*$s,-_*$s,u*$s))}class Il{constructor(e){this._renderNode=null,this._position=e.position||new v,this._ambient=e.ambient||new v,this._diffuse=e.diffuse||new v(.8,.8,.8),this._specular=e.specular||new v(.18,.18,.18),this._shininess=null!=e.shininess?e.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}isActive(){return this._active}setPosition3v(e){this.setPosition(e.x,e.y,e.z)}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,this._renderNode&&(this._renderNode._lightPosition[0]=e,this._renderNode._lightPosition[1]=t,this._renderNode._lightPosition[2]=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 s=this._renderNode;s&&(s._lightParams[0]=e,s._lightParams[1]=t,s._lightParams[2]=i)}setDiffuse(e,t,i){this._diffuse.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[3]=e,s._lightParams[4]=t,s._lightParams[5]=i)}setSpecular(e,t,i){this._specular.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[6]=e,s._lightParams[7]=t,s._lightParams[8]=i)}setShininess(e){this._shininess=e;const t=this._renderNode;t&&(t._lightShininess=e)}addTo(e){this._renderNode=e,this.setShininess(this._shininess),this.setAmbient3v(this._ambient),this.setDiffuse3v(this._diffuse),this.setSpecular3v(this._specular)}}class Dr extends Q{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 Il({ambient:new v(.15,.15,.25),diffuse:new v(.9,.9,.8),specular:new v(.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(Xs(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.getUp().dot(t))),e.slope>.99&&(i=e.getUp());let s=v.proj_b_to_plane(i,t,i).normalize().scale(this.offsetVertical),r=v.proj_b_to_plane(e.getRight(),t,e.getRight()).normalize().scale(this.offsetHorizontal),n=s.add(r),o=e.eye.add(n);if(this._k>0){this._k-=.001;let e=F.getRotationBetweenVectors(this.sunlight._position.normal(),o.normal()).slerp(F.IDENTITY,this._k).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else this.sunlight.setPosition3v(o)}else if(this._k=1,this._f>0){this._f-=.001;let e=F.getRotationBetweenVectors(this.sunlight._position.normal(),Xs(this._currDate).normal()).slerp(F.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(Xs(this._currDate)),this._f=0)}}}const zl=["inertiamove","drag","doubletapzoom"];class Vn{constructor(){this.x=0,this.y=0,this.prev_x=0,this.prev_y=0,this.grabbedPoint=null,this.grabbedSpheroid=new Ft,this._vec=new H,this._vecPrev=new H}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 pa extends Q{constructor(e={}){super(e),this._onCameraFly=()=>{this.stopRotation()},this._name="touchNavigation",this.events=lt(zl,this),this.grabbedPoint=new v,this.inertia=null!=e.inertia?e.inertia:.007,this.minSlope=null!=e.minSlope?e.minSlope:.1,this.jerkLimit=null!=e.jerkLimit?e.jerkLimit:.3,this.grabbedSpheroid=new Ft,this.planet=null,this.qRot=new F,this.scaleRot=0,this.rot=1,this._eye0=new v,this.pointOnEarth=null,this.earthUp=null,this.touches=[new Vn,new Vn],this._keyLock=new Me,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))}onadd(){var e;null!=(e=this.planet)&&e.camera&&this.planet.camera.events.on("flystart",this._onCameraFly)}onremove(){var e;null!=(e=this.planet)&&e.camera&&this.planet.camera.events.off("flystart",this._onCameraFly)}onTouchStart(e){const t=this.renderer.handler;if(this._touching=!0,2===e.sys.touches.length){const i=this.touches[0],s=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 H(i.x,i.y))||null,s.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*t.pixelRatio,s.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*t.pixelRatio,s.prev_x=s.x,s.prev_y=s.y,s.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new H(s.x,s.y))||null,this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter())||null,this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal()),i.grabbedPoint&&s.grabbedPoint&&(i.grabbedSpheroid.radius=i.grabbedPoint.length(),s.grabbedSpheroid.radius=s.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 L(e.lon,e.lat,.57*this.planet.camera.eye.distance(t))),this.events.dispatch(this.events.doubletapzoom,this)}}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],n=this.touches[1];if(!r.grabbedPoint||!n.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,n.prev_x=n.x,n.prev_y=n.y,n.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*i.pixelRatio,n.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*i.pixelRatio;const o=r.vec.add(n.vec).scale(.5),a=this.planet.getCartesianFromPixelEllipsoid(o);if(a){this.pointOnEarth=a;const e=Math.atan2(r.prev_y-n.prev_y,r.prev_x-n.prev_x),i=Math.atan2(r.y-n.y,r.x-n.x)-e,o=t.eye.distance(this.pointOnEarth),l=r.vec.sub(n.vec),h=r.vecPrev.sub(n.vecPrev);let c=l.length()/h.length();const d=1+this.jerkLimit,_=1-this.jerkLimit;c=c>d?d:c<_?_:c;let u=o*-(1-c);t.eye.addA(t.getForward().scale(u)),t.rotateAround(-i,!1,this.pointOnEarth,this.earthUp);const f=r.vec.add(n.vec).scale(.5),g=r.vecPrev.add(n.vecPrev).scale(.5),p=f.sub(g).scale(-1);var s=.5/o*t._lonLat.height*j;s>.003&&(s=.003),t.rotateHorizontal(s*-p.x,!1,this.pointOnEarth,this.earthUp),t.rotateVertical(s*-p.y,this.pointOnEarth,this.minSlope),t.checkTerrainCollision(),t.update(),this.events.dispatch(this.events.drag,this)}this.scaleRot=0}else if(1===e.sys.touches.length){let s=this.touches[0];if(s.prev_x=s.x,s.prev_y=s.y,s.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,s.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,!s.grabbedPoint)return;this.planet.stopFlying();let r=e.direction,n=new V(t.eye,r).hitSphere(s.grabbedSpheroid);if(n)if(t.slope>.2){this.qRot=F.getRotationBetweenVectors(n.normal(),s.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t.rotate(e),t.checkTerrainCollision(),t.update(),this.events.dispatch(this.events.drag,this),this.scaleRot=1}else{let e=s.grabbedPoint,i=v.add(e,t.getUp()),r=v.add(e,e.getNormal()),n=t.unproject(s.x,s.y),o=new v;new V(t.eye,n).hitPlaneRes(vt.fromPoints(e,i,r),o)===V.INSIDE&&(t.eye=this._eye0.addA(o.subA(e).negate()),t.checkTerrainCollision(),t.update(),this.events.dispatch(this.events.drag,this),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(F.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.rotate(i),t.checkTerrainCollision(),t.update(),this.events.dispatch(this.events.inertiamove,this)}this.setLock(t.eye.distance(i)/t.getAltitude()>.01)}}setLock(e){e?(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 ma extends Q{constructor(e={}){super(e),this._keyLock=new Me,this._move=0,this._targetPoint=null}oninit(){let e=new ce({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 ce({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 Dl extends de{constructor(e={}){var t,i;super(e.name),this._ignoreTerrain=!1,this.events=new bi(Fl),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 G({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]}}),null==(i=null==(t=this._propsLabel)?void 0:t.label)||i.setVisibility(!1),this._trackEntity=new G({polyline:{path3v:[],thickness:3.8,color:"rgb(455,455,455)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01;let s=$.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);this._cornerEntity=[new G({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(0,305,0)",object3d:s},properties:{name:"start"}}),new G({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(455,0,0)",object3d:s},properties:{name:"end"}})],this._trackLayer=new _t("track",{entities:[this._trackEntity,this._propsLabel],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!1}),this._cornersLayer=new _t("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(){var e,t,i,s,r;null==(t=null==(e=this._propsLabel)?void 0:e.label)||t.setVisibility(!1),this._onMouseMove_=this._onMouseMove.bind(this),null==(i=this.renderer)||i.events.on("mousemove",this._onMouseMove_,this),this._onMouseLdown_=this._onMouseLdown.bind(this),null==(s=this.renderer)||s.events.on("ldown",this._onMouseLdown_,this),this._onMouseLup_=this._onMouseLup.bind(this),null==(r=this.renderer)||r.events.on("lup",this._onMouseLup_,this),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer)}_deactivate(){var e,t,i;this._startLonLat=null,this._trackLayer.remove(),this._cornersLayer.remove(),null==(e=this.renderer)||e.events.off("mousemove",this._onMouseMove_),null==(t=this.renderer)||t.events.off("ldown",this._onMouseLdown_),null==(i=this.renderer)||i.events.off("lup",this._onMouseLup_),this.clear(),this._onMouseMove_=null,this._onMouseLdown_=null,this._onMouseLup_=null}_onMouseLdown(e){var t,i,s,r,n,o;if(e.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.renderer.handler.canvas.style.cursor="pointer",!this._startLonLat){null==(t=this._propsLabel.label)||t.setVisibility(!1),null==(i=this._trackEntity.polyline)||i.setPath3v([]),null==(s=this._cornerEntity[0].geoObject)||s.setVisibility(!0),null==(r=this._cornerEntity[1].geoObject)||r.setVisibility(!0),null==(o=null==(n=this.renderer)?void 0:n.controls.navigation)||o.deactivate(),this._startLonLat=this._planet.getLonLatFromPixelTerrain(e);let a=this._planet.ellipsoid.lonLatToCartesian(this._startLonLat);this._cornerEntity[0].setCartesian3v(a),this._cornerEntity[1].setCartesian3v(a)}}_onMouseLup(e){var t,i,s;if(this._startLonLat){if(this._pickedCorner=null,this._anchorLonLat=null,null==(t=this._propsLabel.label)||t.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",null==(s=null==(i=this.renderer)?void 0:i.controls.navigation)||s.activate()}_drawLine(e,t,i){var s;i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let r=this._planet.ellipsoid.lonLatToCartesian(t),n=this._planet.ellipsoid.direct(e,t);this._heading=n.initialAzimuth;let o=[];this._cornerEntity[0].setCartesian3v(i),this._cornerEntity[1].setCartesian3v(r);let a=[i,this._planet.ellipsoid.lonLatToCartesian(new L(t.lon,e.lat,e.height)),r,this._planet.ellipsoid.lonLatToCartesian(new L(e.lon,t.lat,e.height)),i];o.push(i);let l=(e,t)=>{let i=t.sub(e),s=i.length();i.normalize();for(let t=0;t<120;t++){let r=i.scaleTo(t*s/120).addA(e);o.push(r)}};for(let e=0;e<a.length-1;e++)l(a[e],a[e+1]);null==(s=this._trackEntity.polyline)||s.setPath3v([o]),this._ignoreTerrain}_onMouseMove(e){var t;if(this._startLonLat){null==(t=this._propsLabel.label)||t.setVisibility(!0);let i=this._planet.getLonLatFromPixelTerrain(e);if(!i)return;this._drawLine(this._startLonLat,i)}}clear(){var e,t,i;null==(e=this._trackEntity.polyline)||e.clear(),null==(t=this._cornerEntity[0].geoObject)||t.setVisibility(!1),null==(i=this._cornerEntity[1].geoObject)||i.setVisibility(!1)}frame(){var e,t;let i=null==(e=this._trackEntity.polyline)?void 0:e.getPath3v()[0];if(i&&!this._ignoreTerrain){let e=0;for(let t=0,s=i.length-1;t<s;t++)e+=i[t+1].distance(i[t]);this._propsLabel.setCartesian3v(i[Math.floor(i.length/2)]),null==(t=this._propsLabel.label)||t.setText(`${s=e,s>1e3?`${(s/1e3).toFixed(1)} km`:s>9?`${Math.round(s)} m`:`${s.toFixed(1)} m`}, ${Math.round(this._heading)} deg`)}var s}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Fl=["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 te(e,t){return new Date(+e+1e3*t)}function Ol(e,t=!0,i=!1){let s=Hl[e.getMonth()],r=e.getUTCDate(),n=e.getUTCFullYear();if(t){let t=e.getUTCHours().toString().padStart(2,"0"),o=e.getUTCMinutes().toString().padStart(2,"0"),a=e.getUTCSeconds().toString().padStart(2,"0");return i?`${s} ${r} ${n} ${t}:${o}:${a}.${e.getUTCMilliseconds().toString().padStart(3,"0")}`:`${s} ${r} ${n} ${t}:${o}:${a}`}return`${s} ${r} ${n}`}function Un(e,t=0,i=10,s=2,r="white"){e.lineWidth=s,e.strokeStyle=r,e.beginPath(),e.moveTo(t,0),e.lineTo(t,i),e.stroke()}function Nl(e,t,i,s,r="12px Arial",n="black",o="left",a="bottom",l=0){e.save(),e.translate(i,s),e.rotate(l*j),e.fillStyle=n,e.textBaseline=a,e.font=r,e.textAlign=o,e.fillText(t,0,0),e.restore()}const Zs=[[.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]],Hl=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Vl=["change","current"];class Ul{constructor(e={}){this.events=lt(Vl),this._current=e.current||new Date,this._rangeStart=e.rangeStart||new Date,this._rangeEnd=e.rangeEnd||te(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 Fe=.001,Gl=["startdrag","stopdrag","startdragcurrent","stopdragcurrent","setcurrent","reset","play","playback","pause","visibility"],Gn="#bfbfbf";class jl extends ut{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 Ul({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,s=-(i-.5*this.clientWidth),r=this.model.rangeStartTime+this._millisecondsInPixel*i;this._zoom(r,s,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*Fe;this.model.set(te(this._clickRangeStart,t),te(this._clickRangeEnd,t))}else if(this._isCurrentDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*Fe,i=te(this._clickCurrentDate,-t);i>=this.model.rangeStart&&i<=this.model.rangeEnd&&(this.model.current=te(this._clickCurrentDate,-t))}},this.events=this.events.registerNames(Gl),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 dt({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 dt({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 jo({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 s=(e-(this.model.rangeStartTime+.5*this.model.range))*Fe,r=te(this.model.rangeStart,s),n=te(this.model.rangeEnd,s),o=(n.getTime()-r.getTime())/20*Fe,a=te(r,o*i),l=te(n,-o*i),h=(l.getTime()-a.getTime())/this.clientWidth;if(h<31536e6&&h>.1){let e=h*t*Fe;this.model.set(te(a,e),te(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=Zs.length;t<i;t++)if(Zs[t][0]>e)return Zs[t-1]}(this._minWidth*this._millisecondsInPixel*Fe);if(e){this._clearCanvas();let i=1e3*e[0],s=i/this._millisecondsInPixel,r=e[1],n=(t=this.model.rangeStartTime)-t%i,o=e[0]<1,a=e[0]<86400;for(let e=n,t=this.model.rangeEndTime+i;e<t;e+=i){let t=this.getOffsetByTime(e);t>=0&&t<=this.clientWidth*this._canvasScale&&Un(this._ctx,t*this._canvasScale,10*this._canvasScale,2*this._canvasScale,Gn);for(let e=1;e<r;e++){let i=t+e*(s/r);i>=0&&i<=this.clientWidth*this._canvasScale&&Un(this._ctx,i*this._canvasScale,5*this._canvasScale,1*this._canvasScale,Gn)}Nl(this._ctx,Ol(new Date(e),a,o),t*this._canvasScale,26*this._canvasScale,"24px monospace","#bfbfbf","center")}this._drawCurrent()}var t}}function jn(e,t){const i=new Date(e);return i.setHours(i.getHours()+t),i}class pi{constructor(){this.resolve=()=>{},this.reject=()=>{},this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t})),Object.freeze(this)}}const ql=["startcollecting","profilecollected","clear"];class Yl{constructor(e={}){this.events=lt(ql),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,s){this._minX=e,this._maxX=t,i&&(this._minY=i),s&&(this._maxY=s)}_getHeightAsync(e,t,i){let s=new pi;if(this.planet){let r=this.planet.terrain.geoid.getHeightLonLat(e);this.planet.terrain.getHeightAsync(e,(n=>{this.planet&&i===this._promiseCounter?(n+=r,this._pGroundCoords[t][1]=n,this._pGroundCoords[t][2]=0,this._pGroundCoords[t][3]=e.height,n>this._pMaxY&&(this._pMaxY=n),n<this._pMinY&&(this._pMinY=n),this._updatePointType(t),s.resolve(n)):s.reject()}))}else s.reject();return s.promise}_collectCoordsBetweenTwoTrackPoints(e,t,i,s,r,n){if(this.planet)for(let o=1;o<=t;o++){this._pDist+=1,this._pIndex++;let t=o*i,a=s.add(r.scaleTo(t)),l=this.planet.ellipsoid.cartesianToLonLat(a);this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,e],((e,t)=>{this._promiseArr.push(this._getHeightAsync(e,t,n))})(l,this._pIndex)}}_collectAllPoints(e,t){if(!this.planet||t!==this._promiseCounter)return;let i=new v,s=new v;for(let r=1,n=e.length;r<n;r++){let n=e[r-1],o=e[r];this.planet.ellipsoid.lonLatToCartesianRes(n,i),this.planet.ellipsoid.lonLatToCartesianRes(o,s);let a=s.sub(i),l=a.length(),h=this.planet.ellipsoid.getSurfaceNormal3v(i),c=v.proj_b_to_plane(a,h),d=c.length(),_=Math.floor(d/1),u=1*l/d;this._getGroundElevation(n,r-1,t),c.normalize(),a.normalize(),this._collectCoordsBetweenTwoTrackPoints(r-1,_,u,i,a,t),this._pDist+=d-1*_,this._pIndex++;let f=o.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,s)=>{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 pi;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 va="rgb(198, 198, 198)",qn=[va,"rgb(255, 255, 0)","rgb(255, 0, 0)"],Wl=["startdrag","stopdrag","pointer","mouseenter","mouseleave","dblclick","tracklength","groundlength","warninglength","collisionlength"];class $l extends ut{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 Yl}),this._onMouseDblClick=e=>{let t,i=this.$canvas.getBoundingClientRect(),s=e.clientX-i.left,r=this._leftDistance+(this._rightDistance-this._leftDistance)*s/this.clientWidth,n=this.model.drawData[1],o=this.model.drawData[0];r<0?(t=1,r=0,s=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):r>this.model.planeDistance?(t=n.length-1,r=this.model.planeDistance,s=(r-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-Re(n,r,((e,t)=>e-t[0]));let a=n[t-1],l=n[t],h=(r-a[0])/(l[0]-a[0]),c=a[1]+h*(l[1]-a[1]),d=a[4],_=o[d],u=o[d+1];h=(r-_[0])/(u[0]-_[0]);let f=_[1]+h*(u[1]-_[1]);this.events.dispatch(this.events.dblclick,r,_,u,a,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(),s=e.clientX-i.left,r=s-.5*this.$canvas.clientWidth,n=r*this._canvasScale/this._pixelsInMeter_x,o=n+this._leftDistance+t,a=n+this._rightDistance-t;n=-r*(a-o)/this.clientWidth,this.setFrame(o+n,a+n),this.redrawPointerCanvas(s)}},this.events=this.events.registerNames(Wl),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,s=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=s.length-1,i=this.model.planeDistance,e=(i-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-Re(s,i,((e,t)=>e-t[0]));let n=s[t-1],o=s[t],a=(i-n[0])/(o[0]-n[0]),l=n[1]+a*(o[1]-n[1]),h=n[4],c=r[h],d=r[h+1];a=(i-c[0])/(d[0]-c[0]);let _=c[1]+a*(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,n,o,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=Ge(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 s=e[0];const r=this.model.maxY;let n=(-this._leftDistance+s[0])*this._pixelsInMeter_x,o=(r-s[1])*this._pixelsInMeter_y;t[s[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(n-4,o-4,8,8),i.stroke(),i.fillStyle="white",i.font=26/devicePixelRatio+"px Arial",i.textBaseline="bottom",i.textAlign="left",i.fillText(`${Math.round(s[1]-t[s[2]][1]).toString()} m`,n+1,o-10),i.stroke();for(let s=1,a=e.length;s<a;s++){let a=e[s];n=(-this._leftDistance+a[0])*this._pixelsInMeter_x,o=(r-a[1])*this._pixelsInMeter_y,t[a[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(n-4,o-4,8,8),i.stroke(),i.fillStyle="white",i.fillText(`${Math.round(a[1]-t[a[2]][1]).toString()} m`,n+1,o-10),i.stroke()}}}_drawTrack(e,t){let i=e[0],s=this._ctx;if(s){const r=this.model.maxY;s.lineWidth=5,s.strokeStyle="rgb(0, 255, 50)",s.beginPath(),s.moveTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(r-i[1])*this._pixelsInMeter_y);let n=0;for(let t=1,i=e.length;t<i;t++){let i=e[t];s.lineTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(r-i[1])*this._pixelsInMeter_y);let o=e[t-1],a=i[0]-o[0],l=i[1]-o[1],h=a*a,c=l*l;n+=Math.sqrt(h+c)}s.stroke(),s.lineWidth=2,s.strokeStyle="rgba(255,255,255,0.7)",s.beginPath();let o=(-this._leftDistance+i[0])*this._pixelsInMeter_x,a=(r-i[1])*this._pixelsInMeter_y,l=(r-t[i[2]][1])*this._pixelsInMeter_y;s.moveTo(o,a),s.lineTo(o,l);for(let i=1,n=e.length;i<n;i++){let n=e[i];o=(-this._leftDistance+n[0])*this._pixelsInMeter_x,a=(r-n[1])*this._pixelsInMeter_y,l=(r-t[n[2]][1])*this._pixelsInMeter_y,s.strokeStyle="rgba(255,255,255,0.7)",s.moveTo(o,a),s.lineTo(o,l)}s.stroke(),this.events.dispatch(this.events.tracklength,n)}}_drawTerrain(e){let t=e[0],i=this._ctx;if(i){const s=this.model.maxY;i.lineWidth=5,i.strokeStyle=va,i.beginPath(),i.moveTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,this.$canvas.height),i.lineTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,(s-t[1])*this._pixelsInMeter_y);let r=0;for(let t=1,n=e.length;t<n;t++){let n=e[t];i.lineTo((-this._leftDistance+n[0])*this._pixelsInMeter_x,(s-n[1])*this._pixelsInMeter_y);let o=e[t-1],a=n[0]-o[0],l=n[1]-o[1],h=a*a,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 s=0,r=0;for(let n=0,o=e.length-1;n<o;n++){let o=e[n],a=e[n+1];if(0!==o[2]&&0!==a[2]){let e=a[0]-o[0],n=a[1]-o[1],l=e*e,h=n*n;2===o[2]?(t.stroke(),t.beginPath(),t.strokeStyle=qn[2],r+=Math.sqrt(l+h)):1===o[2]&&(t.stroke(),t.beginPath(),t.strokeStyle=qn[1],s+=Math.sqrt(l+h)),t.moveTo((-this._leftDistance+o[0])*this._pixelsInMeter_x,(i-o[1])*this._pixelsInMeter_y),t.lineTo((-this._leftDistance+a[0])*this._pixelsInMeter_x,(i-a[1])*this._pixelsInMeter_y)}}t.stroke(),this.events.dispatch(this.events.warninglength,s),this.events.dispatch(this.events.collisionlength,r)}}}let Xl=$.createCylinder(.33,0,1,20,1,!0,!1,0,0,0),Zl=$.createCylinder(.33,.33,1.1,20,1,!0,!0,0,-.55,0);const Kl={startPosition:new v,endPosition:new v,startColor:"rgba(255,131,0,0.2)",endColor:"rgba(255,131,0,1.0)",thickness:2.7},Ql={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]},Jl={text:"",face:"arial",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]},Yn={face:"arial",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]},th={instanced:!0,tag:"ground-pointer",color:"rgb(0,305,0)",object3d:Xl},eh={instanced:!0,tag:"head-pointer",color:"rgb(305,305,0)",object3d:Zl};class ih extends de{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 H(e.x,e.y).sub(this._startClickPos),i=this._startEntityPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);s&&this.setGroundPointCartesian3v(this._pickedGroundEntity.properties.index,s)}else if(this._pickedHeadEntity){let t=this._planet.camera,i=this._pickedHeadEntity.properties.groundEntity.getCartesian(),s=this._planet.ellipsoid.getSurfaceNormal3v(i),r=i.add(s),n=i.add(t.getRight()),o=new v;if(new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,r,n),o)===V.INSIDE){let e=v.proj_b_to_a(o,i),t=e.sub(i).dot(i),r=i.add(s.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.navigation.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.navigation.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.navigation.deactivate(),this._pickedHeadEntity=e.pickingObject},this._onHeadPointerLUp=e=>{this.renderer.controls.navigation.activate(),this._pickedHeadEntity=null},this.events=lt(sh),this._planet=e.planet||null,this._pickedGroundEntity=null,this._pickedHeadEntity=null,this._startClickPos=new H,this._startEntityPos=new H,this._clampToGround=!0,this._trackLayer=new _t("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._groundPointersLayer=new _t("ground-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,5e3,.02],pickingScale:1.5}),this._headPointersLayer=new _t("head-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,1e4,.02],pickingScale:1}),this._columnPointersLayer=new _t("column-pointers",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._trackEntity=new G({polyline:{path3v:[],thickness:3.8,color:"rgba(0,305,0,0.8)",isClosed:!1}}),this._trackLayer=new _t("column-pointers",{entities:[this._trackEntity],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._heightsLayer=new _t("heights-labels",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._pointerHeadEntity=new G({cartesian:new v,billboard:Ql}),this._pointerLabelEntity=new G({cartesian:new v,label:Jl}),this._pointerRayEntity=new G({cartesian:new v,ray:Kl}),this._pointerLayer=new _t("pointer",{entities:[this._pointerHeadEntity,this._pointerLabelEntity,this._pointerRayEntity],pickingEnabled:!1,hideInLayerSwitcher:!0})}flyExtent(){let e=this._headPointersLayer.getEntities(),t=180,i=180,s=-180,r=-180,n=-1e6;if(e.length>1){for(let o=0;o<e.length;o++){let a=e[o].getLonLat();a.lon<t&&(t=a.lon),a.lat<i&&(i=a.lat),a.lon>s&&(s=a.lon),a.lat>r&&(r=a.lat),a.height>n&&(n=a.height)}this._planet.camera.flyExtent(new U(new L(t,i),new L(s,r)),n,{amplitude:0})}}get planet(){return this._planet}_createGroundPointer(e,t=10){let i=this.ellipsoid.getSurfaceNormal3v(e),s=e.add(i.scale(t)),r=new G({ray:{startPosition:e,endPosition:s,startColor:"rgba(255,255,255,0.2)",endColor:"rgba(355,355,355,1.0)",thickness:3.2}}),n=new G({cartesian:e,geoObject:th}),o=new G({cartesian:s,geoObject:eh,properties:{}}),a=new G({cartesian:s,label:Yn});a.appendChild(new G({cartesian:s,label:{...Yn,offset:[-47,45,0]}}));const l=this._groundPointersLayer.getEntities().length;return r.properties=n.properties=o.properties={index:l,altitude:t,lonLatEll:new L,headEntity:o,groundEntity:n,columnEntity:r,heightLabelEntity:a},{headEntity:o,groundEntity:n,columnEntity:r,heightLabelEntity:a}}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,s=t.length;i<s;i++){let s=e[i];t[i]=s.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,(s=>{if(this._planet){let i=this.getHeightMSL(e);t(s+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,s=e.length-1;t<s;t++){let s=i.lonLatToCartesian(e[t]),r=i.lonLatToCartesian(e[t+1]);if(s.distance(r)>1e5)throw new Error("Track is too long! 100 km is maximum.")}let s=new Array(e.length);for(let t=0,i=e.length;t<i;t++)s[t]=this.addPointLonLatAsync(e[t],!0);return Promise.all(s).then((()=>{t||this.events.dispatch(this.events.change,this)})),s}addPointLonLatAsync(e,t=!1){let i=this._planet.ellipsoid.lonLatToCartesian(e),s=this._planet.ellipsoid.getSurfaceNormal3v(i),r=new L(e.lon,e.lat),n=this._planet.ellipsoid.lonLatToCartesian(r),{headEntity:o,groundEntity:a,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(n);return this._groundPointersLayer.add(a),this._columnPointersLayer.add(l),this._headPointersLayer.add(o),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(o.getCartesian()),a.properties.lonLatEll.lon=r.lon,a.properties.lonLatEll.lat=r.lat,a.properties.lonLatEll.height=r.height,new Promise((r=>{this.getHeightELLAsync(e).then((n=>{var l;a.properties.lonLatEll.height=n;let c,d=10;0===e.height?(c=i.add(s.scaleTo(n)),i=c.add(s.scaleTo(d))):(d=e.height-n,c=i.sub(s.scaleTo(d))),a.setCartesian3v(c),h.setCartesian3v(i),h.label.setText(`${n.toFixed(1)} m`),h.childEntities[0].label.setText(`${d.toFixed(1)} m`),o.properties.altitude=d,o.setCartesian3v(i),o.properties.columnEntity.ray.setStartPosition3v(c),o.properties.columnEntity.ray.setEndPosition3v(i),null==(l=this._trackEntity.polyline)||l.setPoint3v(i,o.properties.index),t||(this.events.dispatch(this.events.addpoint,o,this),this.events.dispatch(this.events.change,this)),r(o)}))}))}addGroundPointLonLatAsync(e,t=10,i=!1){let s=this._planet.ellipsoid.lonLatToCartesian(e);return this._addPoint(s,e,t,i)}addGroundPoint3vAsync(e,t=10,i=!1){let s=this._planet.ellipsoid.cartesianToLonLat(e);return this._addPoint(e,s,t,i)}_addPoint(e,t,i,s=!1){return new Promise(((r,n)=>{let{headEntity:o,groundEntity:a,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(e,i);this._groundPointersLayer.add(a),this._columnPointersLayer.add(l),this._headPointersLayer.add(o),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(o.getCartesian()),a.properties.lonLatEll.lon=t.lon,a.properties.lonLatEll.lat=t.lat,a.properties.lonLatEll.height=t.height,this.getHeightELLAsync(t).then((e=>{var n;a.properties.lonLatEll.height=t.height=e;let l=this._planet.ellipsoid.lonLatToCartesian(t),c=this._planet.ellipsoid.getSurfaceNormal3v(l),d=l.add(c.scale(i));h.setCartesian3v(d),h.label.setText(`${e.toFixed(1)} m`),h.childEntities[0].label.setText(`${i.toFixed(1)} m`),o.setCartesian3v(d),o.properties.columnEntity.ray.setEndPosition3v(d),null==(n=this._trackEntity.polyline)||n.setPoint3v(d,o.properties.index),s||(this.events.dispatch(this.events.addpoint,o,this),this.events.dispatch(this.events.change,this)),r(o)}))}))}setHeadPointCartesian3v(e,t){const i=this._headPointersLayer.getEntities()[e];if(i){let s=this._planet.ellipsoid.lonLatToCartesian(i.properties.lonLatEll),r=t.length()-s.length();r<=0&&(t=s,r=0),i.properties.altitude=r,i.setCartesian3v(t),i.properties.columnEntity.ray.setEndPosition3v(t),i.properties.heightLabelEntity.setCartesian3v(t),i.properties.heightLabelEntity.childEntities[0].label.setText(`${r.toFixed(1)} m`),this._trackEntity.polyline.setPoint3v(t,e),this.events.dispatch(this.events.change,this._pickedHeadEntity)}}setGroundPointCartesian3v(e,t){var i;let s=this._groundPointersLayer.getEntities()[e];if(s){let e=this._planet.ellipsoid.cartesianToLonLat(t);s.properties.lonLatEll.lon=e.lon,s.properties.lonLatEll.lat=e.lat,s.properties.lonLatEll.height=e.height;let r=this._planet.ellipsoid.getSurfaceNormal3v(t),n=s.properties.headEntity,o=s.properties.heightLabelEntity,a=s.properties.altitude;s.setCartesian3v(t);let l=t.add(r.scale(a));n.setCartesian3v(l),n.properties.columnEntity.ray.setStartPosition3v(t),n.properties.columnEntity.ray.setEndPosition3v(l),null==(i=this._trackEntity.polyline)||i.setPoint3v(l,n.properties.index),o.setCartesian3v(l),o.label.setText(`${e.height.toFixed(1)} m`),o.childEntities[0].label.setText(`${a.toFixed(1)} m`),this.events.dispatch(this.events.change,s.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 v;const t=this._planet.quadTreeStrategy._renderedNodes,i=this._groundPointersLayer.getEntities();for(let s=0;s<i.length;s++){let r=i[s];for(let i=0;i<t.length;i++){let s=t[i];if(s.segment.isEntityInside(r)){s.segment.getEntityTerrainPoint(r,e),r.setCartesian3v(e),r.properties.columnEntity.ray.setStartPosition3v(e);break}}}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const sh=["change","addpoint"],rh=["reset","list","location"];class nh extends ut{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-buttons"></div>'}),this.events=this.events.registerNames(rh),this.pointListBtn=new dt({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 ce({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 ce({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 oh extends Kt{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 s=e[i];t[i]=new L(s[0],s[1],s[2])}this.model.addPointLonLatArrayAsync(t)}catch(e){console.error(e)}},this.$textarea=null}render(e){super.render(e);let t=new ut({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 ce({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 ah extends ut{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=Ge(e);this.$trackValue.innerText=t[0],this.$trackUnits.innerText=t[1]}setGroundLength(e){let t=Ge(e);this.$groundValue.innerText=t[0],this.$groundUnits.innerText=t[1]}setWarningLength(e){let t=Ge(e);this.$warningValue.innerText=t[0],this.$warningUnits.innerText=t[1]}setCollisionLength(e){let t=Ge(e);this.$collisionValue.innerText=t[0],this.$collisionUnits.innerText=t[1]}}const Xe="rgb(253,77,77)",nn="rgb(248,115,115)",as="rgb(73,73,239)",on="rgb(90,90,253)",ls="rgb(26,122,26)",an="rgb(55,191,55)",Wn="rgba(255,255,255,0.8)",Wi=.1,ya=new v(Wi,Wi,Wi),xa=.17,$n=.0095,lh=$.createCylinder($n,$n,.83).scale(ya),hh=$.createCylinder(0,.04,xa,16,16,!1,!0,0,-.17).scale(ya);class Ks extends G{constructor(e={}){super({independentPicking:!0,yaw:e.yaw||0,pitch:e.pitch||0,roll:e.roll||0,forceGlobalPosition:!0,geoObject:{color:e.color||Xe,scale:1,tag:"line",object3d:lh},properties:e.properties}),this._size=null!=e.size?e.size:1,this.appendChild(new G({yaw:e.yaw||0,pitch:e.pitch||0,roll:e.roll||0,forceGlobalPosition:!0,geoObject:{color:e.color||Xe,scale:1,tag:"tip",object3d:hh},properties:e.properties}))}setSize(e){this._size=e;const t=new v(1,(this._size-xa)/.83,1),i=new v(0,this._size*Wi,0);let s=this.childEntities[0];this.setScale3v(t),s.geoObject.setTranslate3v(i)}setColorHTML(e){let t=this.childEntities[0];this.geoObject.setColorHTML(e),t.geoObject.setColorHTML(e)}}class ch extends G{constructor(e={}){super(e),this._size=null!=e.size?e.size:1,this.childEntities=[],this._init()}_init(){let e=new Ks({color:Xe,yaw:0,pitch:0,roll:90*j,properties:{opName:"move_x",noEdit:!0,style:{color:Xe,selectColor:nn}}}),t=new Ks({color:as,yaw:0,pitch:0,roll:0,properties:{opName:"move_y",noEdit:!0,style:{color:as,selectColor:on}}}),i=new Ks({color:ls,yaw:0,pitch:90*j,roll:0,properties:{opName:"move_z",noEdit:!0,style:{color:ls,selectColor:an}}});this.appendChild(e),this.appendChild(t),this.appendChild(i),this.setSize(this._size)}setSize(e){this.childEntities[0].setSize(e),this.childEntities[1].setSize(e),this.childEntities[2].setSize(e)}setPitch(e){let t=this.childEntities[0],i=t.childEntities[0];t.setPitch(e),i.setPitch(e),t=this.childEntities[1],i=t.childEntities[0],t.setPitch(e),i.setPitch(e),t=this.childEntities[2],i=t.childEntities[0],t.setPitch(e+90),i.setPitch(e+90)}setYaw(e){let t=this.childEntities[0],i=t.childEntities[0];t.setYaw(e),i.setYaw(e),t=this.childEntities[1],i=t.childEntities[0],t.setYaw(e),i.setYaw(e),t=this.childEntities[2],i=t.childEntities[0],t.setYaw(e),i.setYaw(e)}setRoll(e){let t=this.childEntities[0],i=t.childEntities[0];t.setRoll(e+90),i.setRoll(e+90),t=this.childEntities[1],i=t.childEntities[0],t.setRoll(e),i.setRoll(e)}getY(){return this.childEntities[1].getAbsoluteRotation().mulVec3(v.UP).normalize()}}const dh=$.createPlane(1,1,-.5,0,.5);class uh extends G{constructor(e={}){super(e),this._init()}_init(){let e=new G({independentPicking:!0,scale:.025,forceGlobalPosition:!0,geoObject:{color:Wn,tag:"plane",object3d:dh},properties:{opName:"move_xz",noEdit:!0,style:{color:Wn,selectColor:"rgba(255,255,255,1.0)"}}});this.appendChild(e)}}const Li=360,Qs=.95,Xn=new Array(Li),Zn=new Array(Li),Kn=new Array(Li);class _h extends G{constructor(e={}){super(e),this._init()}_init(){const e=Li;let t=new G({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new v))],thickness:3.1,color:Xe,isClosed:!0},properties:{opName:"rotate_pitch",noEdit:!0,style:{color:Xe,selectColor:nn}}}),i=new G({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new v))],thickness:2.5,color:as,isClosed:!0},properties:{opName:"rotate_yaw",noEdit:!0,style:{color:as,selectColor:on}}}),s=new G({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new v))],thickness:2.5,color:ls,isClosed:!0},properties:{opName:"rotate_roll",noEdit:!0,style:{color:ls,selectColor:an}}});this.appendChild(t),this.appendChild(i),this.appendChild(s)}setCartesian3v(e,t=0){if(super.setCartesian3v(e),this._entityCollection&&this._entityCollection.renderNode){let i=this._entityCollection.renderNode,s=i.renderer.activeCamera,r=i.getFrameRotation(e).conjugate(),n=.15*s.eye.distance(e),o=F.xRotation(0),a=F.yRotation(t),l=F.zRotation(0).mul(o).mul(a).mul(i.getFrameRotation(e)).conjugate();for(let t=0,i=0,s=1;t<Li;t+=s,i++){let s=t*j,o=Math.cos(s),a=Math.sin(s),h=l.mulVec3(new v(0,a,o)).normalize().scale(n).add(e),c=r.mulVec3(new v(o,0,a)).normalize().scale(n).add(e),d=l.mulVec3(new v(o,a,0)).normalize().scale(n).add(e);Xn[i]=h,Zn[i]=c,Kn[i]=d}this.childEntities[0].polyline.setPath3v([Xn],void 0,!0),this.childEntities[1].polyline.setPath3v([Zn],void 0,!0),this.childEntities[2].polyline.setPath3v([Kn],void 0,!0);let h=l.mulVec3(new v(1,0,0)).normalize(),c=r.mulVec3(new v(0,1,0)).normalize(),d=l.mulVec3(new v(0,0,1)).normalize();this.childEntities[0].polyline.setVisibleSphere(e,Math.abs(h.dot(s.getForward()))>Qs?0:n),this.childEntities[1].polyline.setVisibleSphere(e,Math.abs(c.dot(s.getForward()))>Qs?0:n),this.childEntities[2].polyline.setVisibleSphere(e,Math.abs(d.dot(s.getForward()))>Qs?0:n)}}}class fh extends G{constructor(e={}){super({...e,forceGlobalPosition:!0}),this._init()}_init(){let e=[],t=[],i=[],s=ve(nn),r=ve(on),n=ve(an);for(let o=0;o<20;o++){let a=1;if(o<5){let e=o/5;a=.5*(1-Math.cos(Math.PI*e))}else if(o>15){let e=(o-15)/5;a=1-.5*(1-Math.cos(Math.PI*e))}t.push([n[0],n[1],n[2],a]),e.push([s[0],s[1],s[2],a]),i.push([r[0],r[1],r[2],a])}let o=new G({polyline:{path3v:[Array.from({length:20},((e,t)=>new v))],thickness:2.5,pathColors:[e],isClosed:!1}}),a=new G({polyline:{path3v:[Array.from({length:20},((e,t)=>new v))],thickness:2.5,pathColors:[i],isClosed:!1}}),l=new G({polyline:{path3v:[Array.from({length:20},((e,t)=>new v))],thickness:2.5,pathColors:[t],isClosed:!1}});this.appendChild(o),this.appendChild(a),this.appendChild(l)}setCartesian3v(e){if(super.setCartesian3v(e),this._entityCollection&&this._entityCollection.renderNode){let t=this._entityCollection.renderNode,i=.05*t.renderer.activeCamera.eye.distance(e);if(t.planet){let s=[],r=[],n=[],o=t.planet.ellipsoid.getSurfaceNormal3v(e),a=this._lonLat,l=10;for(let t=-10;t<l;t++)n.push(new L(a.lon,a.lat+t,a.height)),r.push(new L(a.lon+t,a.lat,a.height)),s.push(e.add(o.scaleTo(t*i)));this.childEntities[0].polyline.setPathLonLatFast([r]),this.childEntities[1].polyline.setPath3vFast([s]),this.childEntities[2].polyline.setPathLonLatFast([n])}else{let t=[],s=[],r=[],n=v.UNIT_Y,o=v.UNIT_X,a=v.UNIT_Z,l=10;for(let h=-10;h<l;h++)s.push(e.add(o.scaleTo(h*i))),r.push(e.add(n.scaleTo(h*i))),t.push(e.add(a.scaleTo(h*i)));this.childEntities[0].polyline.setPath3vFast([s]),this.childEntities[1].polyline.setPath3vFast([r]),this.childEntities[2].polyline.setPath3vFast([t])}}}}function Qn(e,t,i,s,r,n){let o=r.add(v.UP),a=r.add(e),l=new v;if(new V(t,i).hitPlaneRes(vt.fromPoints(r,o,a),l)===V.INSIDE){let i=v.proj_b_to_a(l,e);if(new V(t,s).hitPlaneRes(vt.fromPoints(r,o,a),l)===V.INSIDE){let t=v.proj_b_to_a(l,e).sub(i);n.copy(r.add(t))}}}class gh extends de{constructor(e={}){super(e.name||"GeoObjectEditorScene"),this._onAxisLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onAxisLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.setColorHTML(e.pickingObject.properties.style.color)},this._onAxisLayerLUp=e=>{this._selectedMove=null,this._navActivate(),this._setAxisTrackVisibility(!1)},this._onAxisLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._setAxisTrackVisibility(!0)),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onPlaneLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.geoObject.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onPlaneLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.geoObject.setColorHTML(e.pickingObject.properties.style.color)},this._onPlaneLayerLUp=e=>{this._selectedMove=null,this._navActivate(),this._setAxisTrackVisibility(!1)},this._onPlaneLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._setAxisTrackVisibility(!0)),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onRotateLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.polyline.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onRotateLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.polyline.setColorHTML(e.pickingObject.properties.style.color)},this._onRotateLayerLUp=e=>{this._selectedMove=null,this._navActivate()},this._onRotateLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._selectedEntity&&(this._selectedEntityPitch=this._selectedEntity.getAbsolutePitch(),this._selectedEntityYaw=this._selectedEntity.getAbsoluteYaw(),this._selectedEntityRoll=this._selectedEntity.getAbsoluteRoll())),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onMouseMove=e=>{this._selectedEntity&&this._selectedMove&&this._ops[this._selectedMove]&&this._ops[this._selectedMove](e)},this._onLclick=e=>{e.pickingObject&&e.pickingObject instanceof G&&this.select(e.pickingObject)},this._moveX=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),r=new v;if(this.planet){let n=new V(t.eye,s).hitSphere(new Ft(i.length(),new v)),o=new V(t.eye,e.direction).hitSphere(new Ft(i.length(),new v));if(!o)return;if(r=F.getRotationBetweenVectors(n.normal(),o.normal()).mulVec3(i),this.ellipsoid){let e=this.ellipsoid.cartesianToLonLat(i),t=this.ellipsoid.cartesianToLonLat(r);this.ellipsoid.lonLatToCartesianRes(new L(t.lon,e.lat,e.height),r)}}else Qn(v.UNIT_X,t.eye,s,e.direction,i,r);this._selectedEntity.setAbsoluteCartesian3v(r),this.events.dispatch(this.events.position,r,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveY=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=v.UP;this.planet&&(s=this._axisEntity.getY());let r=i.add(s),n=i.add(t.getRight()),o=new v,a=t.unproject(this._clickPos.x,this._clickPos.y);if(new V(t.eye,a).hitPlaneRes(vt.fromPoints(i,r,n),o)===V.INSIDE){let a=v.proj_b_to_a(o,s);if(new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,r,n),o)===V.INSIDE){let e=v.proj_b_to_a(o,s).sub(a),t=this._selectedEntityCart.add(e);this._selectedEntity.setAbsoluteCartesian3v(t),this.events.dispatch(this.events.position,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}}},this._moveZ=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),r=new v;if(this.planet){let n=new V(t.eye,s).hitSphere(new Ft(i.length(),new v)),o=new V(t.eye,e.direction).hitSphere(new Ft(i.length(),new v));if(!o)return;if(r=F.getRotationBetweenVectors(n.normal(),o.normal()).mulVec3(i),this.ellipsoid){let e=this.ellipsoid.cartesianToLonLat(i),t=this.ellipsoid.cartesianToLonLat(r);this.ellipsoid.lonLatToCartesianRes(new L(e.lon,t.lat,e.height),r)}}else Qn(v.UNIT_Z,t.eye,s,e.direction,i,r);this._selectedEntity.setAbsoluteCartesian3v(r),this.events.dispatch(this.events.position,r,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveXZ=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),r=new v;if(this.planet){let n=new V(t.eye,s).hitSphere(new Ft(i.length(),new v)),o=new V(t.eye,e.direction).hitSphere(new Ft(i.length(),new v));if(!o)return;if(r=F.getRotationBetweenVectors(n.normal(),o.normal()).mulVec3(i),this.ellipsoid){let e=this.ellipsoid.cartesianToLonLat(r),t=this._selectedEntity.getLonLat().height;this.ellipsoid.lonLatToCartesianRes(new L(e.lon,e.lat,t),r)}}else{let n=i.add(v.UNIT_X),o=i.add(v.UNIT_Z),a=new v,l=new v;if(new V(t.eye,s).hitPlaneRes(vt.fromPoints(i,n,o),a)===V.INSIDE&&new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,n,o),l)===V.INSIDE){let e=l.sub(a);r=i.add(e)}}this._selectedEntity.setAbsoluteCartesian3v(r),this.events.dispatch(this.events.position,r,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveXY=e=>{console.log("moveXY")},this._moveZY=e=>{console.log("moveZY")},this._rotatePitch=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=F.xRotation(0),r=F.yRotation(this._selectedEntity.getYaw()),n=F.zRotation(0).mul(s).mul(r).mul(this.getFrameRotation(i)).conjugate().mulVec3(new v(1,0,0)).normalize(),o=t.unproject(this._clickPos.x,this._clickPos.y),a=new vt(i,n),l=new v,h=new v;if(new V(t.eye,o).hitPlaneRes(a,l)===V.INSIDE&&new V(t.eye,e.direction).hitPlaneRes(a,h)===V.INSIDE){let e=l.sub(i).normalize(),t=h.sub(i).normalize(),s=Math.sign(e.cross(t).dot(n)),r=Math.acos(e.dot(t)),o=this._selectedEntityPitch+s*r;this._selectedEntity.setAbsolutePitch(o),this.events.dispatch(this.events.pitch,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._rotateYaw=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=this.getFrameRotation(i).conjugate().mulVec3(new v(0,1,0)).normalize(),r=t.unproject(this._clickPos.x,this._clickPos.y),n=new vt(i,s),o=new v,a=new v;if(new V(t.eye,r).hitPlaneRes(n,o)===V.INSIDE&&new V(t.eye,e.direction).hitPlaneRes(n,a)===V.INSIDE){let e=o.sub(i).normalize(),t=a.sub(i).normalize(),r=Math.sign(t.cross(e).dot(s)),n=Math.acos(e.dot(t)),l=this._selectedEntityYaw+r*n;this._selectedEntity.setAbsoluteYaw(l),this.events.dispatch(this.events.yaw,l,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._rotateRoll=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart;this.getFrameRotation(i).conjugate();let s=F.xRotation(0),r=F.yRotation(this._selectedEntity.getYaw()),n=F.zRotation(0).mul(s).mul(r).mul(this.getFrameRotation(i)).conjugate().mulVec3(new v(0,0,1)).normalize(),o=t.unproject(this._clickPos.x,this._clickPos.y),a=new vt(i,n),l=new v,h=new v;if(new V(t.eye,o).hitPlaneRes(a,l)===V.INSIDE&&new V(t.eye,e.direction).hitPlaneRes(a,h)===V.INSIDE){let e=l.sub(i).normalize(),t=h.sub(i).normalize(),s=Math.sign(e.cross(t).dot(n)),r=Math.acos(e.dot(t)),o=this._selectedEntityRoll+s*r;this._selectedEntity.setAbsoluteRoll(o),this.events.dispatch(this.events.roll,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._scale=e=>{this.events.dispatch(this.events.scale,1,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._scaleX=e=>{},this._scaleY=e=>{},this._scaleZ=e=>{},this.events=lt(ph),this._planet=e.planet||null,this._startPos=null,this._startClick=new H,this._axisEntity=new ch,this._planeEntity=new uh,this._rotateEntity=new _h,this._axisTrackEntity=new fh,this._moveLayer=new se({scaleByDistance:[.1,Ae,.1],useLighting:!1,pickingScale:[5,1.1,5],visibility:!1,depthOrder:1e3}),this._planeLayer=new se({scaleByDistance:[.1,Ae,.1],useLighting:!1,visibility:!1,depthOrder:1e3}),this._rotateLayer=new se({useLighting:!1,visibility:!1,depthOrder:1e3,pickingScale:5}),this._selectedEntity=null,this._clickPos=new H,this._selectedEntityCart=new v,this._selectedEntityPitch=0,this._selectedEntityYaw=0,this._selectedEntityRoll=0,this._selectedMove=null,this._axisTrackVisibility=!1,this._axisTrackLayer=new se({useLighting:!1,visibility:!1,pickingScale:5,pickingEnabled:!1,opacity:.6}),this._ops={move_x:this._moveX,move_y:this._moveY,move_z:this._moveZ,move_xz:this._moveXZ,move_xy:this._moveXY,move_zy:this._moveZY,rotate_pitch:this._rotatePitch,rotate_yaw:this._rotateYaw,rotate_roll:this._rotateRoll,scale:this._scale,scale_x:this._scaleX,scale_y:this._scaleY,scale_z:this._scaleZ}}get ellipsoid(){if(this._planet)return this._planet.ellipsoid}get planet(){return this._planet}bindPlanet(e){this._planet=e}init(){this.activate()}onremove(){this.deactivate()}_addAxisLayers(){this._moveLayer.addTo(this),this._planeLayer.addTo(this),this._rotateLayer.addTo(this),this._axisTrackLayer.addTo(this),this._moveLayer.add(this._axisEntity),this._moveLayer.events.on("mouseenter",this._onAxisLayerMouseEnter),this._moveLayer.events.on("mouseleave",this._onAxisLayerMouseLeave),this._moveLayer.events.on("lup",this._onAxisLayerLUp),this._moveLayer.events.on("ldown",this._onAxisLayerLDown),this._planeLayer.add(this._planeEntity),this._planeLayer.events.on("mouseenter",this._onPlaneLayerMouseEnter),this._planeLayer.events.on("mouseleave",this._onPlaneLayerMouseLeave),this._planeLayer.events.on("lup",this._onPlaneLayerLUp),this._planeLayer.events.on("ldown",this._onPlaneLayerLDown),this._rotateLayer.add(this._rotateEntity),this._rotateLayer.events.on("mouseenter",this._onRotateLayerMouseEnter),this._rotateLayer.events.on("mouseleave",this._onRotateLayerMouseLeave),this._rotateLayer.events.on("lup",this._onRotateLayerLUp),this._rotateLayer.events.on("ldown",this._onRotateLayerLDown),this._axisTrackLayer.add(this._axisTrackEntity)}_navActivate(){this.renderer&&(this.renderer.controls.navigation&&this.renderer.controls.navigation.activate(),this.renderer.controls.SimpleNavigation&&this.renderer.controls.SimpleNavigation.activate())}_navDeactivate(){this.renderer&&(this.renderer.controls.navigation&&this.renderer.controls.navigation.deactivate(),this.renderer.controls.SimpleNavigation&&this.renderer.controls.SimpleNavigation.deactivate())}_removeAxisLayers(){this._moveLayer.remove(),this._planeLayer.remove(),this._rotateLayer.remove()}activate(){this.renderer.events.on("lclick",this._onLclick),this.renderer.events.on("mousemove",this._onMouseMove),this._addAxisLayers()}deactivate(){this.renderer.events.off("lclick",this._onLclick),this.renderer.events.off("mousemove",this._onMouseMove),this._removeAxisLayers(),this.clear()}_setAxisTrackVisibility(e){e!==this._axisTrackVisibility&&(this._axisTrackVisibility=e,this._axisTrackLayer.setVisibility(e))}setVisibility(e){this._moveLayer.setVisibility(e),this._planeLayer.setVisibility(e),this._rotateLayer.setVisibility(e),this.unlockView()}readyToEdit(e){return!e.properties||!e.properties.noEdit}select(e){(!this._selectedEntity||this._selectedEntity&&!e.isEqual(this._selectedEntity))&&this.readyToEdit(e)&&(this._selectedEntity&&this.unselect(),this._selectedEntity=e,this.renderer&&this.renderer.setRelativeCenter(),this.setVisibility(!0),this.events.dispatch(this.events.select,this._selectedEntity))}unselect(){this.setVisibility(!1);let e=this._selectedEntity;this._selectedEntity=null,this.events.dispatch(this.events.unselect,e)}clear(){this.removeEntityCollection(this._moveLayer),this.removeEntityCollection(this._planeLayer),this.removeEntityCollection(this._rotateLayer)}frame(){if(this._selectedEntity){let e=this._selectedEntity.getAbsoluteCartesian();this._axisEntity.setCartesian3v(e),this._planeEntity.setCartesian3v(e),this._rotateEntity.setCartesian3v(e,this._selectedEntity.getAbsoluteYaw()),this._axisTrackEntity.setCartesian3v(e)}}getFrameRotation(e){return this._planet?this._planet.getFrameRotation(e):super.getFrameRotation(e)}getSelectedEntity(){return this._selectedEntity}lockView(){this.renderer&&this._selectedEntity&&this.renderer.controls.CameraLock.lockView(this._selectedEntity)}unlockView(){if(this.renderer&&this._selectedEntity){let e=this.renderer.controls.CameraLock;e&&e.unlockView()}}}const ph=["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","select","unselect","change","position","pitch","yaw","roll","scale"],mh=["change"];class yt extends ut{constructor(e={}){super({template:Dt('<div class="og-input">\n <div class="og-input-label">{label}</div>\n <input type="{type}"/>\n </div>',{label:e.label||"",type:e.type||"text"})}),this._onResize=()=>{},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation()},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onInput=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this._setValue(e.target.value)},this.events=this.events.registerNames(mh),this._value=e.value||"",this._maxFixed=null!=e.maxFixed?e.maxFixed:-1,this.$label=null,this.$input=null}render(e){return super.render(e),this.$label=this.select(".og-input-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="number"==typeof e?_r(e,this._maxFixed):e,this.$input&&(this.$input.value=this._value),this.events.dispatch(this.events.change,this._value,this))}_setValue(e){e!==this._value&&(this._value="number"==typeof e?_r(e,this._maxFixed):e,this.events.dispatch(this.events.change,this._value,this))}get value(){return this._value}_initEvents(){this.el.addEventListener("mousewheel",this._onMouseWheel),this.el.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.el.removeEventListener("mousewheel",this._onMouseWheel),this.el.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("input",this._onInput)}remove(){this._clearEvents(),super.remove()}set visibility(e){this.el&&(this.el.style.display=e?"":"none")}}const vh=["change"];class yh extends ut{constructor(e={}){super({template:Dt('<div class="og-checkbox">\n <div class="og-input-label">{label}</div>\n <div class="og-checkbox-input">\n <input type="checkbox" {checked}/>\n </div>\n </div>',{label:e.label||"",checked:e.checked?"checked":""})}),this._onResize=()=>{},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation()},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onClick=e=>{(e=e||window.event).stopPropagation(),this.checked=!this._checked},this._checked=e.checked||!1,this._disabled=e.disabled||!1,this.events=this.events.registerNames(vh),this.$label=null,this.$input=null}set disabled(e){this._disabled=e,this._updateDisabled()}_updateDisabled(){this.el&&(this._disabled?this.el.classList.add("og-input-disabled"):this.el.classList.remove("og-input-disabled"))}get disabled(){return this._disabled}render(e){return super.render(e),this.$label=this.select(".og-input-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this.$input.checked=this._checked,this._updateDisabled(),this._initEvents(),this}set checked(e){e!==this._checked&&(this._checked=e,this.$input&&(this.$input.checked=this._checked),this.events.dispatch(this.events.change,this._checked,this))}get checked(){return this._checked}_initEvents(){this.el.addEventListener("mousewheel",this._onMouseWheel),this.el.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("click",this._onClick)}_clearEvents(){this.el.removeEventListener("mousewheel",this._onMouseWheel),this.el.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("click",this._onClick)}remove(){this._clearEvents(),super.remove()}set visibility(e){this.el&&(this.el.style.display=e?"":"none")}}class xh extends Kt{constructor(e){super({title:"GeoObject Properties",visible:!1,resizable:!0,useHide:!0,top:25,right:85,width:252,height:480,minHeight:100,minWidth:100,model:e.model}),this._onVisibility=e=>{this.model.setVisibility(e)},this._onSelect=e=>{this.show(),this._refresh(e)},this._onUnselect=e=>{this.hide()},this._onChangeRelativePosition=e=>{let t=this.model.getSelectedEntity();t&&(t.relativePosition=e,this._refresh(t))},this._onPosition=(e,t)=>{this._refresh(t)},this._onPitch=(e,t)=>{this._pitchView.stopPropagation(),this._pitchView.value=t.getPitch()*J,this._absolutePitchView.stopPropagation(),this._absolutePitchView.value=t.getAbsolutePitch()*J},this._onYaw=(e,t)=>{this._yawView.stopPropagation(),this._yawView.value=t.getYaw()*J,this._absoluteYawView.stopPropagation(),this._absoluteYawView.value=t.getAbsoluteYaw()*J},this._onRoll=(e,t)=>{this._rollView.stopPropagation(),this._rollView.value=t.getRoll()*J,this._absoluteRollView.stopPropagation(),this._absoluteRollView.value=t.getAbsoluteRoll()*J},this._onChangeLon=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(parseFloat(e),i.lat,i.height),this._refresh(t)}},this._onChangeLat=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(i.lon,parseFloat(e),i.height),this._refresh(t)}},this._onChangeHeight=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(i.lon,i.lat,parseFloat(e)),this._refresh(t)}},this._onChangeX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(parseFloat(e),i.y,i.z),this._refresh(t)}},this._onChangeY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(i.x,parseFloat(e),i.z),this._refresh(t)}},this._onChangeZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(i.x,i.y,parseFloat(e)),this._refresh(t)}},this._onChangeAbsoluteX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(parseFloat(e),i.y,i.z),this._refresh(t)}},this._onChangeAbsoluteY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(i.x,parseFloat(e),i.z),this._refresh(t)}},this._onChangeAbsoluteZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(i.x,i.y,parseFloat(e)),this._refresh(t)}},this._onChangePitch=e=>{let t=this.model.getSelectedEntity();t&&(t.setPitch(parseFloat(e)*j),this._refresh(t))},this._onChangeYaw=e=>{let t=this.model.getSelectedEntity();t&&(t.setYaw(parseFloat(e)*j),this._refresh(t))},this._onChangeRoll=e=>{let t=this.model.getSelectedEntity();t&&(t.setRoll(parseFloat(e)*j),this._refresh(t))},this._onChangeAbsolutePitch=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsolutePitch(parseFloat(e)*j),this._refresh(t))},this._onChangeAbsoluteYaw=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsoluteYaw(parseFloat(e)*j),this._refresh(t))},this._onChangeAbsoluteRoll=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsoluteRoll(parseFloat(e)*j),this._refresh(t))},this._onChangeScale=e=>{let t=this.model.getSelectedEntity();if(t){let i=parseFloat(e);t.setScale(i),this._scaleXView.stopPropagation(),this._scaleYView.stopPropagation(),this._scaleZView.stopPropagation(),this._scaleXView.value=i,this._scaleYView.value=i,this._scaleZView.value=i}},this._onChangeScaleX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new v(parseFloat(e),i.y,i.z))}},this._onChangeScaleY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new v(i.x,parseFloat(e),i.z))}},this._onChangeScaleZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new v(i.x,i.y,parseFloat(e)))}},this._onGround=()=>{let e=this.model.getSelectedEntity();e&&this.model.planet&&(this.model.planet.terrain?this.model.planet.terrain.getHeightAsync(e.getLonLat(),(e=>{this._heightView.value=e})):this._heightView.value=0)},this._relativePositionView=new yh({label:"Relative position"}),this._lonView=new yt({label:"Lon",type:"number",min:-180,max:180,maxFixed:10}),this._latView=new yt({label:"Lat",type:"number",min:-90,max:90,maxFixed:10}),this._heightView=new yt({label:"Height",type:"number",maxFixed:4}),this._xView=new yt({label:"X",type:"number",maxFixed:10}),this._yView=new yt({label:"Y",type:"number"}),this._zView=new yt({label:"Z",type:"number"}),this._absXView=new yt({label:"Absolute X",type:"number",maxFixed:10}),this._absYView=new yt({label:"Absolute Y",type:"number"}),this._absZView=new yt({label:"Absolute Z",type:"number"}),this._pitchView=new yt({label:"Pitch",type:"number",maxFixed:2}),this._yawView=new yt({label:"Yaw",type:"number",maxFixed:2}),this._rollView=new yt({label:"Roll",type:"number",maxFixed:2}),this._absolutePitchView=new yt({label:"Absolute pitch",type:"number",maxFixed:2}),this._absoluteYawView=new yt({label:"Absolute yaw",type:"number",maxFixed:2}),this._absoluteRollView=new yt({label:"Absolute roll",type:"number",maxFixed:2}),this._scaleView=new yt({label:"Scale",type:"number",maxFixed:2}),this._scaleXView=new yt({label:"Scale X",type:"number",maxFixed:2}),this._scaleYView=new yt({label:"Scale Y",type:"number",maxFixed:2}),this._scaleZView=new yt({label:"Scale Z",type:"number",maxFixed:2}),this._groundBtn=new ce({text:"Ground",title:"Put on the ground",name:"ground",classList:["og-editor-ground_button"]})}render(e){var t;super.render(e),this._initSceneEvents();let i=document.createElement("div");i.classList.add("og-editor_toolbar"),null==(t=this.container)||t.appendChild(i);let s=new dt({classList:["og-editor_toolbar-button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" id="filter-center-focus">\n <path d="M5 15H3v4c0 1.1.9 2 2 2h4v-2H5v-4zM5 5h4V3H5c-1.1 0-2 .9-2 2v4h2V5zm14-2h-4v2h4v4h2V5c0-1.1-.9-2-2-2zm0 16h-4v2h4c1.1 0 2-.9 2-2v-4h-2v4zM12 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>\n</svg>',title:"Lock/Unlock camera view"});return s.appendTo(i),s.events.on("change",(e=>{e?this.model.lockView():this.model.unlockView()})),this.events.on("visibility",(e=>{e||(s.events.stopPropagation(),s.setActive(!1))})),this.events.on("visibility",this._onVisibility),this._relativePositionView.appendTo(this.container),this.model.planet&&(this._lonView.appendTo(this.container),this._latView.appendTo(this.container),this._heightView.appendTo(this.container)),this._xView.appendTo(this.container),this._yView.appendTo(this.container),this._zView.appendTo(this.container),this._absXView.appendTo(this.container),this._absYView.appendTo(this.container),this._absZView.appendTo(this.container),this._pitchView.appendTo(this.container),this._yawView.appendTo(this.container),this._rollView.appendTo(this.container),this._absolutePitchView.appendTo(this.container),this._absoluteYawView.appendTo(this.container),this._absoluteRollView.appendTo(this.container),this._scaleView.appendTo(this.container),this._scaleXView.appendTo(this.container),this._scaleYView.appendTo(this.container),this._scaleZView.appendTo(this.container),this.model.planet&&this._groundBtn.appendTo(this.container),this._relativePositionView.events.on("change",this._onChangeRelativePosition),this._lonView.events.on("change",this._onChangeLon),this._latView.events.on("change",this._onChangeLat),this._heightView.events.on("change",this._onChangeHeight),this._xView.events.on("change",this._onChangeX),this._yView.events.on("change",this._onChangeY),this._zView.events.on("change",this._onChangeZ),this._absXView.events.on("change",this._onChangeAbsoluteX),this._absYView.events.on("change",this._onChangeAbsoluteY),this._absZView.events.on("change",this._onChangeAbsoluteZ),this._pitchView.events.on("change",this._onChangePitch),this._yawView.events.on("change",this._onChangeYaw),this._rollView.events.on("change",this._onChangeRoll),this._absolutePitchView.events.on("change",this._onChangeAbsolutePitch),this._absoluteYawView.events.on("change",this._onChangeAbsoluteYaw),this._absoluteRollView.events.on("change",this._onChangeAbsoluteRoll),this._scaleView.events.on("change",this._onChangeScale),this._scaleXView.events.on("change",this._onChangeScaleX),this._scaleYView.events.on("change",this._onChangeScaleY),this._scaleZView.events.on("change",this._onChangeScaleZ),this._groundBtn.appendTo(this.container),this._groundBtn.events.on("click",this._onGround),this}remove(){super.remove(),this._clearSceneEvents()}_initSceneEvents(){this.model.events.on("select",this._onSelect),this.model.events.on("unselect",this._onUnselect),this.model.events.on("position",this._onPosition),this.model.events.on("pitch",this._onPitch),this.model.events.on("yaw",this._onYaw),this.model.events.on("roll",this._onRoll)}_clearSceneEvents(){this.model.events.off("select",this._onSelect),this.model.events.off("unselect",this._onUnselect),this.model.events.off("position",this._onPosition),this.model.events.off("pitch",this._onPitch),this.model.events.off("yaw",this._onYaw),this.model.events.off("roll",this._onRoll)}_refresh(e){e.parent?this._relativePositionView.disabled=!1:this._relativePositionView.disabled=!0,this._relativePositionView.checked=e.relativePosition;let t=e.getLonLat();this._lonView.stopPropagation(),this._latView.stopPropagation(),this._heightView.stopPropagation(),this._lonView.value=t.lon,this._latView.value=t.lat,this._heightView.value=t.height;let i=e.getCartesian();this._xView.stopPropagation(),this._yView.stopPropagation(),this._zView.stopPropagation(),this._xView.value=i.x,this._yView.value=i.y,this._zView.value=i.z,i=e.getAbsoluteCartesian(),this._absXView.stopPropagation(),this._absYView.stopPropagation(),this._absZView.stopPropagation(),this._absXView.value=i.x,this._absYView.value=i.y,this._absZView.value=i.z,this._pitchView.stopPropagation(),this._yawView.stopPropagation(),this._rollView.stopPropagation(),this._pitchView.value=e.getPitch()*J,this._yawView.value=e.getYaw()*J,this._rollView.value=e.getRoll()*J,this._absolutePitchView.stopPropagation(),this._absoluteYawView.stopPropagation(),this._absoluteRollView.stopPropagation(),this._absolutePitchView.value=e.getAbsolutePitch()*J,this._absoluteYawView.value=e.getAbsoluteYaw()*J,this._absoluteRollView.value=e.getAbsoluteRoll()*J,this._scaleView.stopPropagation();let s=e.getScale();s.x===s.y&&s.y===s.z?this._scaleView.value=s.x:this._scaleView.value=1,this._scaleXView.stopPropagation(),this._scaleYView.stopPropagation(),this._scaleZView.stopPropagation(),this._scaleXView.value=s.x,this._scaleYView.value=s.y,this._scaleZView.value=s.z}hide(){super.hide(),this.model.events.stopPropagation(),this.model.unselect()}}const bh=["lockview","unlockview"];class Jn extends Q{constructor(e={}){super(e),this._onLockViewDraw=()=>{this.renderer&&this._lockEntity&&(this._isFromTheBack||this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(),this._lockDistance))},this._onMouseWheel=e=>{if(this.renderer&&this._lockEntity&&!this._isFromTheBack){let t=this.renderer.activeCamera.eye.distance(this._lockEntity.getAbsoluteCartesian());this._lockDistance-=.33*t*Math.sign(e.wheelDelta),this._lockDistance<.001&&(this._lockDistance=.001),this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(),this._lockDistance)}},this._onMouseMove=e=>{if(this._lockEntity&&this.renderer&&(e.rightButtonDown||this.renderer.events.isKeyPressed(W.KEY_ALT))){let t=this._lockEntity.getAbsoluteCartesian(),i=this.renderer.activeCamera,s=.5/j;s>.007&&(s=.007),this.planet?i.rotateHorizontal(s*(e.x-e.prev_x),!1,t,t.isZero()?v.UP:t.normal()):i.rotateHorizontal(s*(e.x-e.prev_x),!1,t,v.UP),i.rotateVertical(s*(e.y-e.prev_y),t),this._viewDir=t.sub(i.eye).normalize()}},this.events=lt(bh),this._name="CameraLock",this.planet=e.planet||null,this._lockDistance=0,this._isFromTheBack=!1,this._lockEntity=null,this._viewDir=new v(0,0,0)}onactivate(){this.renderer}ondeactivate(){this.renderer&&this.unlockView()}oninit(){this.activate(),this.renderer}flyCartesian(e,t=120){if(!e.isZero()&&this.renderer)if(this.unlockView(),this.planet){let i=this.planet.camera;this.isVisibleDistance(e)&&i.flyDistance(e,t),i.eye.distance(e)<1e6?i.flyDistance(e,t):i.viewDistance(e,t)}else this.renderer.activeCamera.viewDistance(e,t)}lockView(e,t=!1){if(!this.renderer)return;this._lockDistance=this._getDistance(e,this._lockEntity),this._isFromTheBack=t,this._deactivateLockViewEvents(),this._lockEntity=e;let i=this.renderer.activeCamera;this.planet&&this.planet.camera.stopFlying(),i.viewDistance(e.getAbsoluteCartesian(),this._lockDistance),this._deactivateNav(),this._activateLockViewEvents(),this._viewDir=e.getAbsoluteCartesian().sub(i.eye).normalize(),this.events.dispatch(this.events.lockview,this._lockEntity,t)}_activateNav(){this.renderer&&this.renderer.controls.navigation&&this.renderer.controls.navigation.activate(),this.renderer&&this.renderer.controls.simpleNavigation&&this.renderer.controls.simpleNavigation.activate()}_deactivateNav(){this.renderer&&this.renderer.controls.navigation&&(this.renderer.controls.navigation.deactivate(),this.renderer.controls.navigation.stop()),this.renderer&&this.renderer.controls.simpleNavigation&&this.renderer.controls.simpleNavigation.deactivate()}unlockView(){this._lockEntity&&(this._deactivateLockViewEvents(),this._activateNav(),this.events.dispatch(this.events.unlockview,this._lockEntity),this._lockEntity=null)}_getCenterDist(){return this.renderer&&this.renderer.getDistanceFromPixel(this.renderer.handler.getCenter())||0}_getDistance(e,t){if(this.renderer){let i=e.getAbsoluteCartesian(),s=this.renderer.activeCamera,r=s.eye.distance(i);return t&&(r=s.eye.distance(t.getAbsoluteCartesian())),this.isVisibleDistance(i)?r:s.eye.distance(i)<1e6?this._getCenterDist():120}return 0}isVisibleDistance(e,t=0){if(this.planet){let i=this.planet.ellipsoid.equatorialSize,s=this.planet.camera.eye;return s.distance(e)<Math.sqrt(s.length2()-i*i)+t}return!0}get lockEntity(){return this._lockEntity}flyLonLat(e,t=120){if(this.planet){let i=this.planet.ellipsoid.lonLatToCartesian(e);this.flyCartesian(i,t)}}_activateLockViewEvents(){this.renderer&&(this.renderer.events.on("mousewheel",this._onMouseWheel),this.renderer.events.on("mousemove",this._onMouseMove),this.renderer.events.on("draw",this._onLockViewDraw))}_deactivateLockViewEvents(){this.renderer&&(this.renderer.events.off("mousewheel",this._onMouseWheel),this.renderer.events.off("mousemove",this._onMouseMove),this._lockEntity&&this.renderer.events.off("draw",this._onLockViewDraw))}}const wh=["click"];class Th extends ut{constructor(e){super({template:Dt('<button class="og-object3d-collection__item">\n <div class="og-object3d-collection__item_name">{name}</div>\n </button>',{name:e.model.name}),...e}),this.events=lt(wh)}render(e){var t;return super.render(e),null==(t=this.el)||t.addEventListener("click",(e=>{this.events.dispatch(this.events.click,this.model,this,e)})),this}}const Ch=["select"];class Eh extends ut{constructor(e){super({template:'<div class="og-object3d-collection"></div>',model:e.model,...e}),this._onAdd=e=>{this._addItem(e)},this.events=lt(Ch),this._activeView=null}_addItem(e){let t=new Th({model:e});t.appendTo(this.el),t.events.on("click",(e=>{var i,s;this._activeView&&(null==(i=this._activeView.el)||i.classList.remove("active")),this._activeView=t,null==(s=this._activeView.el)||s.classList.add("active"),this.events.dispatch(this.events.select,e,t)}))}render(e){super.render(e);let t=this.model.getItems();for(let e of t)this._addItem(e);return this._initEvents(),this}_initEvents(){this.model.events.on("add",this._onAdd)}}const Ah=["select"];class Lh extends Kt{constructor(e){super({classList:["og-object3d-manager"],title:"Object3D Collection",visible:!1,resizable:!0,useHide:!0,top:25,right:85,width:252,height:480,minHeight:100,minWidth:100}),this._onLoadClick=()=>{let e=new ut({initRender:!0,template:'<input type="file" accept=".obj,.mtl" multiple />'});e.el&&(e.el.addEventListener("change",(e=>{const t=e.target;if(t.files){const e=Array.from(t.files),i=e.find((e=>e.name.toLowerCase().endsWith(".obj"))),s=e.find((e=>e.name.toLowerCase().endsWith(".mtl")));i&&async function(e,t){return await $.readFileObj(e,t).then((i=>({name:e.name,objects:t?i:[$.merge(i)]})))}(i,s).then(this._addObject)}})),e.el.click())},this._addObject=e=>{this._object3dCollectionView.model.addItem(e)},this.events=lt(Ah),this._object3dCollectionView=new Eh({model:e.model})}render(e){var t;super.render(e);let i=document.createElement("div");i.classList.add("og-editor_toolbar"),null==(t=this.container)||t.appendChild(i);let s=new ce({classList:["og-editor_toolbar-button"],icon:'<svg class="svg-icon" style="vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M426.666667 170.666667H170.666667c-47.146667 0-84.906667 38.186667-84.906667 85.333333L85.333333 768c0 47.146667 38.186667 85.333333 85.333334 85.333333h682.666666c47.146667 0 85.333333-38.186667 85.333334-85.333333V341.333333c0-47.146667-38.186667-85.333333-85.333334-85.333333H512l-85.333333-85.333333z" /></svg>',title:"Load 3D object"});return s.appendTo(i),s.events.on("click",this._onLoadClick),this._object3dCollectionView.appendTo(this.container),this._object3dCollectionView.events.on("select",(e=>{this.events.dispatch(this.events.select,e)})),this}}const Ph=["add","remove"];class ln{constructor(e={}){this.events=lt(Ph,this),this._items=ln.createItemsMap(e.collection||[])}static createItemsMap(e){let t=new Map;for(let i=0;i<e.length;i++)t.set(e[i].name,e[i]);return t}getItem(e){return this._items.get(e)}addItem(e,t=!1){this._items.has(e.name)&&!t||(this._items.set(e.name,e),this.events.dispatch(this.events.add,e))}getItems(){return Array.from(this._items,(([e,t])=>t))}}class Fr extends Q{constructor(e={}){super({name:"CameraFrameComposer",autoActivate:!0,...e}),this._onPostdraw=()=>{for(let e=0,t=this._frameHandlers.length;e<t;e++)this._frameHandlers[e].frame()},this._cameraLayer=new se({scaleByDistance:[100,1e6,1],pickingEnabled:!1}),this._cameraScene=new de("CameraScene"),this._frameHandlers=e.frameHandlers||[]}get frameHandlers(){return[...this._frameHandlers]}add(e){e.addTo(this),this._cameraLayer.add(e.cameraEntity)}oninit(){super.oninit(),this._cameraLayer.addTo(this._cameraScene)}activate(){super.activate(),this.renderer&&(this.renderer.events.on("postdraw",this._onPostdraw),this.renderer.addNode(this._cameraScene))}deactivate(){super.deactivate(),this.renderer&&(this.renderer.events.off("postdraw",this._onPostdraw),this.renderer.removeNode(this._cameraScene))}}let Sh=$.createFrustum();class to{constructor(e){this.camera=e.camera,this.frameBuffer=e.frameBuffer,this.frameHandler=e.frameHandler||null,this._composer=null,this._composerIndex=-1,this.showFrustum=null==e.showFrustum||e.showFrustum,this.cameraEntity=new G({visibility:!0,scale:this.frustumScale,geoObject:{tag:"frustum",color:"rgba(0,255,0,0.20)",object3d:Sh}}),this.frameBuffer.init()}get frustumScale(){return $.getFrustumScaleByCameraAspectRatio(1e3,this.camera.getViewAngle(),this.camera.getAspectRatio())}addTo(e){this._composer||(this._composer=e,this._composerIndex=e.frameHandlers.length,this._composer._frameHandlers.push(this))}remove(){this._composer&&(this._composer._frameHandlers.splice(this._composerIndex,1),this._composer=null,this._composerIndex=-1)}frame(){if(this.frameHandler&&this.frameBuffer.handler.gl&&(this.frameHandler(this),this.showFrustum)){let e=this.camera,t=$.getFrustumScaleByCameraAngles(100,e.horizontalViewAngle,e.verticalViewAngle);this.cameraEntity.setScale3v(t),this.cameraEntity.setCartesian3v(e.eye),this.cameraEntity.setAbsolutePitch(e.getAbsolutePitch()),this.cameraEntity.setAbsoluteYaw(e.getAbsoluteYaw()),this.cameraEntity.setAbsoluteRoll(e.getAbsoluteRoll())}}}function Oe(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 eo{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 tt,this.inverseProjectionMatrix=new tt,this.projectionViewMatrix=new tt,this.projectionViewRTEMatrix=new tt,this.inverseProjectionViewMatrix=new tt,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}getProjectionViewRTEMatrix(){return this.projectionViewRTEMatrix._m}getProjectionMatrix(){return this.projectionMatrix._m}getInverseProjectionMatrix(){return this.inverseProjectionMatrix._m}setProjectionMatrix(e,t,i,s,r,n=10){if(r){let r=n*Math.tan(e*Qt),o=r*t;this._setFrustumParams(r,o,i,s),this.projectionMatrix.setOrthographic(this.left,this.right,this.bottom,this.top,this.near,this.far)}else{let r=i*Math.tan(e*Qt),n=r*t;this._setFrustumParams(r,n,i,s),this.projectionMatrix.setPerspective(this.left,this.right,this.bottom,this.top,this.near,this.far)}this.projectionMatrix.inverseTo(this.inverseProjectionMatrix)}_setFrustumParams(e,t,i,s){this.top=e,this.right=t,this.bottom=-this.top,this.left=-this.right,this.near=i,this.far=s}setProjectionViewRTEMatrix(e){this.projectionViewRTEMatrix=this.projectionMatrix.mul(e)}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],Oe(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],Oe(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],Oe(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],Oe(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],Oe(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],Oe(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,s=!0;for(let r=0;r<6;r++){t=0,i=0;for(let s=0;s<8&&(0===i||0===t);s++)e.vertices[s].dotArr(this._f[r])+this._f[r][3]<0?t++:i++;if(0===i)return!1;t>0&&(s=!0)}return s}}const K=class{};K.Linear=e=>e,K.QuadIn=e=>e*e,K.QuadOut=e=>1-(1-e)*(1-e),K.QuadInOut=e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,K.CubicIn=e=>e*e*e,K.CubicOut=e=>1-Math.pow(1-e,3),K.CubicInOut=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,K.QuartIn=e=>e*e*e*e,K.QuartOut=e=>1-Math.pow(1-e,4),K.QuartInOut=e=>e<.5?8*e*e*e*e:1-Math.pow(-2*e+2,4)/2,K.QuintIn=e=>e*e*e*e*e,K.QuintOut=e=>1-Math.pow(1-e,5),K.QuintInOut=e=>e<.5?16*e*e*e*e*e:1-Math.pow(-2*e+2,5)/2,K.SineIn=e=>1-Math.cos(e*Math.PI/2),K.SineOut=e=>Math.sin(e*Math.PI/2),K.SineInOut=e=>-(Math.cos(Math.PI*e)-1)/2,K.ExpoIn=e=>0===e?0:Math.pow(2,10*e-10),K.ExpoOut=e=>1===e?1:1-Math.pow(2,-10*e),K.ExpoInOut=e=>0===e?0:1===e?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2,K.CircIn=e=>1-Math.sqrt(1-Math.pow(e,2)),K.CircOut=e=>Math.sqrt(1-Math.pow(e-1,2)),K.CircInOut=e=>e<.5?(1-Math.sqrt(1-Math.pow(2*e,2)))/2:(Math.sqrt(1-Math.pow(-2*e+2,2))+1)/2,K.BackIn=e=>2.70158*e*e*e-1.70158*e*e,K.BackOut=e=>1+2.70158*Math.pow(e-1,3)+1.70158*Math.pow(e-1,2),K.BackInOut=e=>{const t=2.5949095;return e<.5?Math.pow(2*e,2)*(7.189819*e-t)/2:(Math.pow(2*e-2,2)*((t+1)*(2*e-2)+t)+2)/2},K.ElasticIn=e=>{const t=2*Math.PI/3;return 0===e?0:1===e?1:-Math.pow(2,10*e-10)*Math.sin((10*e-10.75)*t)},K.ElasticOut=e=>{const t=2*Math.PI/3;return 0===e?0:1===e?1:Math.pow(2,-10*e)*Math.sin((10*e-.75)*t)+1},K.ElasticInOut=e=>{const t=2*Math.PI/4.5;return 0===e?0:1===e?1:e<.5?-Math.pow(2,20*e-10)*Math.sin((20*e-11.125)*t)/2:Math.pow(2,-20*e+10)*Math.sin((20*e-11.125)*t)/2+1},K.BounceOut=e=>e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375,K.BounceIn=e=>1-K.BounceOut(1-e),K.BounceInOut=e=>e<.5?.5*(1-K.BounceOut(1-2*e)):.5*(K.BounceOut(2*e-1)+1);let Or=K;const Rh=["viewchange","moveend","flystart","flyend","flystop"],ba=Or.CubicInOut,Ss=class e{constructor(t={}){if(this.__id=e.__counter__++,this.events=lt(Rh,this),this._isOrthographic=t.isOrthographic??!1,this._focusDistance=null!=t.focusDistance?t.focusDistance:10,this._width=t.width||1,this._height=t.height||1,this.eye=t.eye||new v,this.eyeHigh=new Float32Array(3),this.eyeLow=new Float32Array(3),this._viewAngle=t.viewAngle||47,this._horizontalViewAngle=0,this._viewMatrix=new tt,this._viewMatrixRTE=new tt,this._normalMatrix=new Se,this._r=new v(1,0,0),this._u=new v(0,1,0),this._b=new v(0,0,1),this._f=this._b.negateTo(),this._pr=this._r.clone(),this._pu=this._u.clone(),this._pb=this._b.clone(),this._peye=this.eye.clone(),this.isMoving=!1,this._flight=null,this._completeCallback=null,this._frameCallback=null,this._flying=!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],s=new eo({fov:this._viewAngle,aspect:this.getAspectRatio(),near:i[0],far:i[1]});s.cameraFrustumIndex=this.frustums.length,this.frustums.push(s),this.frustumColors.push(s._pickingColorU[0],s._pickingColorU[1],s._pickingColorU[2])}else{let e=1,t=500,i=new eo({fov:this._viewAngle,aspect:this.getAspectRatio(),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.frustumColorIndex=0,this.isFirstPass=!1,this._projSizeConst=0,this.set(t.eye||new v(0,0,1),t.look||new v,t.up||new v(0,1,0))}get isOrthographic(){return this._isOrthographic}set isOrthographic(e){this._isOrthographic!==e&&(this._isOrthographic=e,this.refresh())}get focusDistance(){return this._focusDistance}set focusDistance(e){e!==this._focusDistance&&(this._focusDistance=e,this._isOrthographic&&this.refresh())}get id(){return this.__id}flyCartesian(e,t={}){this.stopFlying(),t.look=t.look||v.ZERO,t.up=t.up||v.UP,t.duration=t.duration||800;const i=t.ease||ba;this._completeCallback=t.completeCallback||(()=>{}),this._frameCallback=t.frameCallback||(()=>{}),t.startCallback&&t.startCallback.call(this);let s=this.eye.clone(),r=this._u,n=this._b,o=t.up,a=e.clone(),l=v.sub(e,t.look),h=o.cross(l);l.normalize(),h.normalize();let c=l.cross(h);this._flight={fly:e=>{let t=1-i(e),o=s.smerp(a,t),h=r.smerp(c,t),d=v.add(o,n.smerp(l,t).negateTo()),_=new v(o.x-d.x,o.y-d.y,o.z-d.z),u=h.cross(_);_.normalize(),u.normalize();let f=_.cross(u);return{eye:o,n:_,u:u,v:f}},duration:t.duration,startedAt:Date.now()},this._flying=!0,this.events.dispatch(this.events.flystart,this)}stopFlying(){this._flying&&(this._flying=!1,this._flight=null,this._frameCallback=null,this.events.dispatch(this.events.flystop,this))}checkFly(){if(this._flying&&null!==this._flight){let e=Math.min((Date.now()-this._flight.startedAt)/this._flight.duration,1);const t=this._flight.fly(e);this.eye=t.eye,this._r=t.u,this._u=t.v,this._b=t.n,this._f.set(-this._b.x,-this._b.y,-this._b.z),this._frameCallback&&this._frameCallback(),this.update(),e>=1&&(this.stopFlying(),this._completeCallback&&(this.events.dispatch(this.events.flyend,this),this._completeCallback(),this._completeCallback=null))}}isFlying(){return this._flying}checkMoveEnd(){let e=this._r,t=this._u,i=this._b,s=this.eye;this._peye.equal(s)&&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(s)}bindFrustumsPickingColors(e){for(let t=0;t<this.frustums.length;t++)e.assignPickingColor(this.frustums[t])}_init(e){this._setProj(this._viewAngle,this.getAspectRatio()),this.set(e.eye||new v(0,0,1),e.look||new v,e.up||new v(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._f.clone()}getBackward(){return this._b.clone()}update(){let e=this._r,t=this._u,i=this._b,s=this.eye;v.doubleToTwoFloat32Array(s,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,-s.dot(e),-s.dot(t),-s.dot(i),1]),this._viewMatrixRTE.set([e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1]);for(let e=0,t=this.frustums.length;e<t;e++)this.frustums[e].setViewMatrix(this._viewMatrix),this.frustums[e].setProjectionViewRTEMatrix(this._viewMatrixRTE);this.events.dispatch(this.events.viewchange,this)}refresh(){this._setProj(this._viewAngle,this.getAspectRatio()),this.update()}get width(){return this._width}get height(){return this._height}setViewportSize(e,t){this._width=e,this._height=t,this.refresh()}getAspectRatio(){return this._width/this._height}_setProj(e,t){this._viewAngle=e;for(let i=0,s=this.frustums.length;i<s;i++){let s=this.frustums[i];s.setProjectionMatrix(e,t,s.near,s.far,this._isOrthographic,this._focusDistance)}var i,s;this._horizontalViewAngle=(i=e,s=t,Gr*Math.atan(Math.tan(Qt*i)*s)),this._updateViewportParameters()}_updateViewportParameters(){this._tanViewAngle_hrad=Math.tan(this._viewAngle*Qt),this._tanViewAngle_hradOneByHeight=this._tanViewAngle_hrad*(1/this._height),this._projSizeConst=Math.min(this._width<512?512:this._width,this._height<512?512:this._height)/(this._viewAngle*j)}setViewAngle(e){this._viewAngle=e,this.refresh()}getViewAngle(){return this._viewAngle}get viewAngle(){return this._viewAngle}get verticalViewAngle(){return this._viewAngle}get horizontalViewAngle(){return this._horizontalViewAngle}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._f.set(-this._b.x,-this._b.y,-this._b.z),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._f.set(-this._b.x,-this._b.y,-this._b.z),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}setRoll(e){let t=Math.cos(e),i=Math.sin(e),s=this._r.clone();this._r.set(t*s.x-i*this._u.x,t*s.y-i*this._u.y,t*s.z-i*this._u.z),this._u.set(i*s.x+t*this._u.x,i*s.y+t*this._u.y,i*s.z+t*this._u.z)}setPitch(e){let t=Math.cos(e),i=Math.sin(e),s=this._b;this._b.set(t*s.x-i*this._u.x,t*s.y-i*this._u.y,t*s.z-i*this._u.z),this._u.set(i*s.x+t*this._u.x,i*s.y+t*this._u.y,i*s.z+t*this._u.z)}setYaw(e){let t=Math.cos(e),i=Math.sin(e),s=this._r;this._r.set(t*s.x-i*this._b.x,t*s.y-i*this._b.y,t*s.z-i*this._b.z),this._b.set(i*s.x+t*this._b.x,i*s.y+t*this._b.y,i*s.z+t*this._b.z)}setPitchYawRoll(e,t,i){let s=new F;s.setPitchYawRoll(e,t,i),this.setRotation(s)}getPitch(){return this.getRotation().getPitch()}getYaw(){return this.getRotation().getYaw()}getRoll(){return this.getRotation().getRoll()}getAbsolutePitch(){return this.getRotation().getPitch()}getAbsoluteYaw(){return this.getRotation().getYaw()}getAbsoluteRoll(){return this.getRotation().getRoll()}getRotation(){return F.getLookRotation(this._f,this._u).conjugate()}setRotation(e,t,i,s){e.mulVec3Res(t||new v(0,1,0),this._u),e.mulVec3Res(i||new v(1,0,0),this._r),e.mulVec3Res(s||new v(0,0,1),this._b),this._f.set(-this._b.x,-this._b.y,-this._b.z)}rotate(e){e.mulVec3Res(this._u,this._u),e.mulVec3Res(this._r,this._r),e.mulVec3Res(this._b,this._b),this._f.set(-this._b.x,-this._b.y,-this._b.z)}unproject2v(e,t,i){return this.unproject(e.x,e.y,t,i)}unproject(e,t,i,s){let r=.5*this._width,n=.5*this._height,o=(e-r)/r,a=-(t-n)/n,l=this.frustums[0];if(this.isOrthographic){if(i){let e=.5*(l.right-l.left)*o,t=.5*(l.top-l.bottom)*a,r=this.getUp().scale(t),n=this.getRight().scale(e),h=r.addA(n),c=this.eye.add(h),d=this.getForward(),_=c.addA(d.scaleTo(i));return s&&s.copy(_),_.sub(this.eye).normalize()}return this.getForward()}{let e=l.inverseProjectionViewMatrix,t=e.mulVec4(new et(o,a,-1,1)).affinity();return e.mulVec4(new et(o,a,0,1)).affinity().subA(t).toVec3().normalize()}}project3v(e){return this.project(e.x,e.y,e.z)}project(e,t,i){let s=this.frustums[0].projectionViewMatrix.mulVec4(new et(e,t,i,1));return new H((1+s.x/s.w)*this._width*.5,(1-s.y/s.w)*this._height*.5)}rotateAround(e,t=!1,i=v.ZERO,s=v.UP){s=t?this._u:s;let r=tt.getRotation(e,s),n=tt.getRotationAroundPoint(e,i,s);this.eye=n.mulVec3(this.eye),this._u=r.mulVec3(this._u).normalize(),this._r=r.mulVec3(this._r).normalize(),this._b=r.mulVec3(this._b).normalize(),this._f.set(-this._b.x,-this._b.y,-this._b.z)}rotateHorizontal(e,t,i,s){this.rotateAround(e,t,i,s)}rotateVertical(e,t){this.rotateAround(e,!1,t,this._r)}projectedSize(e,t){if(this.isOrthographic){const e=this.frustums[0].projectionMatrix._m;return t*(this._height*e[5]*.5)}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.frustumColorIndex=10*(e+1)/255,this.isFirstPass=e===this.FARTHEST_FRUSTUM_INDEX}getCurrentFrustum(){return this.currentFrustumIndex}containsSphere(e){for(let t=0;t<this.frustums.length;t++)if(this.frustums[t].containsSphere(e))return!0;return!1}get frustum(){return this.frustums[this.currentFrustumIndex]}getProjectionMatrix(){return this.frustum.projectionMatrix._m}getProjectionViewMatrix(){return this.frustum.projectionViewMatrix._m}getProjectionViewRTEMatrix(){return this.frustum.projectionViewRTEMatrix._m}getInverseProjectionViewMatrix(){return this.frustum.inverseProjectionViewMatrix._m}getInverseProjectionMatrix(){return this.frustum.inverseProjectionMatrix._m}viewDistance(e,t=1e4){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e),this.update()}copy(e){this.eye.copy(e.eye),this._r.copy(e._r),this._u.copy(e._u),this._b.copy(e._b),this._f.copy(e._f),this._width=e.width,this._height=e.height,this.setViewAngle(e.viewAngle),this.update()}getAltitude(){return this.eye.y}};Ss.__counter__=0;let Pi=Ss;class wa extends Pi{constructor(e,t={}){super({...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 v,this._insideSegment=null,this.slope=0,this._keyLock=new Me,this._flight=null,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)<=ct&&L.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 s=this.planet.ellipsoid,r=s.lonLatToCartesian(this._lonLat),n=t?s.lonLatToCartesian(t):v.ZERO;this.set(r,n,i||r.getNormal()),this.update()}getLonLat(){return this._lonLat}getHeight(){return this._lonLat.height}getExtentPosition(e,t){t=t||0;let i=e.getNorth(),s=e.getSouth(),r=e.getEast(),n=e.getWest();n>r&&(r+=360);let o=this.planet.ellipsoid,a=new L(r,i),l=o.lonLatToCartesian(a);a.lat=s;let h=o.lonLatToCartesian(a);a.lon=n;let c=o.lonLatToCartesian(a);a.lat=i;let d=o.lonLatToCartesian(a),_=v.sub(l,c).scale(.5).addA(c),u=_.length();u<1e-6&&(a.lon=.5*(r+n),a.lat=.5*(i+s),_=o.lonLatToCartesian(a)),d.subA(_),h.subA(_),l.subA(_),c.subA(_);let f=_.getNormal(),g=f.cross(v.NORTH).normalize(),p=g.cross(f).normalize(),m=Math.max(Math.abs(p.dot(d)),Math.abs(p.dot(h)),Math.abs(p.dot(l)),Math.abs(p.dot(c))),y=Math.max(Math.abs(g.dot(d)),Math.abs(g.dot(h)),Math.abs(g.dot(l)),Math.abs(g.dot(c))),x=Math.tan(this._viewAngle*j*.5),b=this.getAspectRatio()*x,w=Math.max(y/b,m/x);return _.normalize(),_.scale(u+w+t),_}viewExtent(e,t){this.stopFlying(),this.set(this.getExtentPosition(e,t),v.ZERO,v.NORTH),this.update()}flyExtent(e,t,i={}){i.look=v.ZERO,this.flyCartesian(this.getExtentPosition(e,t),i)}viewDistance(e,t=1e4){let i=this.eye.add(this.getForward().scaleTo(t)),s=F.getRotationBetweenVectors(i.getNormal(),e.getNormal());if(s.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let i=e.add(s.mulVec3(this.getBackward()).scale(t)),r=s.mulVec3(this.getUp());this.set(i,e,r)}this.update()}flyLonLat(e,t={}){let i=new L(e.lon,e.lat,e.height||this._lonLat.height);this.flyCartesian(this.planet.ellipsoid.lonLatToCartesian(i),t)}flyDistance(e,t=1e4,i={}){let s=this.eye.add(this.getForward().scaleTo(t)),r=F.getRotationBetweenVectors(s.getNormal(),e.getNormal());if(r.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let s=e.add(r.mulVec3(this.getBackward()).scale(t)),n=r.mulVec3(this.getUp());i.look=e,i.up=n,this.flyCartesian(s,i)}}flyCartesian(e,t={}){this.stopFlying(),t.preventLock||(this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet.normalMapCreator.lock(this._keyLock)),t.amplitude=null!=t.amplitude?t.amplitude:1,t.look=t.look||v.ZERO,t.up=t.up||v.NORTH,t.duration=t.duration||800;const i=t.ease||ba;this._completeCallback=t.completeCallback||(()=>{}),this._frameCallback=t.frameCallback||(()=>{}),t.startCallback&&t.startCallback.call(this),t.look instanceof L&&(t.look=this.planet.ellipsoid.lonLatToCartesian(t.look));let s=this.eye.clone(),r=this._u,n=this._b,o=this.planet.ellipsoid.cartesianToLonLat(e),a=t.up,l=this.planet.ellipsoid.lonLatToCartesian(new L(o.lon,o.lat,0)),h=v.sub(e,t.look),c=a.cross(h);h.normalize(),c.normalize();let d=h.cross(c),_=s.getNormal(),u=l.getNormal(),f=1-_.dot(u),g=t.amplitude*yo*Math.sqrt(f>0?f:0),p=6639613,m=Math.max(this._lonLat.height,o.height);m>p&&(p=m);let y=m+2.5*g*(p-m),x=v.ZERO;this._flight={fly:t=>{let a,l=i(t),c=1-l;if(l>=1)a=e.clone();else{let t=s.smerp(e,c).normalize(),i=this.planet.getRayIntersectionEllipsoid(new V(x,t)),r=this._lonLat.height*c*c*c+3*y*c*c*l+3*y*c*l*l+o.height*l*l*l;a=i.addA(t.scale(r))}let _=r.smerp(d,c),u=v.add(a,n.smerp(h,c).negateTo()),f=new v(a.x-u.x,a.y-u.y,a.z-u.z),g=_.cross(f);f.normalize(),g.normalize();let p=f.cross(g);return{eye:a,n:f,u:g,v:p}},duration:t.duration,startedAt:Date.now()},this._flying=!0,this.events.dispatch(this.events.flystart,this)}stopFlying(){this._flying&&(this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet.normalMapCreator.free(this._keyLock),super.stopFlying())}rotateLeft(e,t){this.rotateHorizontal(e,!0!==t,v.ZERO),this.update()}rotateRight(e,t){this.rotateHorizontal(-e,!0!==t,v.ZERO),this.update()}rotateUp(e){this.rotateVertical(e,v.ZERO),this.update()}rotateDown(e){this.rotateVertical(-e,v.ZERO),this.update()}rotateVertical(e,t,i=0){let s=(new tt).setRotation(this._r,e),r=(new tt).setIdentity().translate(t),n=(new tt).setIdentity().translate(t.negateTo()),o=r.mul(s).mul(n).mulVec3(this.eye),a=s.mulVec3(this._u).normalize(),l=s.mulVec3(this._r).normalize(),h=s.mulVec3(this._b).normalize(),c=o.getNormal(),d=h.dot(c);if(!(a.dot(c)<=0))if(i){let e=d-this.slope;if(d<i&&e<0)return;(d>.1&&a.dot(c)>0||this.slope<=.1||this._u.dot(this.eye.getNormal())<=0)&&(this.eye=o,this._u=a,this._r=l,this._b=h,this._f.set(-h.x,-h.y,-h.z))}else this.eye=o,this._u=a,this._r=l,this._b=h,this._f.set(-h.x,-h.y,-h.z)}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=v.proj_b_to_plane(this.slope>=.97?this.getUp():this.getForward(),e).normalize(),i=v.proj_b_to_plane(v.NORTH,e).normalize(),s=Math.sign(e.dot(t.cross(i)))*Math.acos(t.dot(i))*J;return s<0?360+s:s}isVisible(e){let t=this.eye.length();return this.eye.distance(e)<Math.sqrt(t*t-this.planet.ellipsoid.equatorialSizeSqr)}getPitch(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getPitch()}getYaw(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getYaw()}getRoll(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getRoll()}setPitch(e){let t=this.planet.getFrameRotation(this.eye),i=new F;i.setPitchYawRoll(e,this.getYaw(),this.getRoll(),t),this.setRotation(i)}setYaw(e){let t=this.planet.getFrameRotation(this.eye),i=new F;i.setPitchYawRoll(this.getPitch(),e,this.getRoll(),t),this.setRotation(i)}setRoll(e){let t=this.planet.getFrameRotation(this.eye),i=new F;i.setPitchYawRoll(this.getPitch(),this.getYaw(),e,t),this.setRotation(i)}setPitchYawRoll(e,t,i){let s=this.planet.getFrameRotation(this.eye),r=new F;r.setPitchYawRoll(e,t,i,s).conjugate(),this.setRotation(r)}}const Rs=class e{constructor(t,i={}){this.handler=t,this.__id=e.__counter__++,this._fbo=null,this._width=i.width||t.canvas.width,this._height=i.height||t.canvas.height,this._depthComponent=null!=i.depthComponent?i.depthComponent:"DEPTH_COMPONENT16",this._useDepth=null==i.useDepth||i.useDepth,this._active=!1,this._size=i.size||1,this._depthRenderbuffer=null,this._filter=i.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)}isEqual(e){return!!e&&this.__id===e.__id}};Rs.__counter__=0;let hs=Rs;class mi{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,s,r){this._context.drawImage(e,t||0,i||0,s||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,s="normal 14px Verdana",r="black"){this._context.fillStyle=r,this._context.font=s,this._context.fillText(e,t,i)}getWidth(){return this._canvas.width}getHeight(){return this._canvas.height}load(e,t){let i=new Image,s=this;i.onload=function(){s.resize(i.width,i.height),s._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}}const io={UNSIGNED_BYTE:Uint8Array,FLOAT:Float32Array};class Rt extends hs{constructor(e,t={}){super(e,t),this.readPixelBuffersAsync=e=>{const t=this.handler.gl;if(this._skipFrame)return;this._skipFrame=!0;let i=this.width,s=this.height,r=this.pixelBuffers;this.activate();for(let e=0;e<r.length;e++){let n=r[e];t.bindBuffer(t.PIXEL_PACK_BUFFER,n.buffer),t.bufferData(t.PIXEL_PACK_BUFFER,n.data.byteLength,t.STREAM_READ),t.readBuffer(n.glAttachment),t.readPixels(0,0,i,s,t.RGBA,n.glType,0),t.bindBuffer(t.PIXEL_PACK_BUFFER,null)}this.deactivate();const n=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);var o,a;t.flush(),(o=t,a=n,new Promise(((e,t)=>{!function i(){const s=o.clientWaitSync(a,0,0);s==o.WAIT_FAILED?t():s==o.TIMEOUT_EXPIRED?requestAnimationFrame(i):e()}()}))).then((()=>{this._skipFrame=!1,t.deleteSync(n);for(let e=0;e<r.length;e++){let i=r[e];i.data&&(t.bindBuffer(t.PIXEL_PACK_BUFFER,i.buffer),t.getBufferSubData(t.PIXEL_PACK_BUFFER,0,i.data))}t.bindBuffer(t.PIXEL_PACK_BUFFER,null),e&&e(this)}))},this._targets=Rt.createTargets(t.targets),this._size=this._targets.length,this._renderbufferTarget=null!=t.renderbufferTarget?t.renderbufferTarget:"DEPTH_ATTACHMENT",this.textures=t.textures||new Array(this._size),this.pixelBuffers=[],this._skipFrame=!1}static createTargets(e){let t=0,i=0;return e?e.map((e=>{let s=e.attachment||"COLOR_ATTACHMENT";"COLOR_ATTACHMENT"===s&&(s="COLOR_ATTACHMENT"+t++);let r=e.type||"UNSIGNED_BYTE";return{internalFormat:e.internalFormat||"RGBA",format:e.format||"RGBA",type:r,attachment:s,filter:e.filter||"NEAREST",pixelBufferIndex:e.readAsync?i++:-1,TypeArrayConstructor:io[r]}})):[{internalFormat:"RGBA",format:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT0",filter:"NEAREST",pixelBufferIndex:-1,TypeArrayConstructor:io.UNSIGNED_BYTE}]}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);for(let t=0;t<this.pixelBuffers.length;t++)this.pixelBuffers[t].data=null,e.deleteBuffer(this.pixelBuffers[t].buffer);this.pixelBuffers=[],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._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo);let t=[];for(let i=0;i<this._targets.length;i++){let s=this._targets[i],r=this.textures[i]||this.handler.createEmptyTexture2DExt(this._width,this._height,s.filter,s.internalFormat,s.format,s.type),n=e[s.attachment];r&&(this.bindOutputTexture(r,n),this.textures[i]=r),"DEPTH_ATTACHMENT"!==s.attachment&&t.push(n),-1!==s.pixelBufferIndex&&this._createPixelBuffer(s)}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)}getPixelBufferData(e=0){let t=this._targets[e].pixelBufferIndex;return-1!==t?this.pixelBuffers[t].data:null}_createPixelBuffer(e){let t=this.handler.gl,i=e.pixelBufferIndex,s=this.pixelBuffers[i];s||(s=this.pixelBuffers[i]={buffer:null,data:null,glType:-1,glAttachment:-1});let r=this.width*this.height*4;s.data=null,s.data=new e.TypeArrayConstructor(r),s.buffer=t.createBuffer(),t.bindBuffer(t.PIXEL_PACK_BUFFER,s.buffer),t.bufferData(t.PIXEL_PACK_BUFFER,r,t.STREAM_READ),t.bindBuffer(t.PIXEL_PACK_BUFFER,null),s.glType=t[e.type],s.glAttachment=t[e.attachment]}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,s=0,r=1,n=1){let o=this.handler.gl;o.bindFramebuffer(o.FRAMEBUFFER,this._fbo),o.readBuffer&&o.readBuffer(o.COLOR_ATTACHMENT0+s||0),o.readPixels(t*this._width,i*this._height,r,n,o.RGBA,o[this._targets[s].type],e),o.bindFramebuffer(o.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._targets[t].type],e),i.bindFramebuffer(i.FRAMEBUFFER,null)}getImage(){let e=new Uint8Array(4*this._width*this._height);this.readAllPixels(e);let t=new mi(this._width,this._height);return t.setData(e),t.getImage()}readData(e,t,i,s=0){const r=this.width,n=this.height,o=Math.floor(e*(r-1)),a=4*(Math.floor(t*(n-1))*r+o),l=this.pixelBuffers[s].data;l&&(i[0]=l[a],i[1]=l[a+1],i[2]=l[a+2],i[3]=l[a+3])}}const Mh=["tick","end","start","stop"],Ms=class e{constructor(t={}){this.__handler=null,this.active=!0,this.__id=e.__counter__++,this.events=lt(Mh,this),this.name=t.name||"",this.startDate=t.startDate||0,this.endDate=t.endDate||0;let i=t.currentDate||is(new Date);t.startDate&&i<t.startDate&&(i=t.startDate),t.endDate&&i>t.endDate&&(i=t.endDate),this.currentDate=i,this._multiplier=void 0!==t.multiplier?t.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*tn,this._intervalCallback=t}setDate(e){let t=is(e);this.startDate&&t<this.startDate&&(t=this.startDate),this.endDate&&t>this.endDate&&(t=this.endDate),this.currentDate=t}getDate(){return mr(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=Fo(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))}};Ms.__counter__=0;let Nr=Ms;class Bh{constructor(e,t){t._programController=this,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}}let so=class{constructor(){this.next=null,this.prev=null,this.data=null}};class Js{constructor(e=256){this._current=new so,this._head=this._current;for(let t=0;t<e;t++){let e=new so;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 ro=["","WEBKIT_","MOZ_"],tr=["webgl2","webgl"];class Be{constructor(e,t={}){this.framebufferStack=new Js,this._requestAnimationFrameId=0,this.drawFrame=()=>{let e=window.performance.now(),t=this.deltaTime;this.deltaTime=.5*(e-this._lastAnimationFrameTime+this.prevDeltaTime),this.deltaTime>3?this.deltaTime=3:this.deltaTime<1&&(this.deltaTime=1),this.prevDeltaTime=t,this._lastAnimationFrameTime=e,this.defaultClock.tick(this.deltaTime);for(let e=0;e<this._clocks.length;e++)this._clocks[e].tick(this.deltaTime);let i=this.canvas;Math.floor(i.clientWidth*this._params.pixelRatio)===i.width&&Math.floor(i.clientHeight*this._params.pixelRatio)===i.height||(0===i.clientWidth||0===i.clientHeight?this.stop():document.hidden||(this.start(),this.setSize(i.clientWidth,i.clientHeight))),this._frameCallback()},this.events=lt(["visibilitychange","resize"]),this._throttledDrawFrame=this.drawFrame,this.defaultClock=new Nr,this._clocks=[],this.prevDeltaTime=0,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:zo("og_dpi")||t.pixelRatio||1,extensions:t.extensions||[],context:t.context||{}},this.extensions={},this._canvasTarget=e,this._lastAnimationFrameTime=0,this._initialized=!1,this._frameCallback=function(){},this.transparentTexture=null,this.defaultTexture=null,this.framebufferStack=new Js,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||Gt(t.autoActivate))&&this.initialize()}set frameDelay(e){this._throttledDrawFrame=0===e?this.drawFrame:yi(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,s;for(i in ro)if(s=e.getExtension(ro[i]+t),s)return s}static getContext(e,t){let i=null;try{let s=new URLSearchParams(location.search).get("og_ver");if(s)i=e.getContext(s,t),i&&(i.type=s);else for(let s=0;s<tr.length;s++)if(i=e.getContext(tr[s],t),i){i.type=tr[s];break}}catch{ie.logErr("exception during the GL context initialization")}return i||ie.logErr("could not initialise WebGL"),i}setFrameCallback(e){e&&(this._frameCallback=e)}createEmptyTexture2DExt(e=1,t=1,i="NEAREST",s="RGBA",r="RGBA",n="UNSIGNED_BYTE",o="CLAMP_TO_EDGE",a=0){let l=this.gl,h=l.createTexture();return l.bindTexture(l.TEXTURE_2D,h),l.texImage2D(l.TEXTURE_2D,a,l[s.toUpperCase()],e,t,0,l[r.toUpperCase()],l[n.toUpperCase()],null),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l[i.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l[i.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l[o.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l[o.toUpperCase()]),l.bindTexture(l.TEXTURE_2D,null),h}createEmptyTexture_n(e,t,i,s){let r=this.gl,n=r.createTexture();return r.bindTexture(r.TEXTURE_2D,n),r.texImage2D(r.TEXTURE_2D,0,i||r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,s||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,s||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),n}createEmptyTexture_l(e,t,i,s){let r=this.gl,n=r.createTexture();return r.bindTexture(r.TEXTURE_2D,n),r.texImage2D(r.TEXTURE_2D,0,i||r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,s||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,s||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),n}createTexture_n_webgl1(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texImage2D(r.TEXTURE_2D,0,t||r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_l_webgl1(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texImage2D(r.TEXTURE_2D,0,t||r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_mm_webgl1(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texImage2D(r.TEXTURE_2D,0,t||r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_a_webgl1(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texImage2D(r.TEXTURE_2D,0,t||r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameterf(r.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_n_webgl2(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texStorage2D(r.TEXTURE_2D,1,t||r.RGBA8,e.width,e.height),r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.width,e.height,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_l_webgl2(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texStorage2D(r.TEXTURE_2D,1,t||r.RGBA8,e.width,e.height),r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.width,e.height,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_mm_webgl2(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texStorage2D(r.TEXTURE_2D,2,t||r.RGBA8,e.width,e.height),r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.width,e.height,r.RGBA,r.UNSIGNED_BYTE,e),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_a_webgl2(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texStorage2D(r.TEXTURE_2D,2,t||r.RGBA8,e.width,e.height),r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.width,e.height,r.RGBA,r.UNSIGNED_BYTE,e),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameterf(r.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}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 s=[[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 mi;r.fillEmpty();let n=r.getImage();for(let e=0;e<s.length;e++){let r=s[e][1];t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texImage2D(r,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,n)}for(let e=0;e<s.length;e++){let r=s[e][1],n=new Image;n.crossOrigin="",n.onload=function(e,i,s){return function(){t&&e&&(t.bindTexture(t.TEXTURE_CUBE_MAP,e),t.texImage2D(i,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s))}}(i,r,n),n.src=s[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 Bh(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=Be.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||!this.canvas||(this.gl=Be.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[e.length-1].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,s=4){let r=this.gl,n=r.createBuffer();return r.bindBuffer(r.ARRAY_BUFFER,n),r.bufferData(r.ARRAY_BUFFER,t*e*s,i||r.STREAM_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),n.itemSize=e,n.numItems=t,n}setStreamArrayBuffer(e,t,i=0){let s=this.gl;return s.bindBuffer(s.ARRAY_BUFFER,e),s.bufferSubData(s.ARRAY_BUFFER,i,t),s.bindBuffer(s.ARRAY_BUFFER,null),e}createArrayBuffer(e,t,i,s){let r=this.gl,n=r.createBuffer();return r.bindBuffer(r.ARRAY_BUFFER,n),r.bufferData(r.ARRAY_BUFFER,e,s||r.STATIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),n.itemSize=t,n.numItems=i||e.length/t,n}createArrayBufferLength(e,t){let i=this.gl,s=i.createBuffer();return i.bindBuffer(i.ARRAY_BUFFER,s),i.bufferData(i.ARRAY_BUFFER,e,t||i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),s.itemSize=1,s.numItems=e,s}createElementArrayBuffer(e,t,i,s){let r=this.gl,n=r.createBuffer();return r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,n),r.bufferData(r.ELEMENT_ARRAY_BUFFER,e,s||r.STATIC_DRAW),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,null),n.itemSize=t,n.numItems=i||e.length,n}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.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 H(Math.round(.5*e.width),Math.round(.5*e.height)):new H}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,s;if(e&&e.color)i=new mi(2,2),i.fillColor(e.color),s=this.createTexture_n(i.getCanvas()),s.default=!0,t(s);else if(e&&e.url){let i=new Image,r=this;i.onload=function(){s=r.createTextureDefault(i),s.default=!0,t(s)},i.src=e.url}else i=new mi(2,2),i.fillColor("#C5C5C5"),s=this.createTexture_n(i.getCanvas()),s.default=!0,t(s)}deleteTexture(e){e&&!e.default&&this.gl&&this.gl.deleteTexture(e)}destroy(){var e,t;null==(e=this.resizeObserver)||e.disconnect(),null==(t=this.intersectionObserver)||t.disconnect(),this.stop();for(let e in this.programs)this.removeProgram(e);let i=this.gl;if(i){i.deleteTexture(this.transparentTexture),this.transparentTexture=null,i.deleteTexture(this.defaultTexture),this.defaultTexture=null,this.framebufferStack=new Js;let e=i.getParameter(i.MAX_VERTEX_ATTRIBS),t=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,t);for(let t=0;t<e;++t)i.disableVertexAttribArray(t),i.vertexAttribPointer(t,4,i.FLOAT,!1,0,0),i.vertexAttrib1f(t,0);i.deleteBuffer(t);let s=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS);for(let e=0;e<s;++e)i.activeTexture(i.TEXTURE0+e),i.bindTexture(i.TEXTURE_CUBE_MAP,null),i.bindTexture(i.TEXTURE_2D,null);i.activeTexture(i.TEXTURE0),i.useProgram(null),i.bindBuffer(i.ARRAY_BUFFER,null),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindRenderbuffer(i.RENDERBUFFER,null),i.disable(i.BLEND),i.disable(i.CULL_FACE),i.disable(i.DEPTH_TEST),i.disable(i.DITHER),i.disable(i.SCISSOR_TEST),i.blendColor(0,0,0,0),i.blendEquation(i.FUNC_ADD),i.blendFunc(i.ONE,i.ZERO),i.clearColor(0,0,0,0),i.clearDepth(1),i.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 Ta extends hs{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 s=e.createRenderbuffer();e.bindRenderbuffer(e.RENDERBUFFER,s),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,s),t.push(e.COLOR_ATTACHMENT0+i),this.renderbuffers[i]=s,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)}}const Oc=Object.freeze(Object.defineProperty({__proto__:null,Framebuffer:Rt,Handler:Be,Multisample:Ta,Program:X,types:ht},Symbol.toStringTag,{value:"Module"}));class Ca extends Ai{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,ur(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=$e(2*e.width,4096),this._frameHeight=$e(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&&(ur(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}}const Nc=Object.freeze(Object.defineProperty({__proto__:null,AtmosphereConfig:class extends Q{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 dt({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 Kt({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 ut({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-groundAlbedo"></div>\n \n </div>'}),this._maxOpacity=new Z({label:"Max.opacity",max:5}),this._minOpacity=new Z({label:"Min.opacity",max:5}),this._rayleight=new Z({label:"Rayleight Scale",min:-10,max:10}),this._mie=new Z({label:"Mie Scale",min:-10,max:10}),this._height=new Z({label:"Height",max:1e6}),this._bottomRadius=new Z({label:"Polar Radius (BOTTOM_RADIUS)",max:31783761.571225896}),this._equatorialRadius=new Z({label:"Equatorial Radius (EQUATORIAL_RADIUS)",max:31890685}),this._mieScatteringCoefficient=new Z({label:"Mie Scattering Coefficient e-6",min:-39.96,max:39.96}),this._mieExtinctionCoefficient=new Z({label:"Mie Extinction Coef.e-6",min:4.44*-10,max:10*4.44}),this._rayleighScatteringCoefficientA=new Z({label:"Rayleight Scattering Coef A.e-6",min:5.802*-10,max:10*5.802}),this._rayleighScatteringCoefficientB=new Z({label:"Rayleight Scattering Coef B.e-6",min:13.558*-10,max:10*13.558}),this._rayleighScatteringCoefficientC=new Z({label:"Rayleight Scattering Coef C.e-6",min:-331,max:331}),this._ozoneAbsorptionCoefficientA=new Z({label:"Ozone absorbtion Coef A.e-6",min:-6.5,max:6.5}),this._ozoneAbsorptionCoefficientB=new Z({label:"Ozone absorbtion Coef B.e-6",min:-6.5,max:18.81}),this._ozoneAbsorptionCoefficientC=new Z({label:"Ozone absorbtion Coef C.e-6",min:.085*-10,max:10*.085}),this._ozoneDensityHeight=new Z({label:"Ozone Density Height",max:25e5}),this._ozoneDensityWide=new Z({label:"Ozone Density Wide",max:25e5}),this._sunAngularRadius=new Z({label:"Sun Angular Radius",max:4.685}),this._sunIntensity=new Z({label:"Sun Intensity",max:10}),this._groundAlbedo=new Z({label:"Ground Albedo (GROUND_ALBEDO)",max:.5}),this._parameters={ATMOS_HEIGHT:0,RAYLEIGH_SCALE:0,MIE_SCALE:0,GROUND_ALBEDO:0,BOTTOM_RADIUS:0,EQUATORIAL_RADIUS:0,rayleighScatteringCoefficient_0:0,rayleighScatteringCoefficient_1:0,rayleighScatteringCoefficient_2:0,mieScatteringCoefficient:0,mieExtinctionCoefficient:0,ozoneAbsorptionCoefficient_0:0,ozoneAbsorptionCoefficient_1:0,ozoneAbsorptionCoefficient_2:0,SUN_ANGULAR_RADIUS:0,SUN_INTENSITY:0,ozoneDensityHeight:0,ozoneDensityWide:0,disableSunDisk:!1}}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-groundAlbedo"),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._equatorialRadius.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._bottomRadius.max=5*this.planet.ellipsoid.getPolarSize(),this._equatorialRadius.max=5*this.planet.ellipsoid.getEquatorialSize(),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._equatorialRadius.value=this._parameters.EQUATORIAL_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._equatorialRadius.events.on("change",(e=>{this._parameters.EQUATORIAL_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)}},CameraDepthHandler:class extends Q{constructor(e){super(e),this._skipPreRender=!1,this._depthHandlerCallback=e=>{if(!this.planet)return;let t=e.frameBuffer;if(t.handler.gl,t.activate(),this._quadTreeStrategy){let t=e.camera;this._skipPreRender&&this._quadTreeStrategy.collectRenderNodes(t),this._skipPreRender=!0,console.log(this._quadTreeStrategy._renderedNodes)}t.deactivate(),t.readPixelBuffersAsync();let i=this.getLonLatFromPixelTerrain(1,1),s=this.getLonLatFromPixelTerrain(t.width-1,1),r=this.getLonLatFromPixelTerrain(t.width-1,t.height-1),n=this.getLonLatFromPixelTerrain(1,t.height-1);i&&s&&r&&n&&this.cameraGeoImage.setCorners([[i.lon,i.lat],[s.lon,s.lat],[r.lon,r.lat],[n.lon,n.lat]])},this._frameComposer=new Fr,this._frameHandler=null,this.cameraGeoImage=new Ca(`cameraGeoImage:${this.__id}`,{src:"test4.jpg",corners:[[0,1],[1,1],[1,0],[0,0]],visibility:!0,isBaseLayer:!1,opacity:.7}),this._quadTreeStrategy=null}_createCamera(){return this.planet?new wa(this.planet,{frustums:[[100,1e9]],width:640,height:480,viewAngle:45}):new Pi({frustums:[[100,1e9]],width:640,height:480,viewAngle:45})}get camera(){if(this._frameHandler)return this._frameHandler.camera}oninit(){if(super.oninit(),!this.renderer)return;this.renderer.handler.addProgram(new X("camera_depth",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"#version 300 es\n \n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in 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 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:"#version 300 es\n \n precision highp float; \n\n layout(location = 0) out vec4 depthColor;\n\n void main(void) {\n depthColor = vec4(gl_FragCoord.z, gl_FragCoord.z, gl_FragCoord.z, 1.0);\n }"})),this.planet&&this.planet.addLayer(this.cameraGeoImage);let e=new Rt(this.renderer.handler,{width:640,height:480,targets:[{internalFormat:"RGBA16F",type:"FLOAT",attachment:"COLOR_ATTACHMENT",readAsync:!0}],useDepth:!0});if(this._frameHandler=new to({camera:this._createCamera(),frameBuffer:e,frameHandler:this._depthHandlerCallback}),this.renderer.controls.CameraFrameComposer?this._frameComposer=this.renderer.controls.CameraFrameComposer:this.renderer.addControl(this._frameComposer),this._frameComposer.add(this._frameHandler),this.planet){const e={planet:this.planet,maxEqualZoomAltitude:this.planet.quadTreeStrategy.maxEqualZoomAltitude,minEqualZoomAltitude:this.planet.quadTreeStrategy.minEqualZoomAltitude,minEqualZoomCameraSlope:this.planet.quadTreeStrategy.minEqualZoomCameraSlope,transitionOpacityEnabled:!1};this._quadTreeStrategy=new this.planet.quadTreeStrategyPrototype(e),this._quadTreeStrategy.init(this.camera),this._quadTreeStrategy.preRender(),this._quadTreeStrategy.clearRenderedNodes(),this._skipPreRender=!1,this._quadTreeStrategy.preLoad()}}get framebuffer(){if(this._frameHandler)return this._frameHandler.frameBuffer}getCartesianFromPixelTerrain(e,t){if(this._frameHandler){let i=this._frameHandler.frameBuffer,s=this._frameHandler.camera,r=function(e,t,i,s){let r=new H(e,t),n=r.x/s.width,o=(s.height-r.y)/s.height,a=new Float32Array(4),l=0;if(s.readData(n,o,a,0),0===a[0])return 0;let h=a[0],c=i.frustums[0].inverseProjectionMatrix,d=new et(2*n-1,2*o-1,2*h-1,1),_=c.mulVec4(d),u=i.unproject(n*i.width,(1-o)*i.height);return l=-_.z/_.w/u.dot(i.getForward()),l}(e,t,s,i);if(0===r)return;let n=e/i.width,o=(i.height-t)/i.height;return s.unproject(n*s.width,(1-o)*s.height).scaleTo(r).addA(s.eye)}}getLonLatFromPixelTerrain(e,t){if(this.planet){let i=this.getCartesianFromPixelTerrain(e,t);if(i)return this.planet.ellipsoid.cartesianToLonLat(i)}}activate(){super.activate()}deactivate(){super.deactivate()}},CameraFrameComposer:Fr,CameraFrameHandler:to,CameraLock:Jn,CompassButton:Ho,Control:Q,DebugInfo:class extends Q{constructor(e={}){e.name&&""!==e.name||(e.name="DebugInfo"),super(e),this.el=null,this._watch=e.watch||[],this._toggleBtn=new dt({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 Kt({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 ss("Tile grid",{visibility:!0,isBaseLayer:!1,hideInLayerSwitcher:!0,drawTile:function(e,t){let i,s=document.createElement("canvas"),r=s.getContext("2d");s.width=256,s.height=256,r.clearRect(0,0,s.width,s.height),r.beginPath(),r.rect(0,0,s.width,s.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,s.width/2,s.height/2),t(s)}})}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(){var e;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 t=document.createElement("div");t.classList.add("og-debuginfo_controls"),this.el.appendChild(t);let i=this._watch;this._watch=[];for(let e=0;e<i.length;e++)this.addWatch(i[e]);null==(e=this._dialog.container)||e.appendChild(this.el),this.renderer.events.on("draw",this._frame,this);let s=this.planet;s&&this.addWatches([{label:"Nodes count",frame:()=>s.quadTreeStrategy._renderedNodes.length},{label:"Planet._fadingNodes",frame:()=>s.quadTreeStrategy._fadingNodes.size},{label:"createdNodes",frame:()=>s._createdNodesCount},{label:"indexesCache",frame:()=>s._indexesCacheToRemoveCounter},{label:"distBeforeMemClear",frame:()=>Math.round(s._distBeforeMemClear)},{label:"maxZoom/minZoom",frame:()=>s.quadTreeStrategy.maxCurrZoom+" / "+(null==s?void 0:s.quadTreeStrategy.minCurrZoom)},{label:"viewExtent",frame:()=>s.getViewExtent().toString()},{label:"Mouse distance, m",frame:()=>{let e=s.getCartesianFromMouseTerrain();return e?s.camera.eye.distance(e).toFixed(3):""}},{label:"lodSize",frame:()=>Math.round(s.quadTreeStrategy.lodSize)},{label:"deltaTime/FPS",frame:()=>`<div style="width:70px"><div style="width:20px; float: left;">\n ${Math.round(s.renderer.handler.deltaTime)}\n </div> <div style="float: left">\n ${Math.round(1e3/s.renderer.handler.deltaTime)}\n </div></div>`},{label:"-------------------------"},{label:"Pitch, deg",frame:()=>(s.camera.getPitch()*J).toFixed(2)},{label:"Yaw, deg",frame:()=>(s.camera.getYaw()*J).toFixed(2)},{label:"Roll, deg",frame:()=>(s.camera.getRoll()*J).toFixed(2)},{label:"Lon, Lat",frame:()=>`<div style="width:190px">${s.camera._lonLat.lon.toFixed(7)}, ${s.camera._lonLat.lon.toFixed(7)}</div>`},{label:"height/alt, m",frame:()=>`<div style="width:190px">${s.camera._lonLat.height.toFixed(2)+" / "+s.camera.getAltitude().toFixed(2)}</div>`},{label:"cam.slope",frame:()=>s.camera.slope.toFixed(3)},{label:"-------------------------"},{label:"_renderCompleted / renderCompletedActivated",frame:()=>`${s.quadTreeStrategy._renderCompleted} / ${s.quadTreeStrategy._renderCompletedActivated}`},{label:"_terrainCompleted / terrainCompletedActivated",frame:()=>`${s.quadTreeStrategy._terrainCompleted} / ${s.quadTreeStrategy._terrainCompletedActivated}`},{label:"PlainWorker",frame:()=>s._plainSegmentWorker.pendingQueue.length},{label:"TileLoader",frame:()=>`${s._tileLoader.loading} ${s._tileLoader.queue.length}`},{label:"TerrainLoader",frame:()=>s.terrain&&!s.terrain.isEmpty?`${s.terrain.loader.loading} ${s.terrain.loader.queue.length}`:""},{label:"TerrainWorker",frame:()=>s._terrainWorker.pendingQueue.length},{label:"NormalMapCreator",frame:()=>s._normalMapCreator.queueSize},{label:"VectorTileCreator",frame:()=>s._vectorTileCreator.queueSize}]);let r=new dt({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"});r.appendTo(t),r.events.on("change",(e=>{e?s.lockQuadTree():s.unlockQuadTree()}));let n=new dt({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"});n.appendTo(t),n.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:kn,DrawingSwitcher:class extends Q{constructor(e={}){super({name:"DrawingSwitcher",...e}),this.drawingControl=new kn(e)}oninit(){this.planet.addControl(this.drawingControl),this._createMenu()}onactivate(){this.drawingControl.activate()}ondeactivate(){this.drawingControl.deactivate()}_createMenu(){let e=new dt({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 dt({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 dt({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 jo({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:da,ElevationProfileControl:class extends Q{constructor(e={}){super({name:"ElevationProfileControl",...e}),this._onSceneChange=()=>{this._collectProfileThrottled()},this._onElevationProfilePointer=(e,t,i,s,r,n,o,a)=>{let l=this._elevationProfileScene.getPointLonLat(n),h=this._elevationProfileScene.getPointLonLat(n+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(_)),a)},this._onElevationProfileDblClick=(e,t,i,s,r,n,o,a)=>{let l=this._elevationProfileScene.getPointLonLat(n),h=this._elevationProfileScene.getPointLonLat(n+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 ih,this._elevationProfileView=new $l,this._elevationProfileLegend=new ah,this._elevationProfileButtonsView=new nh({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 Kt({title:"Elevation Profile",visible:!1,resizable:!0,useHide:!0,top:175,left:65,width:400,height:200,minHeight:100,minWidth:100}),this._graphView=new ut({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 oh({model:this._elevationProfileScene}),this._toggleBtn=new dt({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=yi((()=>{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.planet&&this._elevationProfileScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._elevationProfileScene)}ondeactivate(){this._poiListDialog.setVisibility(!1),this._elevationProfileView.model.clear(),this.renderer&&this.renderer.removeNode(this._elevationProfileScene),this._dialog.hide()}},FramebufferPreview:class extends Q{constructor(e){super({autoActivate:!0,...e}),this._onDraw=()=>{if(this._framebuffer&&this._screenFramebuffer){let e=this.renderer,t=e.handler.gl;t.disable(t.BLEND),this._screenFramebuffer.activate();let i=this._program._programController,s=i._program;t.bindBuffer(t.ARRAY_BUFFER,e.screenFramePositionBuffer),t.vertexAttribPointer(s.attributes.corners,2,t.FLOAT,!1,0,0),i.activate(),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._framebuffer.textures[this.framebufferCurrentTexture]),t.uniform1i(s.uniforms.inputTexture,0),t.drawArrays(t.TRIANGLE_STRIP,0,4),this._screenFramebuffer.deactivate(),t.enable(t.BLEND),this._screenFramebuffer.readPixelBuffersAsync((e=>{let t=e.getPixelBufferData();if(t){let i=e.width,s=e.height,r=this.$canvas.getContext("2d"),n=new Uint8ClampedArray(t.buffer,t.byteOffset,t.byteLength),o=new ImageData(n,i,s);createImageBitmap(o).then((e=>{r.clearRect(0,0,this.$canvas.width,this.$canvas.height),r.drawImage(e,0,0,this.$canvas.width,this.$canvas.height)}))}}))}},this._dialog=new Kt({title:e.title||"",width:580,height:340,left:100,top:100}),this.$canvas=function(e,t){let i=document.createElement("canvas");return i.width=e,i.height=t,i.style.position="absolute",i.style.width="100%",i.style.height="100%",i}(this._dialog.width,this._dialog.height),this._framebuffer=e.framebuffer||null,this._screenFramebuffer=null,this.framebufferCurrentTexture=0,this._program=function(e=0,t,i,s){return new X(`framebuffer_dialog_screen:${e.toString()}`,{uniforms:{inputTexture:"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 ${s?"tc.y = 1.0 - tc.y;":""} \n }`,fragmentShader:`#version 300 es\n\n precision highp float;\n\n uniform sampler2D inputTexture;\n \n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n\n ${t||""}\n \n ${i||"void mainImage(out vec4 fragColor, in vec2 fragCoord) { \n fragColor = texture(inputTexture, fragCoord);\n }"}\n \n void main(void) { \n mainImage(fragColor, tc);\n }`})}(this.__id,e.common,e.image,e.flippedUV)}bindFramebuffer(e){e.isEqual(this._framebuffer)||(this._framebuffer=e)}oninit(){var e,t;super.oninit(),this.renderer&&(this.renderer.handler.addProgram(this._program),this._screenFramebuffer=new Rt(this.renderer.handler,{width:null==(e=this._framebuffer)?void 0:e.width,height:null==(t=this._framebuffer)?void 0:t.height,useDepth:!1,targets:[{internalFormat:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT",readAsync:!0}]}),this._screenFramebuffer.init())}activate(){var e,t;super.activate(),this._dialog.appendTo(document.body),null==(e=this._dialog.container)||e.appendChild(this.$canvas),null==(t=this.renderer)||t.events.on("draw",this._onDraw)}deactivate(){var e;super.deactivate(),this._dialog.remove(),null==(e=this.renderer)||e.events.off("draw",this._onDraw)}},GeoImageDragControl:class extends Q{constructor(e={}){super(e),this._cornerIndex=-1,this._catchCorner=!1,this._toggleBtn=new dt({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 Ai&&(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 Ai&&(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.navigation.activate()}_onLDown(e){-1!==this._cornerIndex&&(this._catchCorner=!0,e.renderer.controls.navigation.deactivate())}_onMouseLeave(){document.body.style.cursor="auto"}_onMouseMove(e){let t=e.pickingObject;const i=this.planet;if(this._catchCorner){let s=t.getCornersLonLat();s[this._cornerIndex]=i.getLonLatFromPixelTerrain(e),t.setCornersLonLat(s)}else{this._cornerIndex=-1;for(let s=0;s<t._cornersWgs84.length;s++){let r=i.getLonLatFromPixelTerrain(e);if(r&&i.ellipsoid.getGreatCircleDistance(t._cornersWgs84[s],r)/i.getDistanceFromPixel(e)<=.05){this._cornerIndex=s,document.body.style.cursor="move";break}document.body.style.cursor="auto"}}}},GeoObjectEditor:class extends Q{constructor(e={}){super(e),this._geoObjectEditopScene=new gh({name:`geoObjectEditorScene:${this.__id}`}),this._dialog=new xh({model:this._geoObjectEditopScene})}oninit(){this.renderer&&(this.renderer.addControl(new Jn({planet:this.planet})),this._geoObjectEditopScene.bindPlanet(this.planet),this._dialog.appendTo(this.renderer.div||document.body),this.activate())}onactivate(){this.renderer&&this.renderer.addNode(this._geoObjectEditopScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._geoObjectEditopScene),this._dialog.hide()}},HeightRuler:Hn,KeyboardNavigation:class extends Q{constructor(e={}){e=e||{},super({name:"KeyboardNavigation",...e}),this.onCameraPitchUp=()=>{this._camera&&this._camera.setPitch(this._camera.getPitch()+.1*j)},this.onCameraPitchDown=()=>{this._camera&&this._camera.setPitch(this._camera.getPitch()-.1*j)},this.onCameraYawLeft=()=>{this._camera&&this._camera.setYaw(this._camera.getYaw()-.1*j)},this.onCameraYawRight=()=>{this._camera&&this._camera.setYaw(this._camera.getYaw()+.1*j)},this.onCameraMoveForward=()=>{this._camera&&this.force.addA(this._camera.getForward()).normalize()},this.onCameraMoveBackward=()=>{this._camera&&this.force.addA(this._camera.getBackward()).normalize()},this._camera=e.camera||null,this.speed=e.speed||10,this.force=new v,this.vel=new v,this.mass=1}bindCamera(e){this._camera=e}onactivate(){let e=this.renderer;e.events.on("keypress",W.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",W.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",W.KEY_UP,this.onCameraPitchUp,this),e.events.on("keypress",W.KEY_DOWN,this.onCameraPitchDown,this),e.events.on("keypress",W.KEY_LEFT,this.onCameraYawLeft,this),e.events.on("keypress",W.KEY_RIGHT,this.onCameraYawRight,this),e.events.on("draw",this.onDraw,this,-1e3)}ondeactivate(){this.renderer}oninit(){this.activate()}get dt(){return.001*this.renderer.handler.deltaTime}onDraw(){if(this.renderer&&this._camera){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(.96),this.force.set(0,0,0);let t=this._camera;t.eye=t.eye.add(this.vel.scaleTo(this.dt)),t.update()}}},LayerAnimation:class extends Q{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 s=this._layersArr[this._currVisibleIndex];if(s){s.opacity=0,s.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=lt(Tl),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,s=i>this._layersArr.length?this._layersArr.length:i;e<s;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,s=i>this._layersArr.length?this._layersArr.length:i;e<s;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){var t;this._layersArr.push(e),e.setVisibility(!1),e.setBaseLayer(!1),e.opacity=0,null==(t=this.planet)||t.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 s=this._currentIndex;this._currentIndex=e,this._playIndex=e;let r=this._getFrameIndex(s),n=this._getFrameIndex(this._currentIndex),o=this._layersArr[s],a=this._layersArr[e],l=n!=r;l&&this._appendFrameToPlanet(n),o&&(o.isIdle?this._currVisibleIndex=s:(o.opacity=0,o.setVisibility(!1))),a&&(a.opacity=0,a.setVisibility(!0),requestAnimationFrame((()=>{if(a.isIdle||t){a.opacity=1,l&&this._removeFrameFromPlanet(r),o&&(o.opacity=0,o.setVisibility(!1));let e=this._layersArr[this._currVisibleIndex];e&&(e.opacity=0,e.setVisibility(!1))}})),i||this.events.dispatch(this.events.change,this._currentIndex,s))}}},LayerSwitcher:class extends Q{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 Kt({title:"Layer Switcher",top:15,useHide:!0,visible:!1,width:300,maxHeight:500}),this._panel=new ut({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 dt({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 Cl({model:e})}onactivate(){}ondeactivate(){this._dialog.hide()}},Lighting:class extends Q{constructor(e={}){super(e),this._selectedLayer=null,this._toggleBtn=new dt({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 Kt({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 ut({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 Z({label:"Max.opacity",max:5}),this._atmosphereMinOpacity=new Z({label:"Min.opacity",max:5}),this._simpleSkyBackgroundColorOne=new zn({label:"Color One"}),this._simpleSkyBackgroundColorTwo=new zn({label:"Color Two"}),this._gamma=new Z({label:"Gamma",max:5}),this._exposure=new Z({label:"Exposure",max:5}),this._night=new Z({label:"Nightlight",max:5}),this._opacity=new Z({label:"Opacity",max:1}),this._diffuse_r=new Z({label:"Diffuse R",max:5}),this._diffuse_g=new Z({label:"Diffuse G",max:5}),this._diffuse_b=new Z({label:"Diffuse B",max:5}),this._ambient_r=new Z({label:"Ambient R",max:5}),this._ambient_g=new Z({label:"Ambient G",max:5}),this._ambient_b=new Z({label:"Ambient B",max:5}),this._specular_r=new Z({label:"Specular R",max:.2}),this._specular_g=new Z({label:"Specular G",max:.2}),this._specular_b=new Z({label:"Specular B",max:.2}),this._shininess=new Z({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 dt({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 dt({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 s=new dt({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"});s.appendTo(e),s.events.on("change",(e=>{this.planet.lightEnabled=e}));let r=new dt({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 n=this.planet.renderer.controls.SimpleSkyBackground;n&&(this._simpleSkyBackgroundColorOne.value=n.colorOne,this._simpleSkyBackgroundColorTwo.value=n.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 s=e&&e._specular?e._specular:this.planet._specular;this._specular_r.value=s[0],this._specular_g.value=s[1],this._specular_b.value=s[2],this._shininess.value=s[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){}},Navigation:Yi,Object3dManager:class extends Q{constructor(e={}){super(e),this._onSelect=e=>{this._currentItem=e},this._onClick=e=>{if(!this.planet||!this._layer||!this._currentItem)return;let t=this.planet.getLonLatFromPixelTerrain(e.pos);if(t&&(this.renderer.setRelativeCenter(this.planet.camera.eye),this.renderer.events.isKeyPressed(W.KEY_CTRL))){let e=this._createEntity(this._currentItem,t);this._layer.add(e)}},this._layer=e.layer||null,this._currentItem=null,this._collection=new ln({collection:e.collection}),this._dialog=new Lh({model:this._collection})}oninit(){this.renderer&&(this._dialog.appendTo(this.renderer.div||document.body),this._dialog.events.on("select",this._onSelect),this.activate())}onactivate(){this._dialog.show(),this._initEvents()}ondeactivate(){this._dialog.hide(),this._clearEvents()}bindLayer(e){this._layer=e}_initEvents(){this.planet&&this.planet.renderer&&this.planet.renderer.events.on("lclick",this._onClick)}_clearEvents(){this.planet&&this.planet.renderer&&this.planet.renderer.events.off("lclick",this._onClick)}_createEntity(e,t){let i=e.name,s=e.scale,r=new G({lonlat:t,pitch:0,yaw:0,roll:0,scale:s});for(let t=0;t<e.objects.length;t++){let s=e.objects[t],n=new G({forceGlobalPosition:!0,forceGlobalRotation:!0,forceGlobalScale:!0,geoObject:{tag:`${i}:${t.toString()}`,object3d:s}});r.appendChild(n)}return r}},OldMouseNavigation:rn,Ruler:_a,RulerSwitcher:class extends Q{constructor(e={}){super({name:"RulerSwitcher",...e}),this.ruler=new Hn({ignoreTerrain:e.ignoreTerrain})}oninit(){this.planet.addControl(this.ruler),this._createMenuBtn()}onactivate(){this.ruler.activate()}ondeactivate(){this.ruler.deactivate()}_createMenuBtn(){let e=new dt({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:fa,Selection:class extends Q{constructor(e={}){super(e),this._selectorScene=new Dl({name:`selectionScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain,onSelect:e.onSelect,autoSelectionHide:e.autoSelectionHide}),this._toggleBtn=new dt({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 Q{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(){Ro("ogShowFpsControl",(1e3/this.renderer.handler.deltaTime).toFixed(1),this.renderer.handler.canvas.clientWidth-60,0)}},SimpleNavigation:class extends Q{constructor(e={}){super({name:"SimpleNavigation",autoActivate:!0,...e}),this.focusVel=0,this.focusForce=0,this._nx=0,this._ny=0,this._onMouseLeftButtonDown=e=>{if(this._active&&this.renderer){if(this.stop(),this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this._grabbedPoint=this.renderer.getCartesianFromPixel(e),this._grabbedScreenPoint.set(e.nx,e.ny),!this._grabbedPoint){let t=this.renderer.activeCamera,i=new v,s=new v(1,0,0),r=new v(0,0,1),n=new v;new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,s,r),n)===V.INSIDE&&(this._grabbedPoint=n)}this._grabbedPoint&&this._eye0.copy(this.renderer.activeCamera.eye)}},this._onMouseLeftButtonUp=e=>{this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.x===e.prev_x&&(e.y,e.prev_y)},this._onMouseLeftButtonHold=e=>{if(this.renderer&&this._grabbedPoint&&e.moving){let t=this.renderer.activeCamera;if(t.isOrthographic){let i=e.nx-this._grabbedScreenPoint.x,s=e.ny-this._grabbedScreenPoint.y,r=t.frustum,n=-(r.right-r.left)*i,o=(r.top-r.bottom)*s,a=t.getUp().scale(o),l=t.getRight().scale(n);t.eye=this._eye0.add(l.add(a))}else{let i,s,r=Math.abs(t.getForward().dot(v.UP)),n=this._grabbedPoint;r>.7?(i=v.add(n,v.LEFT),s=v.add(n,t.getRight())):(i=v.add(n,t.getRight()),s=v.add(n,v.UP));let o=new v;new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(n,i,s),o)===V.INSIDE&&(t.eye=t.eye.add(n.sub(o)))}t.update()}},this._onRHold=e=>{if(this._lookPos&&e.moving&&this.renderer){const t=this.renderer.activeCamera;this.renderer.controlsBag.scaleRot=1;let i=.5/t.eye.distance(this._lookPos)*j;i>.007?i=.007:i<.003&&(i=.003),t.rotateHorizontal(i*(e.x-e.prev_x),!1,this._lookPos,this._up),t.rotateVertical(i*(e.y-e.prev_y),this._lookPos),t.update()}},this._onRDown=e=>{if(this.renderer)if(this.stop(),this._lookPos=this.renderer.getCartesianFromPixel(e.pos),this._lookPos)this._up=v.UP;else{const t=this.renderer.activeCamera;let i=new vt(v.ZERO,v.UP),s=new V(t.eye,e.direction);this._lookPos=new v,s.hitPlaneRes(i,this._lookPos),this._up=v.UP}},this._onMouseWheel=e=>{if(this.renderer){let t=this.renderer.activeCamera;if(t.isOrthographic){let i=t.frustums[0],s=-(i.right-i.left)*(.5-e.nx),r=(i.top-i.bottom)*(.5-e.ny),n=t.getUp().scale(r),o=t.getRight().scale(s),a=t.eye.add(o.add(n));this._wheelPos=a.add(t.getForward()),this._wheelDist=1,this._nx=e.nx,this._ny=e.ny,this.focusForce=.05*e.wheelDelta}else{let i=this.renderer.getCartesianFromPixel(e);if(!i){i=new v;let s=new vt(v.ZERO,v.UP);new V(t.eye,e.direction).hitPlaneRes(s,i)}let s=i.sub(t.eye).normalize(),r=8*t.eye.distance(i);this.force.addA(s.scale(e.wheelDelta)).normalize().scale(r)}}},this.onCameraMoveForward=()=>{this.force.addA(this.renderer.activeCamera.getForward()).normalize()},this.onCameraMoveBackward=()=>{this.force.addA(this.renderer.activeCamera.getBackward()).normalize()},this.onCameraStrifeLeft=()=>{this.force.addA(this.renderer.activeCamera.getLeft()).normalize()},this.onCameraStrifeRight=()=>{this.force.addA(this.renderer.activeCamera.getRight()).normalize()},this.onCameraLookUp=()=>{this.renderer.activeCamera.update()},this.onCameraLookDown=()=>{this.renderer.activeCamera.update()},this.onCameraTurnLeft=()=>{this.renderer.activeCamera.update()},this.onCameraTurnRight=()=>{this.renderer.activeCamera.update()},this.onCameraRollLeft=()=>{this.renderer.activeCamera.update()},this.onCameraRollRight=()=>{this.renderer.activeCamera.update()},this.speed=e.speed||1,this.force=new v,this.vel=new v,this.mass=1,this._lookPos=void 0,this._grabbedPoint=void 0,this._grabbedScreenPoint=new H,this._up=null,this._eye0=new v,this._wheelDist=0,this._wheelPos=new v}oninit(){}onactivate(){super.onactivate();let e=this.renderer;e.activeCamera.isOrthographic&&e.getDepthMinDistanceAsync().then((t=>{e.activeCamera.focusDistance=t})),e.events.on("mousewheel",this._onMouseWheel),e.events.on("keypress",W.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",W.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",W.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",W.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",W.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",W.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",W.KEY_LEFT,this.onCameraTurnLeft,this),e.events.on("keypress",W.KEY_RIGHT,this.onCameraTurnRight,this),e.events.on("keypress",W.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",W.KEY_E,this.onCameraRollRight,this),e.events.on("rhold",this._onRHold,this),e.events.on("rdown",this._onRDown,this),e.events.on("lhold",this._onMouseLeftButtonHold),e.events.on("ldown",this._onMouseLeftButtonDown),e.events.on("lup",this._onMouseLeftButtonUp),e.events.on("draw",this.onDraw,this,-1e3)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("mousewheel",this._onMouseWheel),e.events.off("keypress",W.KEY_W,this.onCameraMoveForward),e.events.off("keypress",W.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",W.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",W.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",W.KEY_UP,this.onCameraLookUp),e.events.off("keypress",W.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",W.KEY_LEFT,this.onCameraTurnLeft),e.events.off("keypress",W.KEY_RIGHT,this.onCameraTurnRight),e.events.off("keypress",W.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",W.KEY_E,this.onCameraRollRight),e.events.off("rhold",this._onRHold),e.events.off("rdown",this._onRDown),e.events.off("lhold",this._onMouseLeftButtonHold),e.events.off("ldown",this._onMouseLeftButtonDown),e.events.off("lup",this._onMouseLeftButtonUp),e.events.off("draw",this.onDraw)}_handleMouseWheel(){let e=this.renderer.activeCamera;if(e.isOrthographic&&Math.abs(this.focusVel)>.01){e.eye=this._wheelPos.add(e.getBackward().scale(this._wheelDist)),e.focusDistance-=e.focusDistance*this.focusVel*this.dt;let t=e.frustums[0],i=(t.right-t.left)*(.5-this._nx),s=-(t.top-t.bottom)*(.5-this._ny),r=e.getUp().scale(s),n=e.getRight().scale(i);e.eye.addA(n.add(r)),e.update()}else this.vel.length()>.01&&(e.eye=e.eye.add(this.vel.scaleTo(this.dt)),e.update())}onDraw(){this._updateVel(),this._handleMouseWheel()}get dt(){return.001*this.renderer.handler.deltaTime}_updateVel(){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(.77),this.force.set(0,0,0),this.focusVel+=this.focusForce,this.focusVel*=.77,this.focusForce=0}stop(){this.focusVel=0,this.vel.clear()}},SimpleSkyBackground:ga,Sun:Dr,TimelineControl:class extends Q{constructor(e={}){super({name:"timeline",...e});let t=e.current||new Date,i=e.rangeStart||jn(t,-12),s=e.rangeEnd||jn(t,12);this._timelineView=new jl({rangeStart:i,rangeEnd:s,currentDate:t}),this._toggleBtn=new dt({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 Kt({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",(()=>{var e;null==(e=this.planet)||e.sun.stop(),this.renderer&&this.renderer.controls.navigation.deactivate()})),this._timelineView.events.on("stopdrag",(()=>{this.renderer&&this.renderer.controls.navigation.activate()})),this._timelineView.events.on("startdragcurrent",(()=>{var e;null==(e=this.planet)||e.sun.stop(),this.renderer&&this.renderer.controls.navigation.deactivate()})),this._timelineView.events.on("stopdragcurrent",(()=>{this.renderer&&this.renderer.controls.navigation.activate()}))}},ToggleWireframe:class extends Q{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",W.KEY_X,this.toogleWireframe,this),this._isActive&&this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP)}},TouchNavigation:pa,ZoomControl:ma},Symbol.toStringTag,{value:"Module"}));function Ke(e){return new Uint32Array(e)}function kh(e){let t=[],i=0,s=0,r=0;for(let n=1;n<e-1-1;n++){for(let o=1;o<e-1;o++)i=n*e+o,r=(n+1)*e,s=r+o,t.push(i,s);t.push(s,r+1)}return t.push(t[t.length-1],e*e-e),Ke(t)}function Ih(e,t){let i=[];const s=(e-1)/t,r=e*e-e;let n=0;for(let t=0;t<e-2;t++){t%s==0&&(n=t);let o=r-e*t-e+1,a=r-e*n;i.push(a,o)}return t===e-1&&(i.push(e),i.push(0)),Ke(i)}function zh(e,t){let i=[];const s=(e-1)/t;let r=0;for(let t=0;t<e-2;t++){t%s==0&&(r=t);let n=e+t+1,o=r;i.push(o,n)}return t===e-1&&(i.push(e-2),i.push(e-1)),Ke(i)}function Dh(e,t){let i=[];const s=(e-1)/t;let r=0;for(let t=0;t<e-2;t++){t%s==0&&(r=t);let n=e*(t+1)+e-2,o=e+e*r-1;i.push(o,n)}return t===e-1&&(i.push(e*(e-1)-1),i.push(e*e-1)),Ke(i)}function Fh(e,t){let i=[];const s=(e-1)/t;let r=0;const n=e*(e-1)-2,o=e*e-1;for(let t=0;t<e-2;t++){t%s==0&&(r=t);let e=n-t,a=o-r;i.push(a,e)}return t===e-1&&i.push(e*e-e+1),i.push(e*e-e),Ke(i)}function no(e){let t=[[],[],[],[]];for(let i=0;i<=e;i++){let s=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]=Ih(s,e),t[0][i][r]=zh(s,e),t[1][i][r]=Dh(s,e),t[2][i][r]=Fh(s,e)}}return t}function oo(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=kh(e+1)}return t}function Oh(e){let t=new Uint16Array((e+1)*(e+1)*2),i=0;for(let s=0;s<=e;s++)for(let r=0;r<=e;r++)t[i++]=r/e*65535,t[i++]=s/e*65535;return t}let Nh=new class{constructor(e=0){this._maxGridSize=e,this.centerIndexesTable=oo(this._maxGridSize),this.skirtsIndexesTable=no(this._maxGridSize)}get maxGridSize(){return this._maxGridSize}init(){this.centerIndexesTable=oo(this._maxGridSize),this.skirtsIndexesTable=no(this._maxGridSize)}setMaxGridSize(e){this._maxGridSize=e,this.init()}createSegmentIndexes(e,t){if(e){let s=this.centerIndexesTable[e],r=this.skirtsIndexesTable[3][e][t[3]],n=this.skirtsIndexesTable[0][e][t[0]],o=this.skirtsIndexesTable[1][e][t[1]],a=this.skirtsIndexesTable[2][e][t[2]],l=(i=s.length+r.length+n.length+o.length+a.length,new Uint32Array(i));return l.set(s,0),l.set(r,s.length),l.set(n,s.length+r.length),l.set(o,s.length+r.length+n.length),l.set(a,s.length+r.length+n.length+o.length),l}var i;return Ke([0,2,1,3])}initTextureCoordsTable(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=Oh(e)}return t}};function $i(){return Nh}function ao(){return new X("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",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"attribute vec3 aVertexPositionHigh;attribute vec3 aVertexPositionLow;attribute vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec4 uGlobalTextureCoord;uniform vec3 uNormalMapBias;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;varying vec4 vTextureCoord;varying vec3 v_vertex;varying vec3 cameraPosition;varying vec2 vGlobalTextureCoord;varying float v_height;void main(void){vec3 aVertexPosition=aVertexPositionHigh+aVertexPositionLow;vec3 nh=height*normalize(aVertexPosition);vTextureCoord.xy=aTextureCoord;vGlobalTextureCoord=uGlobalTextureCoord.xy+(uGlobalTextureCoord.zw-uGlobalTextureCoord.xy)*aTextureCoord;vTextureCoord.zw=uNormalMapBias.z*(aTextureCoord+uNormalMapBias.xy);cameraPosition=eyePositionHigh+eyePositionLow;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);v_height=height;v_vertex=aVertexPosition+nh;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"precision highp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t1=-b-sqrt(d);t2=-b+sqrt(d);return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);uniform vec4 specular;uniform vec3 diffuse;uniform vec3 ambient;uniform sampler2D uNormalMap;uniform sampler2D nightTexture;uniform sampler2D specularTexture;uniform sampler2D defaultTexture;uniform sampler2D samplerArr[SLICE_SIZE];uniform vec4 tileOffsetArr[SLICE_SIZE];uniform vec3 lightPosition;uniform float layerOpacityArr[SLICE_SIZE];uniform int samplerCount;uniform float nightTextureCoefficient;uniform float camHeight;varying vec4 vTextureCoord;varying vec3 v_vertex;varying vec3 cameraPosition;varying vec2 vGlobalTextureCoord;varying float v_height;vec3 sunPos;void main(void){sunPos=lightPosition;vec3 texNormal=texture2D(uNormalMap,vTextureCoord.zw).rgb;vec3 normal=normalize((texNormal-0.5)*2.0);float minH=1200000.0;float maxH=minH*3.0;float nightCoef=getLerpValue(minH,maxH,camHeight)*nightTextureCoefficient;vec3 lightDir=normalize(sunPos);vec3 viewDir=normalize(cameraPosition-v_vertex);float overGround=1.0-step(0.1,v_height);float shininess=texture2D(specularTexture,vGlobalTextureCoord.st).r*255.0*overGround;vec3 reflectionDirection=reflect(-lightDir,normal);float reflection=max(dot(reflectionDirection,viewDir),0.0);vec3 spec=specular.rgb*pow(reflection,specular.w)*shininess;float diffuseLightWeighting=max(dot(normal,lightDir),0.0);vec4 nightImageColor=texture2D(nightTexture,vGlobalTextureCoord.st);vec3 night=nightStep*(.18-diffuseLightWeighting*3.0)*nightImageColor.rgb*nightCoef;night*=overGround*step(0.0,night);vec4 lightWeighting=vec4(ambient+diffuse*diffuseLightWeighting+night,1.0);gl_FragColor=texture2D(defaultTexture,vTextureCoord.xy);if(samplerCount==0){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}vec4 src;blend(gl_FragColor,samplerArr[0],tileOffsetArr[0],layerOpacityArr[0]);if(samplerCount==1){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}blend(gl_FragColor,samplerArr[1],tileOffsetArr[1],layerOpacityArr[1]);if(samplerCount==2){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}blend(gl_FragColor,samplerArr[2],tileOffsetArr[2],layerOpacityArr[2]);if(samplerCount==3){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}blend(gl_FragColor,samplerArr[3],tileOffsetArr[3],layerOpacityArr[3]);if(samplerCount==4){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}blend(gl_FragColor,samplerArr[4],tileOffsetArr[4],layerOpacityArr[4]);gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);}"})}function lo(e){return new X("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",lightPosition:"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\nprecision highp float;in vec3 aVertexPositionHigh;in vec3 aVertexPositionLow;in vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec4 uGlobalTextureCoord;uniform vec3 uNormalMapBias;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;out vec4 vTextureCoord;out vec3 v_vertex;out vec3 cameraPosition;out vec2 vGlobalTextureCoord;out float v_height;void main(void){vec3 aVertexPosition=aVertexPositionHigh+aVertexPositionLow;vec3 nh=height*normalize(aVertexPosition);vTextureCoord.xy=aTextureCoord;vGlobalTextureCoord=uGlobalTextureCoord.xy+(uGlobalTextureCoord.zw-uGlobalTextureCoord.xy)*aTextureCoord;vTextureCoord.zw=uNormalMapBias.z*(aTextureCoord+uNormalMapBias.xy);cameraPosition=eyePositionHigh+eyePositionLow;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);v_height=height;v_vertex=aVertexPosition+nh;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:di("#version 300 es\nprecision highp float;\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t1=-b-sqrt(d);t2=-b+sqrt(d);return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#define PI 3.1415926538\n#define ATMOS_HEIGHT float(${ATMOS_HEIGHT})\n#define RAYLEIGH_SCALE float(${RAYLEIGH_SCALE})\n#define MIE_SCALE float(${MIE_SCALE})\n#define SAMPLE_COUNT 16\n#define SQRT_SAMPLE_COUNT 4\nconst float GROUND_ALBEDO=float(${GROUND_ALBEDO})/PI;const float BOTTOM_RADIUS=float(${BOTTOM_RADIUS});const float TOP_RADIUS=BOTTOM_RADIUS+ATMOS_HEIGHT;const float EQUATORIAL_RADIUS=float(${EQUATORIAL_RADIUS});const vec3 bottomRadii=vec3(EQUATORIAL_RADIUS,EQUATORIAL_RADIUS,BOTTOM_RADIUS);const vec3 topRadii=bottomRadii+ATMOS_HEIGHT;const vec3 SPHERE_TO_ELLIPSOID_SCALE=vec3(BOTTOM_RADIUS)/bottomRadii;const vec2 rayleighMieHeights=vec2(RAYLEIGH_SCALE,MIE_SCALE)*ATMOS_HEIGHT;const vec3 rayleighScatteringCoefficient=vec3(float(${rayleighScatteringCoefficient_0}),float(${rayleighScatteringCoefficient_1}),float(${rayleighScatteringCoefficient_2}))*1e-6;const float mieScatteringCoefficient=float(${mieScatteringCoefficient})*1e-6;const float mieExtinctionCoefficient=float(${mieExtinctionCoefficient})*1e-6;const vec3 ozoneAbsorptionCoefficient=vec3(float(${ozoneAbsorptionCoefficient_0}),float(${ozoneAbsorptionCoefficient_1}),float(${ozoneAbsorptionCoefficient_2}))*1e-6;const float SUN_ANGULAR_RADIUS=float(${SUN_ANGULAR_RADIUS});const float SUN_INTENSITY=float(${SUN_INTENSITY});const float ozoneDensityHeight=float(${ozoneDensityHeight});const float ozoneDensityWide=float(${ozoneDensityWide});vec3 sunWithBloom(vec3 rayDir,vec3 sunDir){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}vec3 sunWithBloomScaled(vec3 rayDir,vec3 sunDir,float angularScale){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS*angularScale);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}float rayleighPhase(float angle){return 3.0/(16.0*PI)*(1.0+(angle*angle));}float miePhase(float angle){float g=0.8;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));}vec3 opticalDepth(float height,float angle){vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 rayDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);float t1,t2;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,t1,t2);float segmentLength=t2/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 opticalDepth=vec3(0.0);for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;opticalDepth.xy+=exp(-height/rayleighMieHeights)*segmentLength;opticalDepth.z+=(1.0-min(abs(height-ozoneDensityHeight)/ozoneDensityWide,1.0))*segmentLength;t+=segmentLength;}return opticalDepth;}vec3 transmittance(float height,float angle){vec3 opticalDepth=opticalDepth(height,angle);return exp(-(rayleighScatteringCoefficient*opticalDepth.x+mieExtinctionCoefficient*opticalDepth.y+ozoneAbsorptionCoefficient*opticalDepth.z));}uniform vec4 specular;uniform vec3 diffuse;uniform vec3 ambient;uniform vec3 lightPosition;uniform sampler2D uNormalMap;uniform sampler2D nightTexture;uniform sampler2D specularTexture;uniform sampler2D transmittanceTexture;uniform sampler2D scatteringTexture;uniform sampler2D defaultTexture;uniform sampler2D samplerArr[SLICE_SIZE];uniform vec4 tileOffsetArr[SLICE_SIZE];uniform float layerOpacityArr[SLICE_SIZE];uniform int samplerCount;uniform float nightTextureCoefficient;uniform vec2 maxMinOpacity;uniform float camHeight;uniform float transitionOpacity;in vec4 vTextureCoord;in vec3 v_vertex;in vec3 cameraPosition;in vec2 vGlobalTextureCoord;in float v_height;vec3 sunPos;layout(location=0)out vec4 diffuseColor;vec3 transmittanceFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture(transmittanceTexture,vec2(u,v)).xyz;}vec3 multipleScatteringContributionFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture(scatteringTexture,vec2(u,v)).xyz;}void getSunIlluminance(in vec3 point,in vec3 lightDir,out vec3 sunIlluminance){float mu_s=dot(normalize(point),lightDir);float height=length(point)-BOTTOM_RADIUS;sunIlluminance=SUN_INTENSITY*transmittanceFromTexture(height,mu_s);}void atmosGroundColor(out vec4 fragColor,in vec3 normal){vec3 cameraPosition=cameraPosition;if(length(cameraPosition*SPHERE_TO_ELLIPSOID_SCALE)<BOTTOM_RADIUS+1.0){cameraPosition=normalize(cameraPosition*SPHERE_TO_ELLIPSOID_SCALE)*(BOTTOM_RADIUS+1.0)/SPHERE_TO_ELLIPSOID_SCALE;}vec3 rayDirection=normalize(v_vertex-cameraPosition);vec3 lightDir=normalize(sunPos);rayDirection=normalize(rayDirection*SPHERE_TO_ELLIPSOID_SCALE);vec3 camPos=cameraPosition*SPHERE_TO_ELLIPSOID_SCALE;lightDir=normalize(lightDir*SPHERE_TO_ELLIPSOID_SCALE);vec3 light=vec3(0.0);vec3 transmittanceFromCameraToSpace=vec3(1.0);float offset=0.0;float distanceToSpace=0.0;intersectSphere(camPos,rayDirection,TOP_RADIUS,offset,distanceToSpace);vec3 rayOrigin=camPos;if(offset>0.0){rayOrigin+=rayDirection*offset;}float height=length(rayOrigin)-BOTTOM_RADIUS;float rayAngle=dot(rayOrigin,rayDirection)/length(rayOrigin);bool cameraBelow=rayAngle<0.0;transmittanceFromCameraToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);float phaseAngle=dot(lightDir,rayDirection);float rayleighPhase=rayleighPhase(phaseAngle);float miePhase=miePhase(phaseAngle);float distanceToGround=0.0;bool hitGround=intersectSphere(camPos,rayDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>0.0;if(length(v_vertex*SPHERE_TO_ELLIPSOID_SCALE)>BOTTOM_RADIUS){distanceToGround=distance(camPos,v_vertex*SPHERE_TO_ELLIPSOID_SCALE);}float segmentLength=(distanceToGround-max(offset,0.0))/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 transmittanceCamera;vec3 transmittanceLight;for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;vec3 up=position/length(position);float rayAngle=dot(up,rayDirection);float lightAngle=dot(up,lightDir);vec3 transmittanceToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);transmittanceCamera=cameraBelow ?(transmittanceToSpace/transmittanceFromCameraToSpace):(transmittanceFromCameraToSpace/transmittanceToSpace);transmittanceLight=transmittanceFromTexture(height,lightAngle);vec2 opticalDensity=exp(-height/rayleighMieHeights);vec3 scatteredLight=transmittanceLight*(rayleighScatteringCoefficient*opticalDensity.x*rayleighPhase+mieScatteringCoefficient*opticalDensity.y*miePhase);scatteredLight+=multipleScatteringContributionFromTexture(height,lightAngle)*(rayleighScatteringCoefficient*opticalDensity.x+mieScatteringCoefficient*opticalDensity.y);light+=transmittanceCamera*scatteredLight*segmentLength;t+=segmentLength;}light*=SUN_INTENSITY;vec3 hitPoint=camPos+rayDirection*distanceToGround;vec3 up=normalize(hitPoint);float diffuseAngle=max(dot(up,lightDir),0.0);float lightAngle=dot(normal,lightDir);vec3 tA=transmittanceCamera*GROUND_ALBEDO*SUN_INTENSITY;vec3 scatteringLight=multipleScatteringContributionFromTexture(height,lightAngle);vec3 diffuseTransmittanceLight=transmittanceLight*diffuseAngle;light+=tA*(scatteringLight+diffuseTransmittanceLight);fragColor=vec4(pow(light*8.0,vec3(1.0/2.2)),1.0);}void getAtmosFadingOpacity(out float opacity){float c=length(cameraPosition);float maxDist=sqrt(c*c-BOTTOM_RADIUS*BOTTOM_RADIUS);float minDist=c-BOTTOM_RADIUS;float vertDist=distance(cameraPosition,v_vertex);opacity=clamp(maxMinOpacity.y+(maxMinOpacity.x-maxMinOpacity.y)*getLerpValue(minDist,maxDist,vertDist),0.0,1.0);}void main(void){sunPos=lightPosition;vec3 texNormal=texture(uNormalMap,vTextureCoord.zw).rgb;vec3 normal=normalize((texNormal-0.5)*2.0);float minH=1200000.0;float maxH=minH*3.0;float nightCoef=getLerpValue(minH,maxH,camHeight)*nightTextureCoefficient;vec3 lightDir=normalize(sunPos);vec3 viewDir=normalize(cameraPosition-v_vertex);vec4 atmosColor;atmosGroundColor(atmosColor,normal);vec3 sunIlluminance;getSunIlluminance(v_vertex*SPHERE_TO_ELLIPSOID_SCALE,lightDir*SPHERE_TO_ELLIPSOID_SCALE,sunIlluminance);float overGround=1.0-step(0.1,v_height);float shininess=texture(specularTexture,vGlobalTextureCoord.st).r*255.0*overGround;vec3 reflectionDirection=reflect(-lightDir,normal);float reflection=max(dot(reflectionDirection,viewDir),0.0);vec3 spec=sunIlluminance*specular.rgb*pow(reflection,specular.w)*shininess;float diffuseLightWeighting=max(dot(normal,lightDir),0.0);vec4 nightImageColor=texture(nightTexture,vGlobalTextureCoord.st);vec3 night=nightStep*(.18-diffuseLightWeighting*3.0)*nightImageColor.rgb*nightCoef;night*=overGround*step(0.0,night);vec4 lightWeighting=vec4(ambient+sunIlluminance*diffuse*diffuseLightWeighting+night,1.0);float fadingOpacity;getAtmosFadingOpacity(fadingOpacity);getSunIlluminance(cameraPosition,viewDir*SPHERE_TO_ELLIPSOID_SCALE,sunIlluminance);spec*=sunIlluminance;diffuseColor=texture(defaultTexture,vTextureCoord.xy);if(samplerCount==0){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}vec4 src;blend(diffuseColor,samplerArr[0],tileOffsetArr[0],layerOpacityArr[0]);if(samplerCount==1){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[1],tileOffsetArr[1],layerOpacityArr[1]);if(samplerCount==2){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[2],tileOffsetArr[2],layerOpacityArr[2]);if(samplerCount==3){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[3],tileOffsetArr[3],layerOpacityArr[3]);if(samplerCount==4){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[4],tileOffsetArr[4],layerOpacityArr[4]);diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;}",e)})}const er={ATMOS_HEIGHT:1e5,RAYLEIGH_SCALE:.08,MIE_SCALE:.012,GROUND_ALBEDO:.05,BOTTOM_RADIUS:6356752.314245179,EQUATORIAL_RADIUS:6378137,rayleighScatteringCoefficient_0:5.802,rayleighScatteringCoefficient_1:13.558,rayleighScatteringCoefficient_2:33.1,mieScatteringCoefficient:3.996,mieExtinctionCoefficient:4.44,ozoneAbsorptionCoefficient_0:.65,ozoneAbsorptionCoefficient_1:1.881,ozoneAbsorptionCoefficient_2:.085,SUN_ANGULAR_RADIUS:.004685,SUN_INTENSITY:1,ozoneDensityHeight:25e3,ozoneDensityWide:15e3,disableSunDisk:!1};var Hh="attribute vec2 corners;void main(void){gl_Position=vec4(corners,0.0,1.0);}",Vh="precision lowp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t1=-b-sqrt(d);t2=-b+sqrt(d);return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#define PI 3.1415926538\n#define ATMOS_HEIGHT float(${ATMOS_HEIGHT})\n#define RAYLEIGH_SCALE float(${RAYLEIGH_SCALE})\n#define MIE_SCALE float(${MIE_SCALE})\n#define SAMPLE_COUNT 16\n#define SQRT_SAMPLE_COUNT 4\nconst float GROUND_ALBEDO=float(${GROUND_ALBEDO})/PI;const float BOTTOM_RADIUS=float(${BOTTOM_RADIUS});const float TOP_RADIUS=BOTTOM_RADIUS+ATMOS_HEIGHT;const float EQUATORIAL_RADIUS=float(${EQUATORIAL_RADIUS});const vec3 bottomRadii=vec3(EQUATORIAL_RADIUS,EQUATORIAL_RADIUS,BOTTOM_RADIUS);const vec3 topRadii=bottomRadii+ATMOS_HEIGHT;const vec3 SPHERE_TO_ELLIPSOID_SCALE=vec3(BOTTOM_RADIUS)/bottomRadii;const vec2 rayleighMieHeights=vec2(RAYLEIGH_SCALE,MIE_SCALE)*ATMOS_HEIGHT;const vec3 rayleighScatteringCoefficient=vec3(float(${rayleighScatteringCoefficient_0}),float(${rayleighScatteringCoefficient_1}),float(${rayleighScatteringCoefficient_2}))*1e-6;const float mieScatteringCoefficient=float(${mieScatteringCoefficient})*1e-6;const float mieExtinctionCoefficient=float(${mieExtinctionCoefficient})*1e-6;const vec3 ozoneAbsorptionCoefficient=vec3(float(${ozoneAbsorptionCoefficient_0}),float(${ozoneAbsorptionCoefficient_1}),float(${ozoneAbsorptionCoefficient_2}))*1e-6;const float SUN_ANGULAR_RADIUS=float(${SUN_ANGULAR_RADIUS});const float SUN_INTENSITY=float(${SUN_INTENSITY});const float ozoneDensityHeight=float(${ozoneDensityHeight});const float ozoneDensityWide=float(${ozoneDensityWide});vec3 sunWithBloom(vec3 rayDir,vec3 sunDir){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}vec3 sunWithBloomScaled(vec3 rayDir,vec3 sunDir,float angularScale){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS*angularScale);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}float rayleighPhase(float angle){return 3.0/(16.0*PI)*(1.0+(angle*angle));}float miePhase(float angle){float g=0.8;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));}vec3 opticalDepth(float height,float angle){vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 rayDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);float t1,t2;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,t1,t2);float segmentLength=t2/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 opticalDepth=vec3(0.0);for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;opticalDepth.xy+=exp(-height/rayleighMieHeights)*segmentLength;opticalDepth.z+=(1.0-min(abs(height-ozoneDensityHeight)/ozoneDensityWide,1.0))*segmentLength;t+=segmentLength;}return opticalDepth;}vec3 transmittance(float height,float angle){vec3 opticalDepth=opticalDepth(height,angle);return exp(-(rayleighScatteringCoefficient*opticalDepth.x+mieExtinctionCoefficient*opticalDepth.y+ozoneAbsorptionCoefficient*opticalDepth.z));}\n#define DISABLE_SUN_DISK ${ disableSunDisk }\nuniform mat4 viewMatrix;uniform vec3 sunPos;uniform vec3 camPos;uniform vec2 iResolution;uniform float fov;uniform float opacity;uniform float isOrthographic;uniform vec4 frustumParams;uniform sampler2D transmittanceTexture;uniform sampler2D scatteringTexture;float valueHSV(vec3 rgb){return max(max(rgb.r,rgb.g),rgb.b);}vec3 transmittanceFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture2D(transmittanceTexture,vec2(u,v)).xyz;}vec3 multipleScatteringContributionFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture2D(scatteringTexture,vec2(u,v)).xyz;}bool intersectEllipsoidToSphere(in vec3 ro,in vec3 rd,in vec3 ellRadii,in float sphereRadius,out float t1,out float t2){float offset=0.0,distanceToSpace=0.0;if(intersectEllipsoid(ro,rd,ellRadii,offset,distanceToSpace)){vec3 hitEll=ro+rd*offset;vec3 nEll=normalEllipsoid(hitEll,ellRadii);float t=0.0;bool intersectsSphere=intersectSphere(hitEll,nEll,sphereRadius,t);vec3 hitSphere=hitEll+nEll*t;t1=length(hitSphere-ro);hitEll=ro+rd*distanceToSpace;nEll=normalEllipsoid(hitEll,ellRadii);t=0.0;intersectsSphere=intersectSphere(hitEll,nEll,sphereRadius,t);hitSphere=hitEll+nEll*t;t2=length(hitSphere-ro);return true;}return false;}mat4 transpose(in mat4 m){vec4 i0=m[0];vec4 i1=m[1];vec4 i2=m[2];vec4 i3=m[3];mat4 outMatrix=mat4(vec4(i0.x,i1.x,i2.x,i3.x),vec4(i0.y,i1.y,i2.y,i3.y),vec4(i0.z,i1.z,i2.z,i3.z),vec4(i0.w,i1.w,i2.w,i3.w));return outMatrix;}void mainImage(out vec4 fragColor){vec3 cameraPosition=camPos;vec3 lightDirection=normalize(sunPos);vec2 uv=(2.0*gl_FragCoord.xy-iResolution.xy)/iResolution.y;vec3 rayDirection;if(isOrthographic!=0.0){float px=uv.x*iResolution.y/iResolution.x;float py=uv.y;float dx=0.5*frustumParams.x*px;float dy=0.5*frustumParams.y*py;mat4 viewMatrixT=transpose(viewMatrix);vec3 right=normalize(viewMatrixT[0].xyz);vec3 up=normalize(viewMatrixT[1].xyz);vec3 backward=normalize(viewMatrixT[2].xyz);vec3 forward=-backward;rayDirection=forward;cameraPosition=cameraPosition+right*dx+up*dy;}else{float fieldOfView=fov;float z=1.0/tan(fieldOfView*0.5*PI/180.0);rayDirection=normalize(vec3(uv,-z));vec4 rd=transpose(viewMatrix)*vec4(rayDirection,1.0);rayDirection=rd.xyz;}vec3 light=vec3(0.0);vec3 transmittanceFromCameraToSpace=vec3(1.0);float offset=0.0;float distanceToSpace=0.0;rayDirection=normalize(rayDirection*SPHERE_TO_ELLIPSOID_SCALE);cameraPosition*=SPHERE_TO_ELLIPSOID_SCALE;lightDirection=normalize(lightDirection*SPHERE_TO_ELLIPSOID_SCALE);if(length(cameraPosition)<BOTTOM_RADIUS+100.0){cameraPosition=normalize(cameraPosition)*(BOTTOM_RADIUS+100.0);}if(intersectSphere(cameraPosition,rayDirection,TOP_RADIUS,offset,distanceToSpace)){vec3 rayOrigin=cameraPosition;if(offset>0.0){rayOrigin=cameraPosition+rayDirection*offset;}float height=length(rayOrigin)-BOTTOM_RADIUS;float rayAngle=dot(rayOrigin,rayDirection)/length(rayOrigin);bool cameraBelow=rayAngle<0.0;transmittanceFromCameraToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);float phaseAngle=dot(lightDirection,rayDirection);float rayleighPhase=rayleighPhase(phaseAngle);float miePhase=miePhase(phaseAngle);float distanceToGround=0.0;bool hitGround=intersectSphere(cameraPosition,rayDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>0.0;if(intersectSphere(cameraPosition,rayDirection,BOTTOM_RADIUS-100000.0,distanceToGround)&&hitGround){fragColor=vec4(0.47,0.47,0.5,1.0);return;}float segmentLength=abs(((hitGround ? distanceToGround : distanceToSpace)-max(offset,0.0))/float(SAMPLE_COUNT));float t=segmentLength*0.5;vec3 transmittanceCamera;vec3 transmittanceLight;for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;vec3 up=position/length(position);float rayAngle=dot(up,rayDirection);float lightAngle=dot(up,lightDirection);vec3 transmittanceToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);transmittanceCamera=cameraBelow ?(transmittanceToSpace/transmittanceFromCameraToSpace):(transmittanceFromCameraToSpace/transmittanceToSpace);transmittanceLight=transmittanceFromTexture(height,lightAngle);vec2 opticalDensity=exp(-height/rayleighMieHeights);vec3 scatteredLight=transmittanceLight*(rayleighScatteringCoefficient*opticalDensity.x*rayleighPhase+mieScatteringCoefficient*opticalDensity.y*miePhase);scatteredLight+=multipleScatteringContributionFromTexture(height,lightAngle)*(rayleighScatteringCoefficient*opticalDensity.x+mieScatteringCoefficient*opticalDensity.y);light+=transmittanceCamera*scatteredLight*segmentLength;t+=segmentLength;}light*=SUN_INTENSITY;if(hitGround){vec3 hitPoint=cameraPosition+rayDirection*distanceToGround;vec3 up=hitPoint/length(hitPoint);float diffuseAngle=max(dot(up,lightDirection),0.0);float lightAngle=dot(up,lightDirection);light+=transmittanceCamera*GROUND_ALBEDO*multipleScatteringContributionFromTexture(height,lightAngle)*SUN_INTENSITY;light+=transmittanceCamera*transmittanceLight*GROUND_ALBEDO*diffuseAngle*SUN_INTENSITY;}}\n#if !DISABLE_SUN_DISK\n{float distanceToGround=0.0;bool hitGround=intersectSphere(cameraPosition,rayDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>0.0;if(!hitGround){vec3 sunLum;if(isOrthographic!=0.0){float z=1.0/tan(fov*0.5*PI/180.0);vec3 viewRay=normalize(vec3(uv,-z));vec4 rd=transpose(viewMatrix)*vec4(viewRay,1.0);vec3 pseudoRayDirection=normalize(rd.xyz);const float sunOrthoAngularScale=2.0;sunLum=sunWithBloomScaled(pseudoRayDirection,lightDirection,sunOrthoAngularScale)*vec3(1.0,1.0,0.8);}else{sunLum=sunWithBloom(rayDirection,lightDirection)*vec3(1.0,1.0,0.8);}sunLum=smoothstep(0.002,1.0,sunLum);light+=sunLum*SUN_INTENSITY*transmittanceFromCameraToSpace;}}\n#endif\nvec4 color=vec4(pow(opacity*light*8.0,vec3(1.0/2.2)),valueHSV(light)*clamp(opacity,0.0,1.0));fragColor=color;}void main(void){mainImage(gl_FragColor);}";class Uh extends Q{constructor(e={}){super({name:"Atmosphere",...e}),this._transmittanceBuffer=null,this._scatteringBuffer=null,this.opacity=1;const t=e;this._parameters=JSON.parse(JSON.stringify({...er,...t}))}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(){var e;null==(e=this.planet)||e.initAtmosphereShader(this._parameters)}oninit(){this.renderer&&(this._initLookupTextures(),this.initLookupTexturesShaders(),this.drawLookupTextures(),this.removeLookupTexturesShaders(),this.initBackgroundShader(),this.activate())}initLookupTexturesShaders(){var e,t;this.renderer&&(this.renderer.handler.addProgram((e=this._parameters,new X("transmittance",{uniforms:{iResolution:"vec2"},attributes:{a_position:"vec2"},vertexShader:"attribute vec2 a_position;void main(void){gl_Position=vec4(a_position,0.0,1.0);}",fragmentShader:di("precision highp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t1=-b-sqrt(d);t2=-b+sqrt(d);return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#define PI 3.1415926538\n#define ATMOS_HEIGHT float(${ATMOS_HEIGHT})\n#define RAYLEIGH_SCALE float(${RAYLEIGH_SCALE})\n#define MIE_SCALE float(${MIE_SCALE})\n#define SAMPLE_COUNT 16\n#define SQRT_SAMPLE_COUNT 4\nconst float GROUND_ALBEDO=float(${GROUND_ALBEDO})/PI;const float BOTTOM_RADIUS=float(${BOTTOM_RADIUS});const float TOP_RADIUS=BOTTOM_RADIUS+ATMOS_HEIGHT;const float EQUATORIAL_RADIUS=float(${EQUATORIAL_RADIUS});const vec3 bottomRadii=vec3(EQUATORIAL_RADIUS,EQUATORIAL_RADIUS,BOTTOM_RADIUS);const vec3 topRadii=bottomRadii+ATMOS_HEIGHT;const vec3 SPHERE_TO_ELLIPSOID_SCALE=vec3(BOTTOM_RADIUS)/bottomRadii;const vec2 rayleighMieHeights=vec2(RAYLEIGH_SCALE,MIE_SCALE)*ATMOS_HEIGHT;const vec3 rayleighScatteringCoefficient=vec3(float(${rayleighScatteringCoefficient_0}),float(${rayleighScatteringCoefficient_1}),float(${rayleighScatteringCoefficient_2}))*1e-6;const float mieScatteringCoefficient=float(${mieScatteringCoefficient})*1e-6;const float mieExtinctionCoefficient=float(${mieExtinctionCoefficient})*1e-6;const vec3 ozoneAbsorptionCoefficient=vec3(float(${ozoneAbsorptionCoefficient_0}),float(${ozoneAbsorptionCoefficient_1}),float(${ozoneAbsorptionCoefficient_2}))*1e-6;const float SUN_ANGULAR_RADIUS=float(${SUN_ANGULAR_RADIUS});const float SUN_INTENSITY=float(${SUN_INTENSITY});const float ozoneDensityHeight=float(${ozoneDensityHeight});const float ozoneDensityWide=float(${ozoneDensityWide});vec3 sunWithBloom(vec3 rayDir,vec3 sunDir){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}vec3 sunWithBloomScaled(vec3 rayDir,vec3 sunDir,float angularScale){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS*angularScale);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}float rayleighPhase(float angle){return 3.0/(16.0*PI)*(1.0+(angle*angle));}float miePhase(float angle){float g=0.8;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));}vec3 opticalDepth(float height,float angle){vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 rayDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);float t1,t2;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,t1,t2);float segmentLength=t2/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 opticalDepth=vec3(0.0);for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;opticalDepth.xy+=exp(-height/rayleighMieHeights)*segmentLength;opticalDepth.z+=(1.0-min(abs(height-ozoneDensityHeight)/ozoneDensityWide,1.0))*segmentLength;t+=segmentLength;}return opticalDepth;}vec3 transmittance(float height,float angle){vec3 opticalDepth=opticalDepth(height,angle);return exp(-(rayleighScatteringCoefficient*opticalDepth.x+mieExtinctionCoefficient*opticalDepth.y+ozoneAbsorptionCoefficient*opticalDepth.z));}uniform vec2 iResolution;void main(void){vec2 uv=gl_FragCoord.xy/iResolution.xy;float height=uv.y*ATMOS_HEIGHT;float angle=uv.x*2.0-1.0;gl_FragColor=vec4(transmittance(height,angle),1.0);}",e||er)}))),this.renderer.handler.addProgram((t=this._parameters,new X("scattering",{uniforms:{iResolution:"vec2",transmittanceTexture:"sampler2d"},attributes:{a_position:"vec2"},vertexShader:"attribute vec2 a_position;void main(void){gl_Position=vec4(a_position,0.0,1.0);}",fragmentShader:di("precision highp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t1=-b-sqrt(d);t2=-b+sqrt(d);return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#define PI 3.1415926538\n#define ATMOS_HEIGHT float(${ATMOS_HEIGHT})\n#define RAYLEIGH_SCALE float(${RAYLEIGH_SCALE})\n#define MIE_SCALE float(${MIE_SCALE})\n#define SAMPLE_COUNT 16\n#define SQRT_SAMPLE_COUNT 4\nconst float GROUND_ALBEDO=float(${GROUND_ALBEDO})/PI;const float BOTTOM_RADIUS=float(${BOTTOM_RADIUS});const float TOP_RADIUS=BOTTOM_RADIUS+ATMOS_HEIGHT;const float EQUATORIAL_RADIUS=float(${EQUATORIAL_RADIUS});const vec3 bottomRadii=vec3(EQUATORIAL_RADIUS,EQUATORIAL_RADIUS,BOTTOM_RADIUS);const vec3 topRadii=bottomRadii+ATMOS_HEIGHT;const vec3 SPHERE_TO_ELLIPSOID_SCALE=vec3(BOTTOM_RADIUS)/bottomRadii;const vec2 rayleighMieHeights=vec2(RAYLEIGH_SCALE,MIE_SCALE)*ATMOS_HEIGHT;const vec3 rayleighScatteringCoefficient=vec3(float(${rayleighScatteringCoefficient_0}),float(${rayleighScatteringCoefficient_1}),float(${rayleighScatteringCoefficient_2}))*1e-6;const float mieScatteringCoefficient=float(${mieScatteringCoefficient})*1e-6;const float mieExtinctionCoefficient=float(${mieExtinctionCoefficient})*1e-6;const vec3 ozoneAbsorptionCoefficient=vec3(float(${ozoneAbsorptionCoefficient_0}),float(${ozoneAbsorptionCoefficient_1}),float(${ozoneAbsorptionCoefficient_2}))*1e-6;const float SUN_ANGULAR_RADIUS=float(${SUN_ANGULAR_RADIUS});const float SUN_INTENSITY=float(${SUN_INTENSITY});const float ozoneDensityHeight=float(${ozoneDensityHeight});const float ozoneDensityWide=float(${ozoneDensityWide});vec3 sunWithBloom(vec3 rayDir,vec3 sunDir){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}vec3 sunWithBloomScaled(vec3 rayDir,vec3 sunDir,float angularScale){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS*angularScale);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}float rayleighPhase(float angle){return 3.0/(16.0*PI)*(1.0+(angle*angle));}float miePhase(float angle){float g=0.8;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));}vec3 opticalDepth(float height,float angle){vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 rayDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);float t1,t2;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,t1,t2);float segmentLength=t2/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 opticalDepth=vec3(0.0);for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;opticalDepth.xy+=exp(-height/rayleighMieHeights)*segmentLength;opticalDepth.z+=(1.0-min(abs(height-ozoneDensityHeight)/ozoneDensityWide,1.0))*segmentLength;t+=segmentLength;}return opticalDepth;}vec3 transmittance(float height,float angle){vec3 opticalDepth=opticalDepth(height,angle);return exp(-(rayleighScatteringCoefficient*opticalDepth.x+mieExtinctionCoefficient*opticalDepth.y+ozoneAbsorptionCoefficient*opticalDepth.z));}uniform sampler2D transmittanceTexture;uniform vec2 iResolution;vec3 transmittanceFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture2D(transmittanceTexture,vec2(u,v)).xyz;}void main(void){vec2 uv=gl_FragCoord.xy/iResolution.xy;float height=uv.y*ATMOS_HEIGHT;float angle=uv.x*2.0-1.0;vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 up=rayOrigin/length(rayOrigin);vec3 lightDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);const float isotropicPhase=1.0/(4.0*PI);vec3 light=vec3(0.0);vec3 lightTransferFactor=vec3(0.0);for(int i=0;i<SQRT_SAMPLE_COUNT;i++){for(int j=0;j<SQRT_SAMPLE_COUNT;j++){float u=((0.5+float(i))/float(SQRT_SAMPLE_COUNT))*2.0-1.0;float v=(0.5+float(j))/float(SQRT_SAMPLE_COUNT);float r=sqrt(1.0-u*u);float theta=2.0*PI*v;vec3 rayDirection=vec3(cos(theta)*r,sin(theta)*r,u);float rayAngle=dot(up,rayDirection);bool cameraBelow=rayAngle<0.0;vec3 transmittanceFromCameraToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);float offset=0.0;float distanceToSpace=0.0;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,offset,distanceToSpace);float distanceToGround=0.0;bool hitGround=intersectSphere(rayOrigin,rayDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>0.0;float segmentLength=(hitGround ? distanceToGround : distanceToSpace)/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 transmittanceCamera;vec3 transmittanceLight;for(int k=0;k<SAMPLE_COUNT;k++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;vec3 up=position/length(position);float rayAngle=dot(up,rayDirection);float lightAngle=dot(up,lightDirection);float distanceToGround;float shadow=intersectSphere(position,lightDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>=0.0 ? 0.0 : 1.0;vec3 transmittanceToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);transmittanceCamera=cameraBelow ?(transmittanceToSpace/transmittanceFromCameraToSpace):(transmittanceFromCameraToSpace/transmittanceToSpace);transmittanceLight=transmittanceFromTexture(height,lightAngle);vec2 opticalDensity=exp(-height/rayleighMieHeights);vec3 scatteredLight=transmittanceLight*(rayleighScatteringCoefficient*opticalDensity.x+mieScatteringCoefficient*opticalDensity.y)*isotropicPhase;light+=shadow*transmittanceCamera*scatteredLight*segmentLength;lightTransferFactor+=transmittanceCamera*(rayleighScatteringCoefficient*opticalDensity.x+mieScatteringCoefficient*opticalDensity.y)*segmentLength;t+=segmentLength;}if(hitGround){vec3 hitPoint=rayOrigin+rayDirection*distanceToGround;vec3 normal=normalize(hitPoint);float diffuseAngle=max(dot(normal,lightDirection),0.0);light+=transmittanceCamera*transmittanceLight*GROUND_ALBEDO*diffuseAngle;}}}light/=float(SAMPLE_COUNT);lightTransferFactor/=float(SAMPLE_COUNT);vec3 color=light/(1.0-lightTransferFactor);gl_FragColor=vec4(color,1.0);}",t||er)}))))}initBackgroundShader(){var e;this.renderer&&this.renderer.handler.addProgram((e=this._parameters,new X("atmosphereBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",viewMatrix:"mat4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",sunPos:"vec3",opacity:"float",isOrthographic:"float",frustumParams:"vec4"},attributes:{corners:"vec3"},vertexShader:Hh,fragmentShader:di(Vh,{...e,disableSunDisk:null!=e&&e.disableSunDisk?1:0})})))}removeBackgroundShader(){this.renderer&&this.renderer.handler.removeProgram("atmosphereBackground")}removeLookupTexturesShaders(){var e,t;if(this.renderer){let i=this.renderer.handler;null!=(e=this._scatteringBuffer)&&e.isComplete()&&i.removeProgram("scattering"),null!=(t=this._transmittanceBuffer)&&t.isComplete()&&i.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 Rt(this.renderer.handler,{width:1024,height:1024,useDepth:!1,targets:[{filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}]}),this._transmittanceBuffer.init(),this._scatteringBuffer=new Rt(this.renderer.handler,{width:1024,height:1024,useDepth:!1,targets:[{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 s=t.programs.transmittance,r=s._program.attributes,n=s._program.uniforms;s.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(n.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 s=t.programs.scattering,r=s._program.attributes,n=s._program.uniforms;s.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(n.iResolution,[this._scatteringBuffer.width,this._scatteringBuffer.height]),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._transmittanceBuffer.textures[0]),i.uniform1i(n.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,s=i.uniforms,r=e.gl,n=this.renderer,o=this.planet.camera;r.disable(r.DEPTH_TEST),n.enableBlendOneSrcAlpha(),t.activate(),r.bindBuffer(r.ARRAY_BUFFER,n.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(s.transmittanceTexture,0),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,this._scatteringBuffer.textures[0]),r.uniform1i(s.scatteringTexture,1),r.uniformMatrix4fv(s.viewMatrix,!1,o.getViewMatrix());let a=this.planet.sunPos;r.uniform3fv(s.sunPos,[a.x,a.y,a.z]),r.uniform3fv(s.camPos,[o.eye.x,o.eye.y,o.eye.z]),r.uniform2fv(s.iResolution,[n.sceneFramebuffer.width,n.sceneFramebuffer.height]),r.uniform1f(s.fov,o.getViewAngle()),r.uniform1f(s.opacity,this.opacity);let l=o.frustum;r.uniform1f(s.isOrthographic,o.isOrthographic?1:0),r.uniform4fv(s.frustumParams,[l.right-l.left,l.top-l.bottom,l.right,l.top]),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST),n.enableBlendDefault()}}const Ea="degrees",Gh="m";let jh=0;class hn{constructor(e){this.id=jh++,this.code=e.code,this.units=e.units}equal(e){return e.id===this.id}}const cn=new hn({code:"epsg:3857",units:Gh});class qh{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 s=4*i,r=e.applyMaterial(t);this.tileOffsetArr[s]=r[0],this.tileOffsetArr[s+1]=r[1],this.tileOffsetArr[s+2]=r[2],this.tileOffsetArr[s+3]=r[3]}}function At(e,t,i){return Math.floor(Math.abs(i-e)/t)}function Si(e,t,i,s){let r=1/(1<<i),n=s.getWidth()*r,o=s.getHeight()*r,a=s.southWest.lon+e*n,l=s.northEast.lat-t*o;return new U(new L(a,l-o),new L(a+n,l))}const Le=20,Pe=300;let ye=new v,xe=new v,ir=new v,Qe=new v,Je=new v,sr=new v,ti=new V,Di=new V;const hi=new Array(4);hi[0]=0,hi[1]=1,hi[2]=1,hi[3]=0;const ci=new Array(4);ci[0]=!1,ci[1]=!0,ci[2]=!1,ci[3]=!0;class Aa{constructor(e,t,i,s){this.isPole=!1,this._tileGroup=0,this._projection=cn,this.node=e,this.quadTreeStrategy=t,this.planet=t.planet,this.handler=t.planet.renderer.handler,this.bsphere=new Ft,this._plainRadius=0,this.bbox=new No,this._sw=new v,this._nw=new v,this._se=new v,this._ne=new v,this.centerNormal=new v,this._extent=this._extentMerc=s,this._extentLonLat=new U,this.gridSize=this.planet.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 s=this.tempVertices;if(s&&s.length){let r=this.planet.ellipsoid.getSurfaceNormal3v(e);ti.set(e,r.negateTo());let n=this._extent.northEast,o=this._extent.southWest,a=Math.sqrt(s.length/3)-1,l=n.lon,h=n.lat,c=o.lon,d=o.lat,_=(l-c)/a,u=(h-d)/a,f=t.lon-c,g=t.lat-d,p=Math.floor(f/_),m=Math.floor(a-g/u),v=3*((a+1)*m+p),y=3*((a+1)*(m+1)+p);ir.set(s[v],s[v+1],s[v+2]),Qe.set(s[v+3],s[v+4],s[v+5]),Je.set(s[y],s[y+1],s[y+2]);let x=ti.hitTriangleRes(ir,Qe,Je,i);return x===V.INSIDE?e.distance(i):x===V.AWAY&&(Di.set(e,r),Di.hitTriangleRes(ir,Qe,Je,i)===V.INSIDE)?-e.distance(i):(sr.set(s[y+3],s[y+4],s[y+5]),x=ti.hitTriangleRes(Qe,sr,Je,i),x===V.INSIDE?e.distance(i):x===V.AWAY&&(Di.set(e,r),Di.hitTriangleRes(Qe,sr,Je,i)===V.INSIDE)||x===V.AWAY?-e.distance(i):e.distance(i))}return e.distance(this.planet.ellipsoid.hitRay(ti.origin,ti.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[ui[e]]}equalize(){if(this.tileZoom<2||this.gridSize<2)return;this.readyToEngage=!0;let e=this.node.neighbors,t=this.tempVertices,i=this.tempVerticesHigh,s=this.tempVerticesLow,r=this.gridSize,n=r+1,o=e[0][0];if(this._checkEqualization(0,o)){this.node.equalizedSideWithNodeId[0]=o.equalizedSideWithNodeId[2],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,0),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let r=0,o=e*c;r<n;r+=u,o+=f){const e=3*r,n=3*(d*c+o);t[e]=a[n],t[e+1]=a[n+1],t[e+2]=a[n+2],i[e]=l[n],i[e+1]=l[n+1],i[e+2]=l[n+2],s[e]=h[n],s[e+1]=h[n+1],s[e+2]=h[n+2]}}if(o=e[1][0],this._checkEqualization(1,o)){this.node.equalizedSideWithNodeId[1]=o.equalizedSideWithNodeId[3],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,1),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let o=0,_=e*c;o<n;o+=u,_+=f){const e=3*(n*o+r),c=d*_*3;t[e]=a[c],t[e+1]=a[c+1],t[e+2]=a[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],s[e]=h[c],s[e+1]=h[c+1],s[e+2]=h[c+2]}}if(o=e[2][0],this._checkEqualization(2,o)){this.node.equalizedSideWithNodeId[2]=o.equalizedSideWithNodeId[0],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,2),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=1/(1<<this.tileZoom-o.segment.tileZoom),_=Math.max(r/(c*d),1),u=Math.max(c*d/r,1);for(let o=0,d=e*c;o<n;o+=_,d+=u){const e=3*(n*r+o),c=3*d;t[e]=a[c],t[e+1]=a[c+1],t[e+2]=a[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],s[e]=h[c],s[e+1]=h[c+1],s[e+2]=h[c+2]}}if(o=e[3][0],this._checkEqualization(3,o)){this.node.equalizedSideWithNodeId[3]=o.equalizedSideWithNodeId[1],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,3),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let r=0,o=e*c;r<n;r+=u,o+=f){const e=n*r*3,_=3*(d*o+c);t[e]=a[_],t[e+1]=a[_+1],t[e+2]=a[_+2],i[e]=l[_],i[e+1]=l[_+1],i[e+2]=l[_+2],s[e]=h[_],s[e+1]=h[_+1],s[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],s=i&&i[0],r=this.planet.terrain.maxZoom;this.tileZoom===r&&i&&!(t[0].length||t[1].length||t[2].length||t[3].length)&&(s=this.node.getEqualNeighbor(e));let n=s&&s.segment,o=this;if(s&&n&&n.terrainReady&&n.terrainExists&&n.tileZoom<=r&&o._appliedNeighborsZoom[e]!==n.tileZoom){o._appliedNeighborsZoom[e]=n.tileZoom;let t=o.normalMapNormals,i=n.normalMapNormals;if(!t||!i)return;let s=o.normalMapNormals,r=n.normalMapNormals,a=Math.sqrt(t.length/3),l=a-1;const h=l*hi[e];let c,d,_,u;if(o.tileZoom===n.tileZoom){const f=l-h;if(ci[e])for(let e=0;e<a;e++){let n=3*(e*a+h),o=3*(e*a+f);c=s[n]+r[o],d=s[n+1]+r[o+1],_=s[n+2]+r[o+2],u=1/Math.sqrt(c*c+d*d+_*_),i[o]=t[n]=c*u,i[o+1]=t[n+1]=d*u,i[o+2]=t[n+2]=_*u}else for(let e=0;e<a;e++){let n=3*(h*a+e),o=3*(f*a+e);c=s[n]+r[o],d=s[n+1]+r[o+1],_=s[n+2]+r[o+2],u=1/Math.sqrt(c*c+d*d+_*_),i[o]=t[n]=c*u,i[o+1]=t[n+1]=d*u,i[o+2]=t[n+2]=_*u}n._inTheQueue||n._appliedNeighborsZoom[ui[e]]===o.tileZoom||(n._appliedNeighborsZoom[ui[e]]=o.tileZoom,o.planet._normalMapCreator.queue(n))}}}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),s=e.geodeticToCartesian(t.northEast.lon,t.northEast.lat),r=e.geodeticToCartesian(t.southWest.lon,t.northEast.lat),n=e.geodeticToCartesian(t.northEast.lon,t.southWest.lat);this._sw.copy(i),this._nw.copy(r),this._ne.copy(s),this._se.copy(n)}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,s=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*s,n=r*i,o=e.segment.gridSize+1,a=3*((t+r)*o+n),l=3*(t*o+n),h=3*(t*o+n+r),c=3*((t+r)*o+n+r),d=e.segment.tempVertices,_=new v(d[a],d[a+1],d[a+2]),u=new v(d[h],d[h+1],d[h+2]),f=new v(d[l],d[l+1],d[l+2]),g=new v(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,n=e.segment,o=Math.floor(r*s),a=Math.floor(r*i),l=1/r,h=s-l*o,c=i-l*a;t=1===n.gridSize?n.tempVertices:Kr(n.tempVertices,n.gridSize,o,a,1);let d,_,u=new v(t[0],t[1],t[2]),f=new v(t[9],t[10],t[11]),g=new v(t[3]-t[0],t[4]-t[1],t[5]-t[2]),p=new v(t[6]-t[0],t[7]-t[1],t[8]-t[2]),m=new v(t[3]-t[9],t[4]-t[10],t[5]-t[11]),y=new v(t[6]-t[9],t[7]-t[10],t[8]-t[11]),x=h,b=c;d=x+b<l?v.add(g.scaleTo(b/l),p.scaleTo(x/l)).addA(u):v.add(y.scaleTo(1-b/l),m.scaleTo(1-x/l)).addA(f),x=h+1,b=c+1,_=x+b<l?v.add(g.scaleTo(b/l),p.scaleTo(x/l)).addA(u):v.add(y.scaleTo(1-b/l),m.scaleTo(1-x/l)).addA(f),this._createExtentNormals(),this.setBoundingVolume3v(d,_)}}else this.createBoundsByExtent()}setBoundingSphere(e,t,i,s){this.bsphere.center.x=e,this.bsphere.center.y=t,this.bsphere.center.z=i,this.bsphere.radius=this.bsphere.center.distance(s)}setBoundingVolume(e,t,i,s,r,n){this.bbox.setFromBoundsArr([e,t,i,s,r,n]);let o=e+.5*(s-e),a=t+.5*(r-t),l=i+.5*(n-i);this.bsphere.center.set(o,a,l),this.bsphere.radius=this.bsphere.center.distance(new v(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),s=e.y+.5*(t.y-e.y),r=e.z+.5*(t.z-e.z);this.bsphere.center.set(i,s,r),this.bsphere.radius=this.bsphere.center.distance(new v(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]),s=e[2]+.5*(e[5]-e[2]);this.bsphere.center.set(t,i,s),this.bsphere.radius=this.bsphere.center.distance(new v(e[0],e[1],e[2]))}createCoordsBuffers(e,t,i){const s=(i+1)*(i+1),r=this.handler;this.vertexPositionBufferHigh&&this.vertexPositionBufferHigh.numItems===s?(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,s),this.vertexPositionBufferLow=r.createArrayBuffer(t,3,s))}_addViewExtent(){const e=this._extentLonLat;let t=this.quadTreeStrategy._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=Lt;this.tileX=At(t.getCenter().lon,t.getWidth(),-20037508.34),this.tileY=At(t.getCenter().lat,t.getHeight(),i);const s=this.powTileZoom;this.tileXE=(this.tileX+1)%s,this.tileXW=(s+this.tileX-1)%s,this.tileYN=this.tileY-1,this.tileYS=this.tileY+1,this.tileIndex=zt.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+Lt)*ri,this._globalTextureCoordinates[1]=(Lt-e.northEast.lat)*ri,this._globalTextureCoordinates[2]=(e.northEast.lon+Lt)*ri,this._globalTextureCoordinates[3]=(Lt-e.southWest.lat)*ri}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 L.inverseMercator(e,t)}_createPlainVertices(){const e=this.planet.terrain.gridSizeByZoom[this.tileZoom],t=this.planet.terrain.plainGridSize,i=Math.max(t,e),s=this._extent,r=s.getWidth()/i,n=s.getHeight()/i,o=s.southWest.lon,a=s.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,y=this.plainNormals,x=this.normalMapVertices,b=this.normalMapVerticesHigh,w=this.normalMapVerticesLow,T=this.normalMapNormals;for(let e=0;e<d;e++){let t=e%h,i=~~(e/h),s=this.planet.ellipsoid.lonLatToCartesian(this._projToDeg(o+t*r,a-i*n)),d=s.x*c.x,_=s.y*c.y,C=s.z*c.z,E=1/Math.sqrt(d*d+_*_+C*C),A=d*E,L=_*E,P=C*E;v.doubleToTwoFloats(s,ye,xe),x[f]=s.x,b[f]=ye.x,w[f]=xe.x,T[f++]=A,x[f]=s.y,b[f]=ye.y,w[f]=xe.y,T[f++]=L,x[f]=s.z,b[f]=ye.z,w[f]=xe.z,T[f++]=P,i%l==0&&t%l==0&&(g[u]=s.x,p[u]=ye.x,m[u]=xe.x,y[u++]=A,g[u]=s.y,p[u]=ye.y,m[u]=xe.y,y[u++]=L,g[u]=s.z,p[u]=ye.z,m[u]=xe.z,y[u++]=P)}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,s=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/s,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/s,(i.northEast.lat-i.southWest.lat)/r]}initSlice(e){let t=this._slices[e];return t?t.layers=[]:t=this._slices[e]=new qh(this),t}screenRendering(e,t,i,s,r=!1,n){const o=this.handler.gl,a=e.attributes,l=e.uniforms,h=this.materials,c=this.planet,d=this.quadTreeStrategy;let _,u;t&&t.length?(u=t[0],_=u._height):_=0,o.activeTexture(o.TEXTURE0+c.SLICE_SIZE+2),o.bindTexture(o.TEXTURE_2D,s||this.getDefaultTexture()),o.uniform1i(l.defaultTexture,c.SLICE_SIZE+2);let f=0,g=0,p=!1,m=this.initSlice(i);for(this._indexBuffer=this._getIndexBuffer();u;){if(this.layerOverlap(u)&&(u._fading&&u._fadingOpacity>0||(u.minZoom>=d.minCurrZoom||u.maxZoom>=d.minCurrZoom)&&(u.minZoom<=d.maxCurrZoom||u.maxZoom<=d.maxCurrZoom))){p=!0;let e=h[u.__id];e||(e=h[u.__id]=u.createMaterial(this)),e.isReady||(d._renderCompleted=!1),m.append(u,e),c._samplerArr[f]=f,o.activeTexture(o.TEXTURE0+f),o.bindTexture(o.TEXTURE_2D,e.texture||c.transparentTexture),f++}g++,u=t[g]}!p&&r||(o.uniform1f(l.transitionOpacity,n||this._transitionOpacity>1?1:this._transitionOpacity),o.uniform1i(l.samplerCount,f),o.uniform1f(l.height,_),o.uniform1iv(l.samplerArr,c._samplerArr),o.uniform4fv(l.tileOffsetArr,m.tileOffsetArr),o.uniform1fv(l.layerOpacityArr,m.layerOpacityArr),c.lightEnabled&&(o.activeTexture(o.TEXTURE0+c.SLICE_SIZE+3),o.bindTexture(o.TEXTURE_2D,this.normalMapTexture||c.transparentTexture),o.uniform1i(l.uNormalMap,c.SLICE_SIZE+3),o.uniform3fv(l.uNormalMapBias,this.normalMapTextureBias),o.uniform4fv(l.uGlobalTextureCoord,this._globalTextureCoordinates)),o.bindBuffer(o.ARRAY_BUFFER,this.vertexPositionBufferHigh),o.vertexAttribPointer(a.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.vertexPositionBufferLow),o.vertexAttribPointer(a.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.vertexTextureCoordBuffer),o.vertexAttribPointer(a.aTextureCoord,2,o.UNSIGNED_SHORT,!0,0,0),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,this._indexBuffer),o.drawElements(c.drawMode,this._indexBuffer.numItems,o.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.quadTreeStrategy._fadingNodes.has(t.__id)&&(this.quadTreeStrategy._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,s,r=!1){const n=this.handler.gl,o=e.attributes,a=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,n.activeTexture(n.TEXTURE0+e),n.bindTexture(n.TEXTURE_2D,h[t.__id].texture||this.planet.transparentTexture),c._pickingMaskArr[e]=e+c.SLICE_SIZE,n.activeTexture(n.TEXTURE0+e+c.SLICE_SIZE),n.bindTexture(n.TEXTURE_2D,h[t.__id].pickingMask||this.planet.transparentTexture)}!d&&r||(n.uniform1i(a.samplerCount,u),n.uniform1f(a.height,l),n.uniform1iv(a.samplerArr,c._samplerArr),n.uniform1iv(a.pickingMaskArr,c._pickingMaskArr),n.uniform4fv(a.pickingColorArr,c._pickingColorArr),n.uniform4fv(a.tileOffsetArr,_.tileOffsetArr),n.uniform1fv(a.layerOpacityArr,_.layerOpacityArr),n.bindBuffer(n.ARRAY_BUFFER,this.vertexPositionBufferHigh),n.vertexAttribPointer(o.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this.vertexPositionBufferLow),n.vertexAttribPointer(o.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this.vertexTextureCoordBuffer),n.vertexAttribPointer(o.aTextureCoord,2,n.UNSIGNED_SHORT,!0,0,0),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,this._indexBuffer),n.drawElements(n.TRIANGLE_STRIP,this._indexBuffer.numItems,n.UNSIGNED_INT,0))}depthRendering(e,t){const i=this.handler.gl,s=e.attributes,r=e.uniforms;var n;n=t&&t.length?t[0]._height:0,i.uniform1f(r.height,n),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(s.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(s.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=$i().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}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 Fi=new v,Oi=new v;const be=[new H(0,0),new H(1,0),new H(0,1),new H(1,1)],Yh=Math.sqrt(be.length)-1;let at={xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0},Wh=0;class qt{constructor(e,t,i,s,r,n){t.planet._createdNodesCount++,this.__id=Wh++,this.SegmentPrototype=e,this.quadTreeStrategy=t,this.parentNode=s,this.partId=i,this.nodeId=i+(s?4*s.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,n),this._cameraInside=!1,this.inFrustum=0,this._fadingNodes=[],this.createBounds()}createChildNodes(){this.ready=!0;const e=this.quadTreeStrategy,t=this.segment,i=t._extent,s=t.tileZoom+1,r=.5*i.getWidth(),n=.5*i.getHeight(),o=i.northEast,a=i.southWest,l=new L(a.lon+r,a.lat+n),h=this.nodes;h[0]=new qt(this.SegmentPrototype,e,0,this,s,new U(new L(a.lon,a.lat+n),new L(a.lon+r,o.lat))),h[1]=new qt(this.SegmentPrototype,e,1,this,s,new U(l,new L(o.lon,o.lat))),h[2]=new qt(this.SegmentPrototype,e,2,this,s,new U(new L(a.lon,a.lat),l)),h[3]=new qt(this.SegmentPrototype,e,3,this,s,new U(new L(a.lon+r,a.lat),new L(o.lon,a.lat+n)))}createBounds(){let e=this.segment;e._setExtentLonLat(),0===e.tileZoom?e.setBoundingSphere(0,0,0,new v(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,s=e.bsphere.center.z,r=1/Math.sqrt(t*t+i*i+s*s);e.centerNormal.x=t*r,e.centerNormal.y=i*r,e.centerNormal.z=s*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=wn[e][t.partId];if(-1!==i)return t.parentNode.nodes[i];{let s=[];for(;t.parentNode;)if(s.push(t.partId),i=wn[e][t.partId],t=t.parentNode,-1!==i){let r=s.length;for(e=ui[e];t&&r--;)i=Ya[e][s[r]],t=t.nodes[i];return t}}}traverseNodes(e,t,i,s,r){this.ready||this.createChildNodes();let n=this.nodes;n[0].renderTree(e,t,i,s,r),n[1].renderTree(e,t,i,s,r),n[2].renderTree(e,t,i,s,r),n[3].renderTree(e,t,i,s,r)}renderTree(e,t,i,s,r){if(this.quadTreeStrategy._renderedNodes.length>=1e3)return;(!t||r&&this.segment.tileZoom>r.segment.tileZoom)&&(this.prevState=this.state),this.state=2,this.clearNeighbors();let n=this.segment,o=this.quadTreeStrategy.planet;if(this._cameraInside=!1,!this.parentNode||this.parentNode._cameraInside){let t;t=n._projection.id===cn.id?n._extent.isInside(e._lonLatMerc):n._extent.isInside(e._lonLat),t&&(e._insideSegment=n,this._cameraInside=!0)}this.inFrustum=0;let a=e.frustums,l=a.length;if(n.tileZoom<6)for(let e=0;e<l;e++)a[e].containsSphere(n.bsphere)&&(this.inFrustum|=1<<e);else for(let e=0;e<l;e++)n.terrainReady?a[e].containsBox(n.bbox)&&(this.inFrustum|=1<<e):a[e].containsSphere(n.bsphere)&&(this.inFrustum|=1<<e);if(this.inFrustum||this._cameraInside||n.tileZoom<3){let a=Math.abs(e._lonLat.height),l=e.eye.length2()-o.ellipsoid.polarSizeSqr,h=106876472875.63281*o._heightFactor;l=l<h?h:l;let c=n.tileZoom<2||n.tileZoom>19||n.tileZoom<6&&!n.terrainReady;if(e.isOrthographic){let t=e.getForward();c=c||t.dot(n._sw.getNormal())<-0||t.dot(n._nw.getNormal())<-0||t.dot(n._ne.getNormal())<-0||t.dot(n._se.getNormal())<-0}else c=c||e.eye.distance2(n._sw)<l||e.eye.distance2(n._nw)<l||e.eye.distance2(n._ne)<l||e.eye.distance2(n._se)<l;(this.inFrustum&&(c||a>1e4)||this._cameraInside)&&this.quadTreeStrategy.collectVisibleNode(this),n.tileZoom<2?this.traverseNodes(e,t,i,s,r):n.terrainReady&&(!t&&e.projectedSize(n.bsphere.center,n._plainRadius)<this.quadTreeStrategy.lodSize||t&&(n.tileZoom===t||!c))?c?(n.passReady=!0,this.renderNode(this.inFrustum,!this.inFrustum,i,s)):this.state=0:n.terrainReady&&n.checkZoom()&&(!t||e.projectedSize(n.bsphere.center,n.bsphere.radius)>this.quadTreeStrategy._maxLodSize)?this.traverseNodes(e,t,n,s,r):c?(n.passReady=!!t&&n.terrainReady,this.renderNode(this.inFrustum,!this.inFrustum,i,s)):this.state=0}else this.state=0}renderNode(e,t,i,s){let r=this.segment;r.terrainReady||(r.initialized||r.initialize(),this.whileTerrainLoading(i),r.plainProcessing||r.createPlainSegmentAsync(),r.plainReady&&!s&&r.loadTerrain()),r.planet.lightEnabled&&!r.normalMapReady&&this.whileNormalMapCreating(),t?this.state=-1:(!this._cameraInside&&r.tileZoom>this.quadTreeStrategy.maxCurrZoom&&(this.quadTreeStrategy.maxCurrZoom=r.tileZoom),r.tileZoom<this.quadTreeStrategy.minCurrZoom&&(this.quadTreeStrategy.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.quadTreeStrategy._renderedNodes;this.quadTreeStrategy._transitionOpacityEnabled?Zr(t,this,((e,t)=>e.segment.tileZoom-t.segment.tileZoom)):(this.getRenderedNodesNeighbors(t),t.push(this)),this.segment.terrainReady||(this.quadTreeStrategy._renderCompleted=!1,this.quadTreeStrategy._terrainCompleted=!1);let i=0,s=this.quadTreeStrategy._renderedNodesInFrustum;for(;e;)1&e&&s[i].push(this),i++,e>>=1}applyNeighbor(e,t){const i=ui[t];if(0===this.neighbors[t].length||0===e.neighbors[i].length){const s=this.segment,r=e.segment,n=s.gridSize/(r.gridSize*Math.pow(2,r.tileZoom-s.tileZoom));let o=s.gridSize,a=r.gridSize;n>1?(o=Math.ceil(s.gridSize/n),a=r.gridSize):n<1&&(o=s.gridSize,a=Math.ceil(r.gridSize*n)),this.sideSizeLog2[t]=Math.log2(o),e.sideSizeLog2[i]=Math.log2(a)}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],s=this.getCommonSide(i);-1!==s&&this.applyNeighbor(i,s)}}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,s=i._extentLonLat;let r=e.northEast,n=e.southWest,o=s.northEast,a=s.southWest,l=r.lon,h=r.lat,c=n.lon,d=n.lat,_=o.lon,u=o.lat,f=a.lon,g=a.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&&20===i._tileGroup&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(0===t._tileGroup&&i._tileGroup===Pe&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=f&&l<=_||c<=f&&l>=_))return 2;if(t._tileGroup===Pe&&0===i._tileGroup&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(20===t._tileGroup&&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,s=t.tileX-i.segment.tileX*e,r=t.tileY-i.segment.tileY*e;const n=i.segment;let o,a,l,h;this.appliedTerrainNodeId=i.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId;let c=i.segment.gridSize/e,d=i.segment.fileGridSize/e;if(at.xmin=xt,at.xmax=Ct,at.ymin=xt,at.ymax=Ct,at.zmin=xt,at.zmax=Ct,c>=1){t.gridSize=c;let e=(c+1)*(c+1)*3;o=new Float64Array(e),a=new Float32Array(e),l=new Float32Array(e),n.noDataVertices&&(h=new Uint8Array(e/3)),dr(n.terrainVertices,n.terrainVerticesHigh,n.terrainVerticesLow,n.noDataVertices,n.gridSize,c*r,c*s,c,o,a,l,at,h)}else if(d>=1&&i.segment.terrainExists){t.gridSize=d;let e=(d+1)*(d+1)*3;o=new Float64Array(e),a=new Float32Array(e),l=new Float32Array(e),n.noDataVertices&&(h=new Uint8Array(e/3)),dr(n.normalMapVertices,n.normalMapVerticesHigh,n.normalMapVerticesLow,n.noDataVertices,i.segment.fileGridSize,d*r,d*s,d,o,a,l,at,h)}else{t.gridSize=Yh;let e,i=Math.floor(c*r),h=Math.floor(c*s);e=1===n.gridSize?n.terrainVertices:Kr(n.terrainVertices,n.gridSize,i,h,1);let d=1/c,_=r-d*i,u=s-d*h,f=new v(e[0],e[1],e[2]),g=new v(e[9],e[10],e[11]),p=new v(e[3]-e[0],e[4]-e[1],e[5]-e[2]),m=new v(e[6]-e[0],e[7]-e[1],e[8]-e[2]),y=new v(e[3]-e[9],e[4]-e[10],e[5]-e[11]),x=new v(e[6]-e[9],e[7]-e[10],e[8]-e[11]),b=new v;o=new Float64Array(3*be.length),a=new Float32Array(3*be.length),l=new Float32Array(3*be.length);for(let e=0;e<be.length;e++){let t=be[e].y+_,i=be[e].x+u,s=i*c,r=t*c;b=t+i<d?p.scaleTo(s).addA(m.scaleTo(r)).addA(f):x.scaleTo(1-s).addA(y.scaleTo(1-r)).addA(g),v.doubleToTwoFloats(b,Fi,Oi);let n=3*e;o[n]=b.x,o[n+1]=b.y,o[n+2]=b.z,a[n]=Fi.x,a[n+1]=Fi.y,a[n+2]=Fi.z,l[n]=Oi.x,l[n+1]=Oi.y,l[n+2]=Oi.z,b.x<at.xmin&&(at.xmin=b.x),b.x>at.xmax&&(at.xmax=b.x),b.y<at.ymin&&(at.ymin=b.y),b.y>at.ymax&&(at.ymax=b.y),b.z<at.zmin&&(at.zmin=b.z),b.z>at.zmax&&(at.zmax=b.z)}}if(t.readyToEngage=!0,t.terrainVertices=o,t.terrainVerticesHigh=a,t.terrainVerticesLow=l,t.tempVertices=o,t.tempVerticesHigh=a,t.tempVerticesLow=l,t.noDataVertices=h,t.setBoundingVolume(at.xmin,at.ymin,at.zmin,at.xmax,at.ymax,at.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=o,t.terrainVerticesHigh=a,t.terrainVerticesLow=l,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=o,t.fileGridSize=Math.sqrt(o.length/3)-1;let i=Math.sqrt(n.normalMapNormals.length/3)-1,a=i/e;t.normalMapNormals=i>1?Io(n.normalMapNormals,i,a*r,a*s,a):n.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,s=e.segment.tileZoom,r=0;for(;i.segment.tileZoom>s;)r+=Wa[i.partId][t]/(1<<i.segment.tileZoom-s),i=i.parentNode;return r}}class dn{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 un{constructor(e,t,i){this.quadTreeStrategy=e,this._layer=t,this._nodeCapacity=i,this._secondPASS=[],this._counter=0,this._deferredEntitiesPendingQueue=new dn,this._renderingNodes={}}insertEntity(e,t=!1){}setPickingEnabled(e){}dispose(){}insertEntities(e){}collectVisibleEntityCollections(e){}_queueDeferredNode(e){this._layer.getVisibility()&&(e._inTheQueue=!0,this._counter>=1?this._deferredEntitiesPendingQueue.push(e):this._execDeferredNode(e))}_execDeferredNode(e){this._counter++,requestAnimationFrame((()=>{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)}}))}}class Is{constructor(e){this._skipPreRender=!1,this.events=lt($h),this.name=e.name||"",this.projection=e.proj||cn,this.planet=e.planet,this._quadTreeList=[],this._visibleNodes={},this._renderedNodes=[],this._renderedNodesInFrustum=[],this._fadingNodes=new Map,this._fadingNodesInFrustum=[],this._fadingOpaqueSegments=[],this.minCurrZoom=xt,this.maxCurrZoom=Ct,this._viewExtent=new U(new L(180,180),new L(-180,-180)),this._lodSize=256,this._curLodSize=256,this._minLodSize=512,this._maxLodSize=256,this.maxEqualZoomAltitude=e.maxEqualZoomAltitude||15e6,this.minEqualZoomAltitude=e.minEqualZoomAltitude||1e4,this.minEqualZoomCameraSlope=e.minEqualZoomCameraSlope||.8,this._renderCompleted=!1,this._renderCompletedActivated=!1,this._terrainCompleted=!1,this._terrainCompletedActivated=!1,this._transitionOpacityEnabled=null==e.transitionOpacityEnabled||e.transitionOpacityEnabled}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}createEntityCollectionsTreeStrategy(e,t){return new un(this,e,t)}destroyBranches(){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1;for(let e=0,t=this._quadTreeList.length;e<t;e++)this._quadTreeList[e].destroyBranches()}clearLayerMaterial(e,t=!1){let i=e.__id;for(let e=0,s=this._quadTreeList.length;e<s;e++)this._quadTreeList[e].traverseTree((e=>{if(t&&this._renderedNodes.includes(e))return;let s=e.segment.materials;s[i]&&(s[i].clear(),s[i]=null)}))}get terrainReady(){return this._terrainCompleted&&this._terrainCompletedActivated}_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}_initEvents(){this.planet.renderer.events.on("resize",(()=>{this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1})),this.planet.renderer.events.on("postdraw",(()=>{this._checkRendercompleted()}))}init(e){this._initEvents(),this._renderedNodesInFrustum=new Array(e.frustums.length);for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e]=[];this.preRender(),this.clearRenderedNodes(),this.preLoad()}clearRenderedNodes(){this._clearRenderedNodeList(),this._clearRenderNodesInFrustum()}_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.isOrthographic||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,s=[];this._clearRenderNodesInFrustum(),this._renderedNodes=[];for(let r=0,n=t.length;r<n;r++){let n=t[r],o=n.segment.centerNormal.dot(e.getBackward());if(n.segment.tileZoom===this.maxCurrZoom||o<.81){this._renderedNodes.push(n);let e=0,t=n.inFrustum;for(;t;)1&t&&i[e].push(n),e++,t>>=1}else s.push(n)}for(let t=0,i=s.length;t<i;t++)s[t].renderTree(e,this.maxCurrZoom,null,!1,s[t])}}set transitionOpacityEnabled(e){this._transitionOpacityEnabled=e}get transitionOpacityEnabled(){return this._transitionOpacityEnabled}collectRenderNodes(e){if(this._skipPreRender&&(this._lodSize=wo(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.minCurrZoom=xt,this.maxCurrZoom=Ct,this._collectRenderNodes(e),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 s=i._fadingNodes[t];s.segment&&s.segment._transitionOpacity>=1&&(s.clearNeighbors(),s.getRenderedNodesNeighbors(e),e.push(s))}}}this._skipPreRender=!0}preRender(){this._skipPreRender=!1;for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.createChildNodes(),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)}}_clearVisibleNodes(){this._visibleNodes={}}_collectRenderNodes(e){this._clearVisibleNodes();for(let t=0;t<this._quadTreeList.length;t++)this._quadTreeList[t].renderTree(e,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,s,r=t,n=1<<r;return i=At(e.lon,360/n,-180),s=At(e.lat,180/n,90),[i,s,r,0]}getLonLatTileOffset(e,t,i,s,r){let n;n=Si(t,i,s,U.createFromArray([-180,-90,180,90]));let o=n.getWidth()/(r-1),a=n.getHeight()/(r-1);return[r-Math.ceil((e.lat-n.southWest.lat)/a)-1,Math.floor((e.lon-n.southWest.lon)/o)]}collectVisibleNode(e){this._visibleNodes[e.nodeId]=e}}const $h=["rendercompleted","terraincompleted"],zs=new hn({code:"epsg:4326",units:Ea}),ho=(90-ct)/Math.pow(2,7);class Hr extends Aa{constructor(e,t,i,s){super(e,t,i,s),this._projection=zs,this._extentLonLat=this._extent,this._extentMerc=new U(s.southWest.forwardMercatorEPS01(),s.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;if(this._isNorth){let t=Math.floor((90-this._extent.northEast.lat)/ho);e=Math.floor(t/16)+7}else{let t=Math.floor((Ot-this._extent.northEast.lat)/ho);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=zt.getTileIndex(this.tileX,this.tileY,this.tileZoom,this._tileGroup)}_assignTileXIndexes(e){this.tileX=At(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=20,this.tileY=At(t,e.getHeight(),90)):(this._tileGroup=Pe,this.tileY=At(t,e.getHeight(),Ot)),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_projToDeg(e,t){return new L(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}_getLayerExtentOffset(e){const t=e._extent,i=this._extent,s=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/s,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/s,(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 pe{constructor(e,t,i,s,r,n){this.strategy=e,this.layer=e._layer,this.parentNode=i,this.childNodes=[],this.partId=t,this.nodeId=t+(i?4*i.nodeId+1:0),this.state=null,this.extent=s,this.count=0,this.deferredEntities=[],this.entityCollection=null,this.zoom=n,this._inTheQueue=!1,this.bsphere=new Ft,r&&this._setExtentBounds()}insertEntity(e,t=!1){this.buildTree([e],t)}_addEntitiesToCollection(e,t=!1){if(e.length){const i=this.layer,s=i._planet;let r=this.entityCollection;r||(r=new se({pickingEnabled:i._pickingEnabled,labelMaxLetters:i.labelMaxLetters}),r._layer=this.layer,r.addTo(s,!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 v)}__setLonLat__(e){return e._lonLat.isZero()&&!e._cartesian.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),Math.abs(e._lonLat.lat)<ct?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc=new L,e._lonLatMerc}buildTree(e,t=!1){if(this.count+=e.length,e.length>this.layer._nodeCapacity){const i=this.childNodes;i.length||this.createChildNodes();let s=[],r=[],n=[],o=[],a=e.length;for(;a--;){const t=e[a];i[0].isInside(t)?(t._nodePtr=i[0],s.push(t)):i[1].isInside(t)?(t._nodePtr=i[1],r.push(t)):i[2].isInside(t)?(t._nodePtr=i[2],n.push(t)):i[3].isInside(t)&&(t._nodePtr=i[3],o.push(t))}s.length&&i[0].buildTree(s,t),r.length&&i[1].buildTree(r,t),n.length&&i[2].buildTree(n,t),o.length&&i[3].buildTree(o,t)}else this._addEntitiesToCollection(e,t)}isInside(e){return!!e._lonLatMerc&&this.extent.isInside(e._lonLatMerc)}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),r=t.northEast,n=t.southWest,o=new L(n.lon+i,n.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new pe(e,0,this,new U(new L(n.lon,n.lat+s),new L(n.lon+i,r.lat)),l,h),a[1]=new pe(e,1,this,new U(o,new L(r.lon,r.lat)),l,h),a[2]=new pe(e,2,this,new U(new L(n.lon,n.lat),o),l,h),a[3]=new pe(e,3,this,new U(new L(n.lon+i,n.lat),new L(r.lon,n.lat+s)),l,h)}collectRenderCollectionsPASS1(e,t){const i=e[this.nodeId];if(i){const s=this.childNodes;this.entityCollection?this.renderCollection(t,e):s.length&&(1===i.state?this.strategy._secondPASS.push(this):(s[0].collectRenderCollectionsPASS1(e,t),s[1].collectRenderCollectionsPASS1(e,t),s[2].collectRenderCollectionsPASS1(e,t),s[3].collectRenderCollectionsPASS1(e,t)))}}collectRenderCollectionsPASS2(e,t,i){const s=this.layer._planet.camera,r=s.eye.distance(this.bsphere.center)-this.bsphere.radius<3570*Math.sqrt(s._lonLat.height)||s._lonLat.height>1e4;if(this.count>0&&r&&s.containsSphere(this.bsphere)){const s=this.childNodes;this.entityCollection?this.renderCollection(t,e,i):s.length&&(s[0].collectRenderCollectionsPASS2(e,t,i),s[1].collectRenderCollectionsPASS2(e,t,i),s[2].collectRenderCollectionsPASS2(e,t,i),s[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.childNodes;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 s=this.strategy;s._renderingNodes[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?s._queueDeferredNode(this):this.applyCollection());let r=this.entityCollection,n=this.layer;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 r=e[s];this.alignEntityToTheGround(r,t[i].segment)}else{const t=this.strategy.quadTreeStrategy._renderedNodes;for(;s--;){let i=e[s],r=t.length;for(;r--;)if(t[r].segment.isEntityInside(i)){this.alignEntityToTheGround(i,t[r].segment);break}}}}}alignEntityToTheGround(e,t){let i=new v;t.getEntityTerrainPoint(e,i);let s=Number(this.layer.relativeToGround)&&e._altitude||0;if(s){let t=this.layer._planet.ellipsoid.getSurfaceNormal3v(i);e._setCartesian3vSilent(i.addA(t.scale(s)))}else e._setCartesian3vSilent(i)}isVisible(){return!!this.strategy._renderingNodes[this.nodeId]}}class Ce extends pe{constructor(e,t,i,s,r,n){super(e,t,i,s,r,n),this.strategy=e,this.isNorth=!1}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),r=t.northEast,n=t.southWest,o=new L(n.lon+i,n.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new Ce(e,0,this,new U(new L(n.lon,n.lat+s),new L(n.lon+i,r.lat)),l,h),a[1]=new Ce(e,1,this,new U(o,new L(r.lon,r.lat)),l,h),a[2]=new Ce(e,2,this,new U(new L(n.lon,n.lat),o),l,h),a[3]=new Ce(e,3,this,new U(new L(n.lon+i,n.lat),new L(r.lon,n.lat+s)),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.strategy._renderingNodesNorth[this.nodeId])||!!this.strategy._renderingNodesSouth[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.isNorth?this.strategy._renderingNodesNorth[this.nodeId]=!0:this.strategy._renderingNodesSouth[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.strategy._queueDeferredNode(this):this.applyCollection());const s=this.entityCollection;s._fadingOpacity=this.layer._fadingOpacity,s.scaleByDistance=this.layer.scaleByDistance,s.pickingScale=this.layer.pickingScale,s.isEmpty()||e.push(s)}}class Xh extends un{constructor(e,t,i){super(e,t,i);let s=t._planet;this._entityCollectionsTree=new pe(this,0,null,U.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34]),s,0),this._entityCollectionsTreeNorth=new Ce(this,0,null,U.createFromArray([-180,ct,180,90]),s,0),this._entityCollectionsTreeSouth=new Ce(this,0,null,U.createFromArray([-180,-90,180,Ot]),s,0),this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={}}insertEntity(e,t=!1){e._lonLat.lat>ct?(this._entityCollectionsTreeNorth.__setLonLat__(e),this._entityCollectionsTreeNorth.insertEntity(e,t)):e._lonLat.lat<Ot?(this._entityCollectionsTreeSouth.__setLonLat__(e),this._entityCollectionsTreeSouth.insertEntity(e,t)):(this._entityCollectionsTree.__setLonLat__(e),this._entityCollectionsTree.insertEntity(e,t))}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)}))}dispose(){this._entityCollectionsTree=null,this._entityCollectionsTreeNorth=null,this._entityCollectionsTreeSouth=null,this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={}}insertEntities(e){let t=[],i=[],s=[];for(let r=0,n=e.length;r<n;r++){let n=e[r];n._lonLat.lat>ct?(t.push(n),this._entityCollectionsTreeNorth.__setLonLat__(n)):n._lonLat.lat<Ot?(i.push(n),this._entityCollectionsTreeSouth.__setLonLat__(n)):(s.push(n),this._entityCollectionsTree.__setLonLat__(n))}this._entityCollectionsTree.buildTree(s),this._entityCollectionsTreeNorth.buildTree(t),this._entityCollectionsTreeSouth.buildTree(i)}collectVisibleEntityCollections(e){this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={};let t=this._layer._planet.quadTreeStrategy;this._secondPASS=[],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.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.collectRenderCollectionsPASS1(t._visibleNodesSouth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesSouth,e,this._secondPASS[i].nodeId)}}class La extends Is{constructor(e){super({name:"Earth",...e}),this._visibleNodesNorth={},this._visibleNodesSouth={}}collectVisibleNode(e){let t=e.segment._tileGroup;20===t?this._visibleNodesNorth[e.nodeId]=e:t===Pe?this._visibleNodesSouth[e.nodeId]=e:this._visibleNodes[e.nodeId]=e}_clearVisibleNodes(){super._clearVisibleNodes(),this._visibleNodesNorth={},this._visibleNodesSouth={}}createEntityCollectionsTreeStrategy(e,t){return new Xh(this,e,t)}init(e){this._quadTreeList=[new qt(Aa,this,0,null,0,U.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34])),new qt(Hr,this,0,null,0,U.createFromArray([-180,ct,180,90])),new qt(Hr,this,0,null,0,U.createFromArray([-180,-90,180,Ot]))],super.init(e)}getTileXY(e,t){let i,s,r=function(e,t=ct){return e>t?20:e<-t?Pe:0}(e.lat,ct),n=t,o=1<<n;if(20===r)i=At(e.lon,360/o,-180),s=At(e.lat,(90-ct)/o,90);else if(r===Pe)i=At(e.lon,360/o,-180),s=At(e.lat,(90-ct)/o,Ot);else{let t=Ji(e);i=At(t.lon,Qi/o,-20037508.34),s=At(t.lat,Qi/o,Lt)}return[i,s,n,r]}getLonLatTileOffset(e,t,i,s,r){let n,o=e;e.lat>ct?n=Si(t,i,s,U.createFromArray([-180,ct,180,90])):e.lat<Ot?n=Si(t,i,s,U.createFromArray([-180,-90,180,Ot])):(o=Ji(e),n=Ze(t,i,s));let a=n.getWidth()/(r-1),l=n.getHeight()/(r-1);return[r-Math.ceil((o.lat-n.southWest.lat)/l)-1,Math.floor((o.lon-n.southWest.lon)/a)]}}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,s=13===e[2]?4:3,r=null,n=null;function o(){let t=s;for(var i=s;;i++){if(i>=e.length)throw new Error("Geoid model file: missing newline in header");if(10===e[i]){s=i+1;break}}return i>t&&13===e[i-1]&&i--,String.fromCharCode.apply(null,e.slice(t,i))}for(;"#"===(i=o())[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 (.*)$/))&&(n=parseFloat(t[1]),!isFinite(n)))throw new Error("Geoid model file: bad scale "+t[1]);let a=0,l=0;if((t=i.match(/^\s*(\d+)\s+(\d+)\s*$/))&&(a=parseInt(t[1],10),l=parseInt(t[2],10)),!(t&&a>=0&&l>=0))throw new Error("Geoid model file: bad PGM width&height line");if(65535!=parseInt(o()))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===n)throw new Error("Geoid model file: PGM file does not contain scale");if(a<2||l<2)throw new Error("Geoid model file: Raster size too small");if(e.length-s!=a*l*2)throw new Error("Geoid model file: File has the wrong length");return{scale:n,offset:r,width:a,height:l,rlonres:a/360,rlatres:(l-1)/180,i:s,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 s=2*(t*i.width+e)+i.i;return i.rawfile[s]<<8|i.rawfile[s+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 s=(90-t)*i.rlatres,r=e*i.rlonres,n=Math.floor(s),o=Math.floor(r);r-=o,s-=n,n===i.height-1&&n--,this._cached_ix===o&&this._cached_iy===n||(this._cached_ix=o,this._cached_iy=n,this._v00=this._rawval(o,n),this._v01=this._rawval(o+1,n),this._v10=this._rawval(o,n+1),this._v11=this._rawval(o+1,n+1));let a=(1-s)*((1-r)*this._v00+r*this._v01)+s*((1-r)*this._v10+r*this._v11);return i.offset+i.scale*a}}class Zh{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,s=new L((e[3].lon-e[0].lon)/i,(e[3].lat-e[0].lat)/i),r=new L((e[2].lon-e[1].lon)/i,(e[2].lat-e[1].lat)/i),n=new L((e[1].lon-e[0].lon)/i,(e[1].lat-e[0].lat)/i),o=new L((e[2].lon-e[3].lon)/i,(e[2].lat-e[3].lat)/i);const a=(i+1)*(i+1)*2,l=a/2;let h=new Float32Array(a),c=new Float32Array(a),d=new Array(l),_=0,u=0,f=0,g=new Float32Array(2);for(let t=0;t<=i;t++){let a=new L(e[0].lon+t*s.lon,e[0].lat+t*s.lat),l=new L(e[1].lon+t*r.lon,e[1].lat+t*r.lat);for(let t=0;t<=i;t++){let i=ko(a,l,new L(e[0].lon+t*n.lon,e[0].lat+t*n.lat),new L(e[3].lon+t*o.lon,e[3].lat+t*o.lat));ae(i.lon,g),h[_++]=g[0],c[u++]=g[1],ae(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();ae(t.lon,g),h[2*e]=g[0],c[2*e]=g[1],ae(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 Rt(e,{width:2,height:2,useDepth:!1}),this._framebuffer.init(),this._framebufferMercProj=new Rt(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 X("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 Kh=["loadend","layerloadend"];class Sa{constructor(e=24){this.MAX_REQUESTS=e,this.events=lt(Kh),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.quadTreeStrategy&&t.quadTreeStrategy._terrainCompletedActivated)?(t.events.dispatch(t.events.loadend,t),this.events.dispatch(this.events.layerloadend,t),e.__requestCounterFrame__=0):e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,t)}))}_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 Qh{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 dn(1024),this._lock=new zr}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 X("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 X("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 Rt(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 s=new Float32Array((t+1)*(t+1)*2);for(let e=0;e<=t;e++)for(let r=0;r<=t;r++){let n=2*(e*(t+1)+r);s[n]=r/i-1,s[n+1]=e/i-1}this._verticesBufferArray[t]=this._handler.createArrayBuffer(s,2,s.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,s=Math.sqrt(i)-1;let r=this._verticesBufferArray[s];if(r){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let n=e.normalMapTexturePtr;const o=this._handler,a=o.gl;let l=o.createArrayBuffer(t,3,i,a.DYNAMIC_DRAW);const h=this._framebuffer;let c=o.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(this._normalMapVerticesTexture),c.activate(),a.bindBuffer(a.ARRAY_BUFFER,r),a.vertexAttribPointer(d.a_position,r.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,l),a.vertexAttribPointer(d.a_normal,l.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[s]),a.drawElements(a.TRIANGLE_STRIP,this._indexBufferArray[s].numItems,a.UNSIGNED_INT,0),a.deleteBuffer(l),h.bindOutputTexture(n),c=o.programs.normalMapBlur,c.activate(),a.bindBuffer(a.ARRAY_BUFFER,this._positionBuffer),a.vertexAttribPointer(c._program.attributes.a_position,this._positionBuffer.itemSize,a.FLOAT,!1,0,0),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,this._normalMapVerticesTexture),a.uniform1i(c._program.uniforms.s_texture,0),a.drawArrays(a.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,s=Math.sqrt(i)-1;let r=this._verticesBufferArray[s];if(r){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let n=e.normalMapTexturePtr;const o=this._handler,a=o.gl;let l=o.createArrayBuffer(t,3,i,a.DYNAMIC_DRAW);const h=this._framebuffer,c=o.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(n),c.activate(),a.bindBuffer(a.ARRAY_BUFFER,r),a.vertexAttribPointer(d.a_position,r.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,l),a.vertexAttribPointer(d.a_normal,l.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[s]),a.drawElements(a.TRIANGLE_STRIP,this._indexBufferArray[s].numItems,a.UNSIGNED_INT,0),a.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)}}const _n=new hn({code:"equi",units:Ea}),Ra='(function(){"use strict";let l=null,K=null,O=null,Q=null,S=null,T=null,U=null;function P(a,t){t<0?(t=-t,a+=l.width/2):t>=l.height&&(t=2*(l.height-1)-t,a+=l.width/2),a<0?a+=l.width:a>=l.width&&(a-=l.width);var n=2*(t*l.width+a)+l.i;return l.rawfile[n]<<8|l.rawfile[n+1]}const sa=.5*Math.PI,W=2003750834e-2,ia=Math.PI/W,ua=180/W,X=180/Math.PI,Ma=X*sa,Y=Math.PI/180,da=2*X;let k=0,Z=0,_=null;const B=function(a,t,n){this.x=a,this.y=t,this.z=n};var $=function(a,t,n,o){let f=function(c,C){if(!l)return 0;c<0&&(c+=360);var w=(90-C)*l.rlatres,M=c*l.rlonres,u=Math.floor(w),d=Math.floor(M);M-=d,w-=u,u===l.height-1&&u--,K===d&&O===u||(K=d,O=u,Q=P(d,u),S=P(d+1,u),T=P(d,u+1),U=P(d+1,u+1));let L=null;return L=(1-w)*((1-M)*Q+M*S)+w*((1-M)*T+M*U),l.offset+l.scale*L}(a,t)*n,h=Y*t,r=Y*a,m=Math.sin(h),x=Z/Math.sqrt(1-k*m*m),H=(x+f)*Math.cos(h);o.x=H*Math.cos(r),o.y=H*Math.sin(r),o.z=(x*(1-k)+f)*m},ma=function(a,t,n,o){$(a*ua,da*Math.atan(Math.exp(t*ia))-Ma,n,o)},e=new B(0,0,0),p=new B(0,0,0),y=new B(0,0,0),pa=function(a,t,n){let o=a.x,f=a.y,h=a.z;var r;o>=0?(r=65536*Math.floor(o/65536),t.x=Math.fround(r),n.x=Math.fround(o-r)):(r=65536*Math.floor(-o/65536),t.x=Math.fround(-r),n.x=Math.fround(o+r)),f>=0?(r=65536*Math.floor(f/65536),t.y=Math.fround(r),n.y=Math.fround(f-r)):(r=65536*Math.floor(-f/65536),t.y=Math.fround(-r),n.y=Math.fround(f+r)),h>=0?(r=65536*Math.floor(h/65536),t.z=Math.fround(r),n.z=Math.fround(h-r)):(r=65536*Math.floor(-h/65536),t.z=Math.fround(-r),n.z=Math.fround(h+r))};self.onmessage=function(a){if(a.data.model)l=a.data.model,l.rawfile=a.data.rawfile;else if(a.data.params){let t=549755748352,n=-549755748352,o=549755748352,f=-549755748352,h=549755748352,r=-549755748352;k=a.data.params[8],Z=a.data.params[9];let m=a.data.params[2],x=a.data.params[3],H=a.data.params[10],c=a.data.params[11],C=a.data.params[12],w=a.data.params[13];_=a.data.params[1]===0?ma:$;let M=Math.max(x,m),u=(a.data.params[6]-a.data.params[4])/M,d=(a.data.params[7]-a.data.params[5])/M,L=a.data.params[4],ya=a.data.params[7],aa=Math.max(x/m,1),N=M+1;const z=N*N,R=(m+1)*(m+1)*3;let b=new Float32Array(R),A=new Float64Array(R),F=new Float32Array(R),g=new Float32Array(R),V=new Float32Array(3*z),q=new Float64Array(3*z),v=new Float32Array(3*z),I=new Float32Array(3*z),s=0,i=0;for(let j=0;j<z;j++){let la=j%N,na=~~(j/N);_(L+la*u,ya-na*d,w,e);let D=e.x*H,E=e.y*c,G=e.z*C,J=1/Math.sqrt(D*D+E*E+G*G),oa=D*J,fa=E*J,ha=G*J;pa(e,p,y),q[i]=e.x,v[i]=p.x,I[i]=y.x,V[i++]=oa,q[i]=e.y,v[i]=p.y,I[i]=y.y,V[i++]=fa,q[i]=e.z,v[i]=p.z,I[i]=y.z,V[i++]=ha,na%aa==0&&la%aa==0&&(A[s]=e.x,F[s]=p.x,g[s]=y.x,b[s++]=oa,A[s]=e.y,F[s]=p.y,g[s]=y.y,b[s++]=fa,A[s]=e.z,F[s]=p.z,g[s]=y.z,b[s++]=ha,e.x<t&&(t=e.x),e.x>n&&(n=e.x),e.y<o&&(o=e.y),e.y>f&&(f=e.y),e.z<h&&(h=e.z),e.z>r&&(r=e.z))}let ta=.5*(n-t),ra=.5*(f-o),ea=.5*(r-h),wa=Math.sqrt(ta*ta+ra*ra+ea*ea);self.postMessage({id:a.data.params[0],plainVertices:A,plainVerticesHigh:F,plainVerticesLow:g,plainNormals:b,normalMapNormals:V,normalMapVertices:q,normalMapVerticesHigh:v,normalMapVerticesLow:I,plainRadius:wa},[A.buffer,F.buffer,g.buffer,b.buffer,V.buffer,q.buffer,v.buffer,I.buffer])}}})();\n//# sourceMappingURL=PlainSegmentWorker.worker-CT1cj8jj.js.map\n',co=typeof self<"u"&&self.Blob&&new Blob([Ra],{type:"text/javascript;charset=utf-8"});function Jh(e){let t;try{if(t=co&&(self.URL||self.webkitURL).createObjectURL(co),!t)throw"";const i=new Worker(t,{name:null==e?void 0:e.name});return i.addEventListener("error",(()=>{(self.URL||self.webkitURL).revokeObjectURL(t)})),i}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Ra),{name:null==e?void 0:e.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}class tc extends en{constructor(e=2){super(e,Jh)}_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 s=new Uint8Array(t.rawfile.length);s.set(t.rawfile),e.postMessage({model:i,rawfile:s},[s.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=e._projection.id===zs.id||e._projection.id===_n.id?1:0,s=new Float64Array([this._sourceId,i,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:s},[s.buffer])}else this._pendingQueue.push(e);else this.check()}}const Ma='(function(){"use strict";function H(r,e){return function(z,b){let v=0,N=z.length-1;for(;v<=N;){let n=Math.floor(.5*(v+N));if(Math.abs(z[n]-b)<.001)return n;z[n]<b?v=n+1:N=n-1}return-1}(r,e)!==-1}var y=function(r,e,z){this.x=r,this.y=e,this.z=z},Y=function(r,e,z){let b=r.x,v=r.y,N=r.z;var n;b>=0?(n=65536*Math.floor(b/65536),e.x=Math.fround(n),z.x=Math.fround(b-n)):(n=65536*Math.floor(-b/65536),e.x=Math.fround(-n),z.x=Math.fround(b+n)),v>=0?(n=65536*Math.floor(v/65536),e.y=Math.fround(n),z.y=Math.fround(v-n)):(n=65536*Math.floor(-v/65536),e.y=Math.fround(-n),z.y=Math.fround(v+n)),N>=0?(n=65536*Math.floor(N/65536),e.z=Math.fround(n),z.z=Math.fround(N-n)):(n=65536*Math.floor(-N/65536),e.z=Math.fround(-n),z.z=Math.fround(N+n))};y.prototype.sub=function(r){return new y(this.x-r.x,this.y-r.y,this.z-r.z)},y.prototype.add=function(r){return new y(this.x+r.x,this.y+r.y,this.z+r.z)},y.prototype.cross=function(r){return new y(this.y*r.z-this.z*r.y,this.z*r.x-this.x*r.z,this.x*r.y-this.y*r.x)},y.prototype.normalize=function(r){var e=this.x,z=this.y,b=this.z,v=1/Math.sqrt(e*e+z*z+b*b);return this.x=e*v,this.y=z*v,this.z=b*v,this},y.prototype.distance=function(r){return this.sub(r).length()},y.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)};var x=new y(0,0,0),i=new y(0,0,0),t=new y(0,0,0);self.onmessage=function(r){var e=r.data.elevations,z=r.data.this_plainVertices,b=r.data.this_plainNormals,v=r.data.this_normalMapVertices,N=r.data.this_normalMapNormals,n=r.data.heightFactor,Dr=r.data.gridSize,D=r.data.noDataValues,Hr=r.data.id,Q=549755748352,W=-549755748352,T=549755748352,$=-549755748352,Z=549755748352,X=-549755748352;const J=Math.sqrt(e.length)-1,K=J+1,R=K*K,C=Dr,vr=J/C,L=C+1,tr=n;var a,d,p,m,yr,sr,S=0,xr=0,U=L*L*3,h=new Float64Array(U),j=new Float32Array(U),k=new Float32Array(U),lr=new Uint8Array(L*L),u=v,g=N;if(J>=C){a=new Float32Array(3*R),d=new Float64Array(3*R),p=new Float32Array(3*R),m=new Float32Array(3*R);for(let f=0;f<R;f++){var Ar=f%K,Fr=~~(f/K),ur=f,o=3*ur,rr=e[ur];H(D,rr)&&(rr=0);var Mr=tr*rr,s=new y(u[o]+Mr*g[o],u[o+1]+Mr*g[o+1],u[o+2]+Mr*g[o+2]);if(Y(s,i,t),d[o]=s.x,d[o+1]=s.y,d[o+2]=s.z,p[o]=i.x,p[o+1]=i.y,p[o+2]=i.z,m[o]=t.x,m[o+1]=t.y,m[o+2]=t.z,Fr%vr==0&&Ar%vr==0){let A=new y(u[o],u[o+1],u[o+2]),V=new y(u[o+3],u[o+4],u[o+5]),F=e[ur+1];H(D,F)&&(F=0);let q=!1;if(D.length===0){let _=A.distance(V);q=Math.abs(rr-F)/_>10||rr<-5e3}q?lr[xr]=1:(lr[xr]=0,s.x<Q&&(Q=s.x),s.x>W&&(W=s.x),s.y<T&&(T=s.y),s.y>$&&($=s.y),s.z<Z&&(Z=s.z),s.z>X&&(X=s.z)),j[S]=i.x,k[S]=t.x,h[S++]=s.x,j[S]=i.y,k[S]=t.y,h[S++]=s.y,j[S]=i.z,k[S]=t.z,h[S++]=s.z,xr++}if(Fr!==J&&Ar!==J){var gr=f+1,M=3*gr,B=e[gr];H(D,B)&&(B=0);var cr=tr*B,ar=new y(u[M]+cr*g[M],u[M+1]+cr*g[M+1],u[M+2]+cr*g[M+2]);Y(ar,i,t),d[M]=ar.x,d[M+1]=ar.y,d[M+2]=ar.z,p[M]=i.x,p[M+1]=i.y,p[M+2]=i.z,m[M]=t.x,m[M+1]=t.y,m[M+2]=t.z;var Vr=f+K,c=3*Vr;H(D,B=e[Vr])&&(B=0);var wr=tr*B,nr=new y(u[c]+wr*g[c],u[c+1]+wr*g[c+1],u[c+2]+wr*g[c+2]);Y(nr,i,t),d[c]=nr.x,d[c+1]=nr.y,d[c+2]=nr.z,p[c]=i.x,p[c+1]=i.y,p[c+2]=i.z,m[c]=t.x,m[c+1]=t.y,m[c+2]=t.z;var qr=f+K+1,w=3*qr;H(D,B=e[qr])&&(B=0);var dr=tr*B,er=new y(u[w]+dr*g[w],u[w+1]+dr*g[w+1],u[w+2]+dr*g[w+2]);Y(er,i,t),d[w]=er.x,d[w+1]=er.y,d[w+2]=er.z,p[w]=i.x,p[w+1]=i.y,p[w+2]=i.z,m[w]=t.x,m[w+1]=t.y,m[w+2]=t.z;var Lr=ar.sub(s),Sr=nr.sub(s),Nr=er.sub(s),hr=Sr.cross(Nr).normalize(),zr=Nr.cross(Lr).normalize(),O=zr.add(hr).normalize();a[o]+=O.x,a[o+1]+=O.y,a[o+2]+=O.z,a[M]+=zr.x,a[M+1]+=zr.y,a[M+2]+=zr.z,a[c]+=hr.x,a[c+1]+=hr.y,a[c+2]+=hr.z,a[w]+=O.x,a[w+1]+=O.y,a[w+2]+=O.z}}}else{a=new Float32Array(U),d=new Float64Array(U),p=new Float32Array(U),m=new Float32Array(U),a=new Float32Array(U);var E=C/J,_r=U/3,pr=J+1;for(let f=0;f<_r;f++){let A=Math.floor(f/L),V=f%L,F=A%E,q=V%E,_=Math.floor(A/E)*pr+Math.floor(V/E);V===C&&(_-=1,q=E),A===C&&(_-=pr,F=E);let mr=_+1,fr=_+pr,br=fr+1,or=e[_],ir=e[mr],P=e[fr],G=e[br];H(D,or)&&(or=0),H(D,ir)&&(ir=0),H(D,P)&&(P=0),H(D,G)&&(G=0);let I=or*(1-(yr=q/E))*(1-(sr=F/E))+ir*yr*(1-sr)+P*(1-yr)*sr+G*yr*sr,l=3*f;x.x=z[l]+I*b[l],x.y=z[l+1]+I*b[l+1],x.z=z[l+2]+I*b[l+2],Y(x,i,t),h[l]=x.x,h[l+1]=x.y,h[l+2]=x.z,j[l]=i.x,j[l+1]=i.y,j[l+2]=i.z,k[l]=t.x,k[l+1]=t.y,k[l+2]=t.z,x.x<Q&&(Q=x.x),x.x>W&&(W=x.x),x.y<T&&(T=x.y),x.y>$&&($=x.y),x.z<Z&&(Z=x.z),x.z>X&&(X=x.z)}d.set(h),p.set(j),m.set(k);for(let f=0;f<_r;f++)if(~~(f/L)!==C&&f%L!==C){let A=3*f,V=A+3,F=A+3*L,q=F+3,_=new y(h[A],h[A+1],h[A+2]),mr=new y(h[V],h[V+1],h[V+2]),fr=new y(h[F],h[F+1],h[F+2]),br=new y(h[q],h[q+1],h[q+2]),or=mr.sub(_).normalize(),ir=fr.sub(_).normalize(),P=br.sub(_).normalize(),G=ir.cross(P).normalize(),I=P.cross(or).normalize(),l=I.add(G).normalize();a[A]+=l.x,a[A+1]+=l.y,a[A+2]+=l.z,a[V]+=I.x,a[V+1]+=I.y,a[V+2]+=I.z,a[F]+=G.x,a[F+1]+=G.y,a[F+2]+=G.z,a[q]+=l.x,a[q+1]+=l.y,a[q+2]+=l.z}}self.postMessage({id:Hr,normalMapNormals:a,normalMapVertices:d,normalMapVerticesHigh:p,normalMapVerticesLow:m,terrainVertices:h,terrainVerticesHigh:j,terrainVerticesLow:k,noDataVertices:lr,bounds:[Q,T,Z,W,$,X]},[a.buffer,d.buffer,p.buffer,m.buffer,h.buffer,j.buffer,k.buffer,lr.buffer])}})();\n//# sourceMappingURL=TerrainWorker.worker-DmikdfB2.js.map\n',uo=typeof self<"u"&&self.Blob&&new Blob([Ma],{type:"text/javascript;charset=utf-8"});function ec(e){let t;try{if(t=uo&&(self.URL||self.webkitURL).createObjectURL(uo),!t)throw"";const i=new Worker(t,{name:null==e?void 0:e.name});return i.addEventListener("error",(()=>{(self.URL||self.webkitURL).revokeObjectURL(t)})),i}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Ma),{name:null==e?void 0:e.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}class ic extends en{constructor(e=2){super(e,ec)}_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()}}let Ne=new Float32Array(2);class sc{constructor(e,t=256,i=256){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 X("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 X("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 Rt(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,s=e.programs.vectorTilePolygonRasterization,r=this._width,n=this._height,o=r,a=n,l=o<<1,h=a<<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?(o=l,a=h):(o=r,a=n);let f=g._updateTexture||e.createEmptyTexture_l(o,a),p=u?g._updatePickingMask||e.createEmptyTexture_n(o,a):null;g.applyTexture(f,p),_.setSize(o,a),_.bindOutputTexture(f),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);let m=g.segment.getExtentMerc();ae(m.southWest.lon,Ne),c[0]=Ne[0],d[0]=Ne[1],ae(m.southWest.lat,Ne),c[1]=Ne[0],d[1]=Ne[1],c[2]=2/m.getWidth(),c[3]=2/m.getHeight(),s.activate();let v=s._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,[o,a]),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 Ri extends de{constructor(e={}){super(e.name),this._minDistanceBeforeMemClear=0,this._renderingFadingNodes=(e,t,i,s,r,n,o,a)=>{let l=0===n,h=this.terrain.equalizeVertices;for(let c=0,d=s._fadingNodes.length;c<d;c++){let d=s._fadingNodes[c].segment;e._fadingNodes.has(s._fadingNodes[0].__id)&&!t.has(d.node.__id)&&(t.set(d.node.__id,!0),d._transitionOpacity<1?o.push(d):l?(h&&d.equalize(),d.readyToEngage&&d.engage(),d.screenRendering(i,r,n),a.push(d)):d.screenRendering(i,r,n,this.transparentTexture,!0))}},this._renderingFadingNodesNoDepth=(e,t,i,s,r,n,o)=>{let a=0===n,l=this.terrain.equalizeVertices,h=i.gl;h.disable(h.DEPTH_TEST);for(let h=0,c=s._fadingNodes.length;h<c;h++){let c=s._fadingNodes[h].segment;e._fadingNodes.has(s._fadingNodes[0].__id)&&!t.has(c.node.__id)&&(t.set(c.node.__id,!0),a?(l&&c.equalize(),c.readyToEngage&&c.engage(),c.screenRendering(i,r,n),o.push(c)):c.screenRendering(i,r,n,this.transparentTexture,!0))}h.enable(h.DEPTH_TEST)},this._createdNodesCount=0,this.transitionTime=580,this.ellipsoid=e.ellipsoid||So,this._atmosphere=new Uh(e.atmosphereParameters),this.lightEnabled=!0,this._planetRadius2=(this.ellipsoid.getPolarSize()-1e4)*(this.ellipsoid.getPolarSize()-1e4),this._layers=[],this._updateLayers=!1,this.visibleTileLayers=[],this.visibleVectorLayers=[],this._visibleVectorLayersByDepthOrder=[],this._visibleTileLayerSlices=[],this._visibleEntityCollections=[[]],this.baseLayer=null,this.terrain=null,this.camera=new wa(this,{frustums:e.frustums,eye:new v(25e6,0,0),look:v.ZERO,up:v.NORTH,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude}),this.mousePositionOnEarth=new v,this.emptyTexture=null,this.transparentTexture=null,this.defaultTexture=null,this._initialViewExtent=null,this.layerLock=new zr,this.terrainLock=new zr,this._heightFactor=1,this._indexesCache=[],this._indexesCacheToRemove=[],this._indexesCacheToRemoveCounter=0,this._textureCoordsBufferCache=[];const t={planet:this,maxEqualZoomAltitude:e.maxEqualZoomAltitude,minEqualZoomAltitude:e.minEqualZoomAltitude,minEqualZoomCameraSlope:e.minEqualZoomCameraSlope,transitionOpacityEnabled:e.transitionOpacityEnabled};this.quadTreeStrategyPrototype=e.quadTreeStrategyPrototype||La,this.quadTreeStrategy=new this.quadTreeStrategyPrototype(t),this._nightTexture=null,this._specularTexture=null;let i=jt(e.ambient,new v(.2,.2,.3)),s=jt(e.diffuse,new v(1,1,1)),r=jt(e.specular,new v(63e-5,55e-5,32e-5)),n=e.shininess||18;this._ambient=new Float32Array([i.x,i.y,i.z]),this._diffuse=new Float32Array([s.x,s.y,s.z]),this._specular=new Float32Array([r.x,r.y,r.z,n]),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._maxNodes=e.maxNodesCount||200,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 Zh(this),this._vectorTileCreator=new sc(this,e.vectorTileSize,e.vectorTileSize),this._normalMapCreator=new Qh(this),this._terrainWorker=new ic(3),this._plainSegmentWorker=new tc(3),this._tileLoader=new Sa(e.maxLoadingRequests||12),this._memKey=new Me,this.events=lt(rc),this._distBeforeMemClear=0,this._prevCamEye=new v,this._initialized=!1,this._collectRenderNodesIsActive=!0,this.nightTextureCoefficient=2,this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphereEnabled=e.atmosphereEnabled||!1,this._atmosphereMaxMinOpacity=new Float32Array([.95,.28]),this.solidTextureOne=null,this.solidTextureTwo=null,this._nightTextureSrc=e.nightTextureSrc||null,this._specularTextureSrc=e.specularTextureSrc||null,this._transparentBackground=e.transparentBackground||!1}get terrainReady(){return this.quadTreeStrategy.terrainReady}get maxGridSize(){return this._maxGridSize}getNorthFrameRotation(e){return this.getFrameRotation(e)}getFrameRotation(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=jt(e);this._diffuse=new Float32Array(t.toArray())}set ambient(e){let t=jt(e);this._ambient=new Float32Array(t.toArray())}set specular(e){let t=jt(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]}get sun(){if(this.renderer&&this.renderer.controls.sun)return this.renderer.controls.sun}get sunPos(){return this.sun.sunlight.getPosition()}addControl(e){e.planet=this,e.addTo(this.renderer)}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._heightFactor!==e&&(this._heightFactor=e,this.quadTreeStrategy.destroyBranches(),this.quadTreeStrategy.clearRenderedNodes())}getHeightFactor(){return this._heightFactor}setTerrain(e){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)}))}initAtmosphereShader(e){if(this.renderer&&this.renderer.handler&&this._atmosphereEnabled){let t=this.renderer.handler;t.isWebGl2()?(t.removeProgram("drawnode_screen_wl"),t.addProgram(lo(e))):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(lo(this._atmosphere.parameters)):e.addProgram(ao()),this._transparentBackground||this.renderer.controls.SimpleSkyBackground&&this.renderer.controls.SimpleSkyBackground.deactivate()):(this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphere.deactivate(),this._transparentBackground||(this.renderer.controls.SimpleSkyBackground?this.renderer.controls.SimpleSkyBackground.activate():this.addControl(new ga)),e.isWebGl2()?e.addProgram(new X("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",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\nprecision highp float;in vec3 aVertexPositionHigh;in vec3 aVertexPositionLow;in vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec4 uGlobalTextureCoord;uniform vec3 uNormalMapBias;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;out vec4 vTextureCoord;out vec3 v_vertex;out vec3 cameraPosition;out vec2 vGlobalTextureCoord;out float v_height;void main(void){vec3 aVertexPosition=aVertexPositionHigh+aVertexPositionLow;vec3 nh=height*normalize(aVertexPosition);vTextureCoord.xy=aTextureCoord;vGlobalTextureCoord=uGlobalTextureCoord.xy+(uGlobalTextureCoord.zw-uGlobalTextureCoord.xy)*aTextureCoord;vTextureCoord.zw=uNormalMapBias.z*(aTextureCoord+uNormalMapBias.xy);cameraPosition=eyePositionHigh+eyePositionLow;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);v_height=height;v_vertex=aVertexPosition+nh;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"#version 300 es\nprecision highp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t1=-b-sqrt(d);t2=-b+sqrt(d);return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);uniform vec4 specular;uniform vec3 diffuse;uniform vec3 ambient;uniform sampler2D uNormalMap;uniform sampler2D nightTexture;uniform sampler2D specularTexture;uniform sampler2D defaultTexture;uniform sampler2D samplerArr[SLICE_SIZE];uniform vec4 tileOffsetArr[SLICE_SIZE];uniform vec3 lightPosition;uniform float layerOpacityArr[SLICE_SIZE];uniform int samplerCount;uniform float nightTextureCoefficient;uniform float transitionOpacity;uniform float camHeight;in vec4 vTextureCoord;in vec3 v_vertex;in vec3 cameraPosition;in vec2 vGlobalTextureCoord;in float v_height;vec3 sunPos;layout(location=0)out vec4 diffuseColor;void main(void){sunPos=lightPosition;vec3 texNormal=texture(uNormalMap,vTextureCoord.zw).rgb;vec3 normal=normalize((texNormal-0.5)*2.0);float minH=1200000.0;float maxH=minH*3.0;float nightCoef=getLerpValue(minH,maxH,camHeight)*nightTextureCoefficient;vec3 lightDir=normalize(sunPos);vec3 viewDir=normalize(cameraPosition-v_vertex);float overGround=1.0-step(0.1,v_height);float shininess=texture(specularTexture,vGlobalTextureCoord.st).r*255.0*overGround;vec3 reflectionDirection=reflect(-lightDir,normal);float reflection=max(dot(reflectionDirection,viewDir),0.0);vec3 spec=specular.rgb*pow(reflection,specular.w)*shininess;float diffuseLightWeighting=max(dot(normal,lightDir),0.0);vec4 nightImageColor=texture(nightTexture,vGlobalTextureCoord.st);vec3 night=nightStep*(.18-diffuseLightWeighting*3.0)*nightImageColor.rgb*nightCoef;night*=overGround*step(0.0,night);vec4 lightWeighting=vec4(ambient+diffuse*diffuseLightWeighting+night,1.0);diffuseColor=texture(defaultTexture,vTextureCoord.xy);if(samplerCount==0){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}vec4 src;blend(diffuseColor,samplerArr[0],tileOffsetArr[0],layerOpacityArr[0]);if(samplerCount==1){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[1],tileOffsetArr[1],layerOpacityArr[1]);if(samplerCount==2){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[2],tileOffsetArr[2],layerOpacityArr[2]);if(samplerCount==3){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[3],tileOffsetArr[3],layerOpacityArr[3]);if(samplerCount==4){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[4],tileOffsetArr[4],layerOpacityArr[4]);diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;}"})):e.addProgram(ao()))}_initializeShaders(){if(!this.renderer)throw new Error("Renderer is not initialized");let e=this.renderer,t=e.handler;t.addProgram(new X("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;attribute vec3 aVertexPositionHigh;attribute vec3 aVertexPositionLow;attribute vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;varying vec2 vTextureCoord;void main(void){vTextureCoord=aTextureCoord;vec3 nh=height*normalize(aVertexPositionHigh+aVertexPositionLow);mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);mat4 m=projectionMatrix*viewMatrixRTE;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;gl_Position=m*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"precision highp float;\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);uniform vec4 tileOffsetArr[SLICE_SIZE];uniform float layerOpacityArr[SLICE_SIZE];uniform sampler2D defaultTexture;uniform sampler2D samplerArr[SLICE_SIZE];uniform int samplerCount;varying vec2 vTextureCoord;void main(void){gl_FragColor=texture2D(defaultTexture,vTextureCoord);if(samplerCount==0)return;vec4 src;blend(gl_FragColor,samplerArr[0],tileOffsetArr[0],layerOpacityArr[0]);if(samplerCount==1)return;blend(gl_FragColor,samplerArr[1],tileOffsetArr[1],layerOpacityArr[1]);if(samplerCount==2)return;blend(gl_FragColor,samplerArr[2],tileOffsetArr[2],layerOpacityArr[2]);if(samplerCount==3)return;blend(gl_FragColor,samplerArr[3],tileOffsetArr[3],layerOpacityArr[3]);if(samplerCount==4)return;blend(gl_FragColor,samplerArr[4],tileOffsetArr[4],layerOpacityArr[4]);}"})),t.addProgram(new X("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;attribute vec3 aVertexPositionHigh;attribute vec3 aVertexPositionLow;attribute vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;varying vec2 vTextureCoord;void main(void){vTextureCoord=aTextureCoord;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);mat4 m=projectionMatrix*viewMatrixRTE;vec3 nh=height*normalize(aVertexPositionHigh+aVertexPositionLow);vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;gl_Position=m*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"precision highp float;\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);uniform vec4 tileOffsetArr[SLICE_SIZE];uniform vec4 pickingColorArr[SLICE_SIZE];uniform sampler2D samplerArr[SLICE_SIZE];uniform sampler2D pickingMaskArr[SLICE_SIZE];uniform int samplerCount;varying vec2 vTextureCoord;void main(void){gl_FragColor=vec4(0.0);if(samplerCount==0)return;vec2 tc;vec4 t;vec4 p;blendPicking(gl_FragColor,tileOffsetArr[0],samplerArr[0],pickingMaskArr[0],pickingColorArr[0],1.0);if(samplerCount==1)return;blendPicking(gl_FragColor,tileOffsetArr[1],samplerArr[1],pickingMaskArr[1],pickingColorArr[1],1.0);if(samplerCount==2)return;blendPicking(gl_FragColor,tileOffsetArr[2],samplerArr[2],pickingMaskArr[2],pickingColorArr[2],1.0);if(samplerCount==3)return;blendPicking(gl_FragColor,tileOffsetArr[3],samplerArr[3],pickingMaskArr[3],pickingColorArr[3],1.0);if(samplerCount==4)return;blendPicking(gl_FragColor,tileOffsetArr[4],samplerArr[4],pickingMaskArr[4],pickingColorArr[4],1.0);}"})),t.addProgram(new X("drawnode_depth",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3",frustumPickingColor:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"#version 300 es\nprecision highp float;in vec3 aVertexPositionHigh;in vec3 aVertexPositionLow;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;void main(void){mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);mat4 m=projectionMatrix*viewMatrixRTE;vec3 nh=height*normalize(aVertexPositionHigh+aVertexPositionLow);vec3 eyePosition=eyePositionHigh+eyePositionLow;vec3 vertexPosition=aVertexPositionHigh+aVertexPositionLow;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;gl_Position=m*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"#version 300 es\nprecision highp float;uniform float frustumPickingColor;layout(location=0)out vec4 frustumColor;layout(location=1)out vec4 depthColor;void main(void){frustumColor=vec4(frustumPickingColor,frustumPickingColor,frustumPickingColor,1.0);depthColor=vec4(gl_FragCoord.z,gl_FragCoord.z,gl_FragCoord.z,1.0);}"})),e.addPickingCallback(this,this._renderColorPickingFramebufferPASS),e.addDepthCallback(this,(()=>{this.renderDepthFramebuffer(this.camera,this.quadTreeStrategy)}))}_onLayerLoadend(e){this.events.dispatch(this.events.layerloadend,e)}init(){this._tileLoader.events.on("layerloadend",this._onLayerLoadend,this),$i().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 s=0;s<=e;s++){!this._indexesCache[i][s]&&(this._indexesCache[i][s]=new Array(e));for(let r=0;r<=e;r++){!this._indexesCache[i][s][r]&&(this._indexesCache[i][s][r]=new Array(e));for(let n=0;n<=e;n++){!this._indexesCache[i][s][r][n]&&(this._indexesCache[i][s][r][n]=new Array(e));for(let o=0;o<=e;o++){let e={buffer:null};if(i>=1&&i===s&&i===r&&i===n&&i===o){let t=$i().createSegmentIndexes(i,[s,r,n,o]);e.buffer=this.renderer.handler.createElementArrayBuffer(t,1)}else this._indexesCacheToRemove[t++]=e;this._indexesCache[i][s][r][n][o]=e}}}}}this.renderer.events.on("drawtransparent",(()=>{this._renderScreenNodesWithHeightPASS()})),this._textureCoordsBufferCache=[];let i=$i().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)));if(this.renderer.handler.createDefaultTexture(null,(e=>{this.solidTextureOne=e,this.solidTextureTwo=e})),this.transparentTexture=this.renderer.handler.transparentTexture,this.drawMode=this.renderer.handler.gl.TRIANGLE_STRIP,this._initializeShaders(),this._initializeAtmosphere(),this._updateVisibleLayers(),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.quadTreeStrategy.init(this.camera),this.initLayers(),this._initialized=!0,this._initialViewExtent&&this.viewExtent(this._initialViewExtent),this.renderer.activeCamera=this.camera,this.camera.bindFrustumsPickingColors(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,s=e.length;i<s;i++){let s=e[i];t.deleteBuffer(s.buffer),s.buffer=null}}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._updateLayers=!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(){this.visibleVectorLayers.sort(((e,t)=>e.getZIndex()-t.getZIndex()||e.getHeight()-t.getHeight()));let e={0:[]};for(const t of this.visibleVectorLayers)e[t.depthOrder]||(e[t.depthOrder]=[]),e[t.depthOrder].push(t);if(this._visibleVectorLayersByDepthOrder.length=0,this._visibleVectorLayersByDepthOrder=[],this._visibleVectorLayersByDepthOrder=Object.keys(e).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[Number(t)])),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,s=this.visibleTileLayers.length;i<s;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])}}_renderScreenNodesPASSNoAtmos(){let e=this.camera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodes(this.quadTreeStrategy,t,e,this.quadTreeStrategy._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesPASSAtmos(){let e=this.camera,t=this._setUniformsAtmos(e);this._renderingScreenNodes(this.quadTreeStrategy,t,e,this.quadTreeStrategy._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSNoAtmos(){let e=this.camera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodesWithHeight(this.quadTreeStrategy,t,e,this.quadTreeStrategy._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSAtmos(){let e=this.camera,t=this._setUniformsAtmos(e);this._renderingScreenNodesWithHeight(this.quadTreeStrategy,t,e,this.quadTreeStrategy._renderedNodesInFrustum[e.currentFrustumIndex])}_globalPreDraw(){let e=this.camera;this._distBeforeMemClear+=this._prevCamEye.distance(e.eye),this._prevCamEye.copy(e.eye),this._createdNodesCount>this._maxNodes&&this._distBeforeMemClear>this._minDistanceBeforeMemClear&&(this.terrain.clearCache(),this.memClear()),this._indexesCacheToRemoveCounter>600&&this._clearIndexesCache()}preFrame(){this._updateLayers&&(this._updateLayers=!1,this._updateVisibleLayers()),this.camera.isFirstPass&&(this.camera.update(),this._collectRenderNodesIsActive&&this.quadTreeStrategy.collectRenderNodes(this.camera),this._normalMapCreator.frame(),this._geoImageCreator.frame(),this._vectorTileCreator.frame(),this.camera.checkTerrainCollision(),this.camera.update(),this.events.dispatch(this.events.draw,this),this._collectVectorLayerCollections());for(let e=0;e<this._visibleEntityCollections.length;e++)this.drawEntityCollections(this._visibleEntityCollections[e],e)}frame(){this._renderScreenNodesPASS()}lockQuadTree(){this._collectRenderNodesIsActive=!1,this.camera.setTerrainCollisionActivity(!1)}unlockQuadTree(){this._collectRenderNodesIsActive=!0,this.camera.setTerrainCollisionActivity(!0)}_setUniformsNoAtmos(e){let t,i,s=this.renderer,r=s.handler,n=r.gl;return n.enable(n.CULL_FACE),s.enableBlendOneSrcAlpha(),this.lightEnabled?(r.programs.drawnode_screen_wl.activate(),t=r.programs.drawnode_screen_wl._program,i=t.uniforms,n.uniform3fv(i.lightPosition,this._lightPosition),n.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),n.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(n.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),n.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),n.uniform4fv(i.specular,this.baseLayer._specular||this._specular),n.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(n.uniform3fv(i.diffuse,this._diffuse),n.uniform3fv(i.ambient,this._ambient),n.uniform4fv(i.specular,this._specular),n.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE),n.bindTexture(n.TEXTURE_2D,this._nightTexture||this.transparentTexture),n.uniform1i(i.nightTexture,this.SLICE_SIZE),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE+1),n.bindTexture(n.TEXTURE_2D,this._specularTexture||this.transparentTexture),n.uniform1i(i.specularTexture,this.SLICE_SIZE+1),n.uniform1f(i.camHeight,e.getHeight())):(r.programs.drawnode_screen_nl.activate(),t=r.programs.drawnode_screen_nl._program,i=t.uniforms,n.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),n.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),n.uniform3fv(i.eyePositionHigh,e.eyeHigh),n.uniform3fv(i.eyePositionLow,e.eyeLow),t}_setUniformsAtmos(e){let t,i,s=this.renderer,r=s.handler,n=r.gl;return n.enable(n.CULL_FACE),s.enableBlendOneSrcAlpha(),this.lightEnabled?(r.programs.drawnode_screen_wl.activate(),t=r.programs.drawnode_screen_wl._program,i=t.uniforms,n.uniform3fv(i.lightPosition,this._lightPosition),n.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),n.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(n.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),n.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),n.uniform4fv(i.specular,this.baseLayer._specular||this._specular),n.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(n.uniform3fv(i.diffuse,this._diffuse),n.uniform3fv(i.ambient,this._ambient),n.uniform4fv(i.specular,this._specular),n.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),n.uniform2fv(i.maxMinOpacity,this._atmosphereMaxMinOpacity),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE),n.bindTexture(n.TEXTURE_2D,this._nightTexture||this.transparentTexture),n.uniform1i(i.nightTexture,this.SLICE_SIZE),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE+1),n.bindTexture(n.TEXTURE_2D,this._specularTexture||this.transparentTexture),n.uniform1i(i.specularTexture,this.SLICE_SIZE+1),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE+4),n.bindTexture(n.TEXTURE_2D,s.controls.Atmosphere._transmittanceBuffer.textures[0]),n.uniform1i(i.transmittanceTexture,this.SLICE_SIZE+4),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE+5),n.bindTexture(n.TEXTURE_2D,s.controls.Atmosphere._scatteringBuffer.textures[0]),n.uniform1i(i.scatteringTexture,this.SLICE_SIZE+5),n.uniform1f(i.camHeight,e.getHeight())):(r.programs.drawnode_screen_nl.activate(),t=r.programs.drawnode_screen_nl._program,i=t.uniforms,n.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),n.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),n.uniform3fv(i.eyePositionHigh,e.eyeHigh),n.uniform3fv(i.eyePositionLow,e.eyeLow),t}static __refreshLayersFadingOpacity__(e,t,i){for(let s=e.length-1;s>=0;--s){let r=e[s];r._fading&&r._refreshFadingOpacity(t,i)&&e.splice(s,1)}}_renderingScreenNodes(e,t,i,s){let r=this._visibleTileLayerSlices;r.length&&i.isFirstPass&&Ri.__refreshLayersFadingOpacity__(r[0],e.minCurrZoom,e.maxCurrZoom);let n=new Map,o=[],a=this.terrain.equalizeVertices,l=s.length;if(e._fadingOpaqueSegments=[],i.slope>.8||!this.terrain||this.terrain.isEmpty)for(;l--;){let i=s[l],o=i.segment;this._renderingFadingNodesNoDepth(e,n,t,i,r[0],0,e._fadingOpaqueSegments),a&&o.equalize(),o.readyToEngage&&o.engage(),o.screenRendering(t,r[0],0)}else{for(;l--;){let i=s[l],h=i.segment;this._renderingFadingNodes(e,n,t,i,r[0],0,o,e._fadingOpaqueSegments),h._transitionOpacity<1?o.push(h):(a&&h.equalize(),h.readyToEngage&&h.engage(),h.screenRendering(t,r[0],0))}for(let e=0;e<o.length;e++){let i=o[e];a&&i.equalize(),i.readyToEngage&&i.engage(),i.screenRendering(t,r[0],0)}}}_renderingScreenNodesWithHeight(e,t,i,s){let r=this.renderer.handler.gl;r.enable(r.POLYGON_OFFSET_FILL),r.disable(r.CULL_FACE);let n=new Map,o=[],a=this._visibleTileLayerSlices;for(let l=1,h=a.length;l<h;l++){i.isFirstPass&&Ri.__refreshLayersFadingOpacity__(a[l],e.minCurrZoom,e.maxCurrZoom),r.polygonOffset(0,-l);let h=s.length;for(;h--;){let i=s[h];this._renderingFadingNodes(e,n,t,i,a[l],l,o),i.segment._transitionOpacity<1?i.segment.initSlice(l):i.segment.screenRendering(t,a[l],l,this.transparentTexture,!0)}}r.disable(r.POLYGON_OFFSET_FILL),r.enable(r.CULL_FACE)}_renderColorPickingFramebufferPASS(){let e,t=this.renderer,i=t.handler,s=i.gl;i.programs.drawnode_colorPicking.activate(),e=i.programs.drawnode_colorPicking._program;let r=e.uniforms,n=t.activeCamera;s.enable(s.CULL_FACE),s.uniformMatrix4fv(r.viewMatrix,!1,n.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,n.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,n.eyeHigh),s.uniform3fv(r.eyePositionLow,n.eyeLow);let o=this.quadTreeStrategy._renderedNodesInFrustum[n.getCurrentFrustum()],a=this._visibleTileLayerSlices,l=o.length;for(;l--;)o[l].segment._transitionOpacity>=1&&o[l].segment.colorPickingRendering(e,a[0],0);for(let t=0;t<this.quadTreeStrategy._fadingOpaqueSegments.length;++t)this.quadTreeStrategy._fadingOpaqueSegments[t].colorPickingRendering(e,a[0],0);s.enable(s.POLYGON_OFFSET_FILL);for(let t=1,i=a.length;t<i;t++)for(l=o.length,s.polygonOffset(0,-t);l--;)o[l].segment.colorPickingRendering(e,a[t],t,this.transparentTexture,!0);s.disable(s.POLYGON_OFFSET_FILL)}renderDepthFramebuffer(e,t){let i,s=this.renderer.handler,r=s.gl;s.programs.drawnode_depth.activate(),i=s.programs.drawnode_depth._program;let n=i.uniforms;r.disable(r.BLEND),r.disable(r.POLYGON_OFFSET_FILL),r.uniformMatrix4fv(n.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.eyeHigh),r.uniform3fv(n.eyePositionLow,e.eyeLow),r.uniform1f(n.frustumPickingColor,e.frustumColorIndex);let o=t._renderedNodesInFrustum[e.getCurrentFrustum()],a=this._visibleTileLayerSlices,l=o.length;for(;l--;)o[l].segment._transitionOpacity>=1&&o[l].segment.depthRendering(i,a[0]);for(let e=0;e<t._fadingOpaqueSegments.length;++e)t._fadingOpaqueSegments[e].depthRendering(i,a[0]);r.enable(r.BLEND)}_collectVectorLayerCollections(){let e=this._visibleVectorLayersByDepthOrder.length;this._visibleEntityCollections.length=0,this._visibleEntityCollections=new Array(e);for(let e=0;e<this._visibleEntityCollections.length;e++)this._visibleEntityCollections[e]=[];for(;e--;){let t=this._visibleVectorLayersByDepthOrder[e],i=t.length;for(;i--;){let s=t[i];s._fading&&s._refreshFadingOpacity(this.quadTreeStrategy.minCurrZoom,this.quadTreeStrategy.maxCurrZoom)&&(t.splice(i,1),0===t.length&&this._visibleVectorLayersByDepthOrder.splice(e,1)),s.collectVisibleCollections(this._visibleEntityCollections[e]),s.update()}}}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.project3v(e)}getPixelFromLonLat(e){let t=this.ellipsoid.lonLatToCartesian(e);if(t)return this.renderer.activeCamera.project3v(t)}getDistanceFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return t.distance(this.renderer.activeCamera.eye)}getDistanceFromPixel(e){return this.renderer.getDistanceFromPixel(e)||this.getDistanceFromPixelEllipsoid(e)||0}viewExtent(e){this.camera?this.camera.viewExtent(e):this._initialViewExtent=e}viewExtentArr(e){this.viewExtent(new U(new L(e[0],e[1]),new L(e[2],e[3])))}getExtent(){if(this.renderer){let e=this.renderer.handler.getWidth(),t=this.renderer.handler.getHeight(),i=[this.getLonLatFromPixelTerrain(new H(0,0)),this.getLonLatFromPixelTerrain(new H(e,0)),this.getLonLatFromPixelTerrain(new H(e,t)),this.getLonLatFromPixelTerrain(new H(0,t))];if(i[0]&&i[1]&&i[2]&&i[3]){let e=i[0].lon,t=i[2].lat,s=i[1].lon,r=i[0].lat;for(let n=0;n<i.length;n++)i[n].lon>s&&(s=i[n].lon),i[n].lat>r&&(r=i[n].lat),i[n].lon<e&&(e=i[n].lon),i[n].lat<t&&(t=i[n].lat);return new U(new L(e,t),new L(s,r))}}return this.quadTreeStrategy._viewExtent}getViewExtent(){return this.quadTreeStrategy._viewExtent}viewLonLat(e,t,i){this.camera.setLonLat(e,t,i)}flyExtent(e,t,i={}){this.camera.flyExtent(e,t,i)}flyCartesian(e,t){this.camera.flyCartesian(e,t)}flyLonLat(e,t={}){this.camera.flyLonLat(e,t)}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 _t&&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.quadTreeStrategy._renderedNodes,s=i.length;for(;s--;)if(i[s].segment.isEntityInside(e))return i[s].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.quadTreeStrategy.clearRenderedNodes()}destroy(){var e;this._terrainWorker.destroy(),this._plainSegmentWorker.destroy(),null==(e=this.renderer)||e.destroy(),this.onremove(),super.destroy()}}const rc=["draw","layeradd","baselayerchange","layerremove","layervisibilitychange","rendercompleted","terraincompleted","layerloadend"];class fn extends de{constructor(e){super("skybox"),this.params=e,this.vertexPositionBuffer=null,this.texture=null}static createDefault(e){return new fn({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 X("skybox",{uniforms:{projectionViewMatrix:{type:ht.MAT4},uSampler:{type:ht.SAMPLERCUBE},pos:{type:ht.VEC3}},attributes:{aVertexPosition:{type:ht.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 }"})),this.texture=this.renderer.handler.loadCubeMapTexture(this.params),this._createBuffers(),this.drawMode=this.renderer.handler.gl.TRIANGLES}preFrame(){let e=this.renderer.handler,t=e.gl,i=this.renderer.activeCamera;t.disable(t.DEPTH_TEST),e.programs.skybox.activate();let s=e.programs.skybox._program,r=s.uniforms;if(i.isOrthographic){const e=i.frustum.near,s=i.frustum.far,n=i.getAspectRatio(),o=e*Math.tan(i.viewAngle*Qt),a=o*n,l=(new tt).setPerspective(-a,a,-o,o,e,s),h=(new tt).set(i.getViewMatrix());t.uniformMatrix4fv(r.projectionViewMatrix,!1,l.mul(h)._m)}else 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 n=this.vertexPositionBuffer;t.bindBuffer(t.ARRAY_BUFFER,n),t.vertexAttribPointer(s.attributes.aVertexPosition,n.itemSize,t.FLOAT,!1,0,0),t.drawArrays(this.drawMode,0,n.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)}}const Hc=Object.freeze(Object.defineProperty({__proto__:null,Axes:class extends de{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 X("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:Ri,RenderNode:de,SkyBox:fn},Symbol.toStringTag,{value:"Module"})),Bs=class e{constructor(t={}){this.__id=e.__counter__++,this.equalizeVertices=t.equalizeVertices||!1,this.equalizeNormals=!1,this.isEmpty=!0,this.name=t.name||"empty",this.minZoom=t.minZoom||2,this.maxZoom=t.maxZoom||19,this.maxNativeZoom=t.maxNativeZoom||this.maxZoom,this.gridSizeByZoom=t.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=t.geoid||new Pa({src:t.geoidSrc||null}),this._isReady=!1}setUrlRewriteCallback(e){}get isIdle(){return!0}isEqual(e){return e.__id===this.__id}static checkNoDataValue(e,t){return-1!==Xr(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){}};Bs.__counter__=0;let Mi=Bs;class gn extends Mi{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=lt(nc,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=$r(t.extent,new U(new L(-180,-90),new L(180,90))),this._dataType="arrayBuffer",this._maxNodeZoom=this.gridSizeByZoom.length-1,this._elevationCache={},this._fetchCache={},this._cache=t.cache||"default",this._loader=new Sa,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,s){if(!e||e.lat>ct||e.lat<Ot)return t(0),!0;s=null==s||s;const[r,n,o,a]=this._planet.quadTreeStrategy.getTileXY(e,i||this.maxZoom);let l=zt.getTileIndex(r,n,o,a),h=this.getElevationCache(l),c=Ji(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._urlRewriteCallback&&this._urlRewriteCallback(r,n,o,a)||this.buildURL(r,n,o,a),type:this._dataType,options:{cache:this._cache}}),this._fetchCache[l]=i),i.then((i=>{let h=Ze(r,n,o);if("ready"===i.status){let e={heights:this._createHeights(i.data,null,a,r,n,o,h),extent:h};this.setElevationCache(l,e),t(this._getGroundHeightMerc(c,e))}else if("error"===i.status){if(s&&o>this.maxNativeZoom)return s=!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(),s=Math.sqrt(t.heights.length),r=i/(s-1),n=s-Math.ceil((e.lat-t.extent.southWest.lat)/r)-1,o=Math.floor((e.lon-t.extent.southWest.lon)/r),a=(n+1)*s+o,l=a+1,h=n*s+o,c=h+1,d=t.heights[a],_=t.heights[l],u=t.heights[h],f=t.heights[c],g=new v(t.extent.southWest.lon+r*o,d,t.extent.northEast.lat-r*n-r),p=new v(g.x+r,_,g.z),m=new v(g.x,u,g.z+r),y=new v(g.x+r,f,g.z+r),x=new v(e.lon,1e5,e.lat),b=new V(x,new v(0,-1,0)),w=new v,T=b.hitTriangleRes(g,p,m,w);return T===V.INSIDE?w.y:(T=b.hitTriangleRes(p,y,m,w),T===V.INSIDE?w.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,options:{cache:this._cache},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,s){return Dt(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,s,r,n,o,a){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 nc=["load","loadend"];class Ds extends zt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(oc),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,this._cache=t.cache||"default"}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:{cache:this._cache}},(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 Dt(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,s=i.node,r=!1,n=this.__id,o=e;for(;s.parentNode;)if(s=s.parentNode,o=s.segment.materials[n],o&&o.textureExists){r=!0;break}if(i.passReady){let r=e.layer.maxNativeZoom;if(s.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 s=t.segment.materials[e.layer.__id];s?!s.isLoading&&!s.isReady&&this.loadMaterial(s,!0):(s=t.segment.materials[e.layer.__id]=e.layer.createMaterial(t.segment),this.loadMaterial(s,!0))}}if(r){e.appliedNode=s,e.appliedNodeId=s.nodeId,e.texture=o.texture;let t=1/(2<<i.tileZoom-s.segment.tileZoom-1);e.texOffset[0]=i.tileX*t-s.segment.tileX,e.texOffset[1]=i.tileY*t-s.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;90===e.northEast.lat&&(t.northEast.lat=20087508.34),180===e.northEast.lon&&(t.northEast.lon=20087508.34),-90===e.southWest.lat&&(t.southWest.lat=-20087508.34),-180===e.southWest.lon&&(t.southWest.lon=-20087508.34)}}const oc=["load","loadend"];class me extends Ds{constructor(e,t){super(e,t),this._extra=new URLSearchParams(t.extra).toString(),t.extent||this.setExtent(new U(new L(-180,-90),new L(180,90))),this.layers=t.layers,this.imageWidth=t.imageWidth||256,this.imageHeight=t.imageHeight||256,this._getBbox=me.get_bbox_v1_1_1,this._version="",this.setVersion(t.version)}static createRequestUrl(e,t,i="image/png",s="1.1.1",r="GetMap",n,o,a=256,l=256,h){return`${e}?LAYERS=${t}&FORMAT=${i}&SERVICE=WMS&VERSION=${s}&REQUEST=${r}&SRS=${n}&BBOX=${o}&WIDTH=${a}&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,t){return"epsg:4326"===t?`${e.getSouth()},${e.getWest()},${e.getNorth()},${e.getEast()}`:`${e.getWest()},${e.getSouth()},${e.getEast()},${e.getNorth()}`}_checkSegment(e){return!0}get instanceName(){return"WMS"}_createUrl(e){return me.createRequestUrl(this.url,this.layers,"image/png",this._version,"GetMap",e._projection.code,this._getBbox(e.getExtent(),e._projection.code),this.imageWidth,this.imageHeight,this._extra)}setVersion(e){this._version=e||"1.1.1","1.1.1"===this._version?this._getBbox=me.get_bbox_v1_1_1:"1.3.0"===e&&(this._getBbox=me.get_bbox_v1_3_0)}_correctFullExtent(){const e=this._extent,t=this._extentMerc;90===e.northEast.lat&&(t.northEast.lat=20087508.34),180===e.northEast.lon&&(t.northEast.lon=20087508.34),-90===e.southWest.lat&&(t.southWest.lat=-20087508.34),-180===e.southWest.lon&&(t.southWest.lon=-20087508.34)}}class je extends gn{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:Ki(this._imageSize)?this._imageSize/2:$e(this._imageSize)/2,this._dataType="arrayBuffer"}isBlur(e){return e.tileZoom>=18}_createUrl(e){return me.createRequestUrl(this.url,this._layers,this._format,"1.1.1","GetMap",e._projection.code,me.get_bbox_v1_1_1(e.getExtent()),this._imageSize,this._imageSize)}_createHeights(e,t,i,s,r,n,o,a){let l=new Int16Array(e);if(!Ki(this._imageSize)){let e=new Float32Array(l.length);return function(e,t){for(let i=0,s=t.length;i<s;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,s){let r=Math.sqrt(i.length)-1,n=r+1,o=Math.sqrt(e.length),a=o/r,l=0,h=0;for(let c=0,d=0,_=e.length;c<_;c++){let _=e[c],u=je.checkNoDataValue(t,_),f=!1,g=!1,p=Math.floor(c/o),m=c%o,v=Math.floor(m/r),y=Math.floor(p/r),x=s[y][v],b=p%r,w=m%r,T=(b+y)*n+w+v;if(x[T]=_,(p+y)%a==0&&(m+v)%a==0&&(i[d++]=_),(m+1)%r==0&&m!==o-1){l=e[c],f=je.checkNoDataValue(t,l);let o=_;u||f||(o=.5*(_+l)),T=(b+y)*n+w+1,x[T]=o,(p+y)%a==0&&(i[d++]=o);let h=(b+y)*n+(w+1)%r;s[y][v+1][h]=o}if((p+1)%r==0&&p!==o-1){h=e[c+o],g=je.checkNoDataValue(t,h);let l=_;u||g||(l=.5*(_+h)),T=(b+1)*n+w+v,x[T]=l,(m+v)%a==0&&(i[d++]=l);let f=(b+1)%r*n+w+v;s[y+1][v][f]=l}if((m+1)%r==0&&m!==o-1&&(p+1)%r==0&&p!==o-1){let a=e[c+o+1],p=je.checkNoDataValue(t,a),m=_;u||f||g||p||(m=.25*(_+l+h+a)),T=(b+1)*n+(w+1),x[T]=m,i[d++]=m;let C=(b+1)*n;s[y][v+1][C]=m;let E=r;s[y+1][v][E]=m;let A=0;s[y+1][v+1][A]=m}}}(l,this.noDataValues,d,c);let _=zt.getTileIndex(s,r,n,i);this.setElevationCache(_,{heights:d,extent:o});let u=this._imageSize/this.plainGridSize;for(let e=0;e<u;e++)for(let t=0;t<u;t++){let o=2*s+t,a=2*r+e,l=n+1,h=zt.getTileIndex(o,a,l,i);this.setElevationCache(h,{heights:c[e][t],extent:Ze(o,a,l)})}return d}}class St extends gn{constructor(e,t={}){super(e||"RgbTerrain",{equalizeVertices:null==t.equalizeVertices||t.equalizeVertices,maxZoom:t.maxZoom||17,noDataValues:t.noDataValues||[null!=t.minHeight?t.minHeight:-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={},this._minHeight=t.minHeight||-1e4,this._resolution=t.resolution||.1}static checkNoDataValue(e,t){return t>5e4||-1!==Xr(e,t)}rgb2Height(e,t,i){return 255===e?this._minHeight:this._minHeight+this._resolution*(256*e*256+256*t+i)}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,s,r,n,o,a){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(!Ki(this._imageSize)&&h===this._imageSize){let e=new Float32Array(h*h);return this.extractElevationTilesRgbNonPowerOfTwo(l,e,this._heightFactor),e}if(this._imageSize===this.plainGridSize){let e=(this.plainGridSize+1)*(this.plainGridSize+1),i=new Float32Array(e),[s,r,n]=t?rr(t.tileX,t.tileY,t.tileZoom,c,d,_):[0,0,0];return this.extractElevationSimple(l,this.noDataValues,u,s,r,n,f,i,this._heightFactor,this._imageSize),i}let g=(this.plainGridSize+1)*(this.plainGridSize+1),p=h/this.plainGridSize,m=new Float32Array(g),v=new Array(p);for(let e=0;e<p;e++){v[e]=[];for(let t=0;t<p;t++)v[e][t]=new Float32Array(g)}if(a)this.extractElevationTilesRgbNoChildren(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,f,m);else{this.extractElevationTilesRgb(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,f,m,v);for(let e=0;e<p;e++)for(let t=0;t<p;t++){let[o,a,l]=[2*s+t,2*r+e,n+1],h=zt.getTileIndex(o,a,l,i);this.setElevationCache(h,{heights:v[e][t],extent:Ze(o,a,l)})}}let y=zt.getTileIndex(s,r,n,i);return this.setElevationCache(y,{heights:m,extent:o}),m}getHeightAsync(e,t,i){if(0===(i=i??this.maxZoom))return t(0),!0;const s=this._planet.quadTreeStrategy,[r,n,o,a]=s.getTileXY(e,i),[l,h]=s.getLonLatTileOffset(e,r,n,o,this._imageSize),c=4*(l*this._imageSize+h),d=zt.getTileIndex(r,n,o,a);if(this._imageDataCache[d]){let s=this._imageDataCache[d],r=this._heightFactor*this.rgb2Height(s[c],s[c+1],s[c+2]);return St.checkNoDataValue(this.noDataValues,r)?this.getHeightAsync(e,t,i-1):(t(this._heightFactor*this.rgb2Height(s[c],s[c+1],s[c+2])),!0)}let _=this._fetchCache[d];return _||(_=this._loader.fetch({src:this._urlRewriteCallback&&this._urlRewriteCallback(r,n,o,a)||this.buildURL(r,n,o,a),type:this._dataType,options:{cache:this._cache}}),this._fetchCache[d]=_),_.then((s=>{if("ready"===s.status){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(s.data,0,0);let r=this._ctx.getImageData(0,0,256,256).data;this._imageDataCache[d]=r;let n=this._heightFactor*this.rgb2Height(r[c],r[c+1],r[c+2]);if(St.checkNoDataValue(this.noDataValues,n))return this.getHeightAsync(e,t,i-1);t(this._heightFactor*this.rgb2Height(r[c],r[c+1],r[c+2]))}else{if("error"===s.status)return this.getHeightAsync(e,t,i-1);this._fetchCache[d]=null,delete this._fetchCache[d]}})),!1}extractElevationSimple(e,t,i=null,s,r,n,o,a,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*this.rgb2Height(e[u],e[u+1],e[u+2]);(St.checkNoDataValue(t,f)||0===f)&&i&&(f=Xt(n,s,r,i,_,d,o)),a[_*(h+1)+d]=f}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(c*h+d),u=l*this.rgb2Height(e[_],e[_+1],e[_+2]);(St.checkNoDataValue(t,u)||0===u)&&i&&(u=Xt(n,s,r,i,c,d,o)),a[c*(h+1)+h]=u}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(d*h+c),u=l*this.rgb2Height(e[_],e[_+1],e[_+2]);(St.checkNoDataValue(t,u)||0===u)&&i&&(u=Xt(n,s,r,i,d,c,o)),a[h*(h+1)+c]=u}let c=l*this.rgb2Height(e[e.length-4],e[e.length-3],e[e.length-2]);(St.checkNoDataValue(t,c)||0===c)&&i&&(c=Xt(n,s,r,i,h-1,h-1,o)),a[a.length-1]=c}extractElevationTilesRgbNonPowerOfTwo(e,t,i=1){for(let s=0,r=t.length;s<r;s++){let r=4*s;t[s]=i*this.rgb2Height(e[r],e[r+1],e[r+2])}}extractElevationTilesRgb(e,t,i,s=null,r,n,o,a,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]=rr(a,l,h,r,n,o);for(let r=0,n=0,o=e.length/4;r<o;r++){let o=4*r,a=t*this.rgb2Height(e[o],e[o+1],e[o+2]),l=St.checkNoDataValue(i,a),h=!1,T=!1,C=Math.floor(r/g),E=r%g;(l||0===a)&&s&&(a=Xt(w,x,b,s,Math.floor(C/p),Math.floor(E/p),c));let A=Math.floor(E/u),L=Math.floor(C/u),P=_[L][A],S=C%u,R=E%u,M=(S+L)*f+R+A;if(P[M]=a,(C+L)%p==0&&(E+A)%p==0&&(d[n++]=a),(E+1)%u==0&&E!==g-1){m=t*this.rgb2Height(e[o+4],e[o+5],e[o+6]),h=St.checkNoDataValue(i,m),(h||0===m)&&s&&(m=Xt(w,x,b,s,Math.floor(C/p),Math.floor((E+1)/p),c));let r=a;l||h||(r=.5*(a+m)),M=(S+L)*f+R+1,P[M]=r,(C+L)%p==0&&(d[n++]=r);let g=(S+L)*f+(R+1)%u;_[L][A+1][g]=r}if((C+1)%u==0&&C!==g-1){y=4*g,v=t*this.rgb2Height(e[o+y],e[o+y+1],e[o+y+2]),T=St.checkNoDataValue(i,v),(T||0===v)&&s&&(v=Xt(w,x,b,s,Math.floor((C+1)/p),Math.floor(E/p),c));let r=.5*(a+v);l||T||(r=.5*(a+v)),M=(S+1)*f+R+A,P[M]=r,(E+A)%p==0&&(d[n++]=r);let h=(S+1)%u*f+R+A;_[L+1][A][h]=r}if((E+1)%u==0&&E!==g-1&&(C+1)%u==0&&C!==g-1){let r=t*this.rgb2Height(e[o+y+4],e[o+y+5],e[o+y+6]),g=St.checkNoDataValue(i,r);(g||0===r)&&s&&(r=Xt(w,x,b,s,Math.floor((C+1)/p),Math.floor((E+1)/p),c));let B=a;l||h||T||g||(B=.25*(a+m+v+r)),M=(S+1)*f+(R+1),P[M]=B,d[n++]=B;let k=(S+1)*f;_[L][A+1][k]=B;let I=u;_[L+1][A][I]=B;let z=0;_[L+1][A+1][z]=B}}}extractElevationTilesRgbNoChildren(e,t,i,s=null,r,n,o,a,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]=rr(a,l,h,r,n,o);for(let r=0,n=0,o=e.length/4;r<o;r++){let o=4*r,a=t*this.rgb2Height(e[o],e[o+1],e[o+2]),l=St.checkNoDataValue(i,a),h=!1,w=!1,T=Math.floor(r/f),C=r%f;(l||0===a)&&s&&(a=Xt(b,y,x,s,Math.floor(n/u),n%u,c));let E=Math.floor(C/_),A=Math.floor(T/_);if((T+A)%g==0&&(C+E)%g==0&&(d[n++]=a),(C+1)%_==0&&C!==f-1){p=t*this.rgb2Height(e[o+4],e[o+5],e[o+6]),h=St.checkNoDataValue(i,p),(h||0===p)&&s&&(p=Xt(b,y,x,s,Math.floor(n/u),n%u,c));let r=a;l||h||(r=.5*(a+p)),(T+A)%g==0&&(d[n++]=r)}if((T+1)%_==0&&T!==f-1){v=4*f,m=t*this.rgb2Height(e[o+v],e[o+v+1],e[o+v+2]),w=St.checkNoDataValue(i,m),(w||0===m)&&s&&(m=Xt(b,y,x,s,Math.floor(n/u),n%u,c));let r=.5*(a+m);l||w||(r=.5*(a+m)),(C+E)%g==0&&(d[n++]=r)}if((C+1)%_==0&&C!==f-1&&(T+1)%_==0&&T!==f-1){let r=t*this.rgb2Height(e[o+v+4],e[o+v+5],e[o+v+6]),_=St.checkNoDataValue(i,r);(_||0===r)&&s&&(r=Xt(b,y,x,s,Math.floor(n/u),n%u,c));let f=a;l||h||w||_||(f=.25*(a+p+m+r)),d[n++]=f}}}}function rr(e,t,i,s,r,n){let o=2<<i-n-1;return[e-o*s,t-o*r,1/o]}function Xt(e,t,i,s,r,n,o){let a=Math.sqrt(s.length),l=s[Math.floor(i*e*a+r*e)*a+Math.floor(t*e*a+n*e)];return o&&l>0?0:l}const ac={[Le]:"north",[Pe]:"south"},lc=(e,t,i,s)=>{let r=ac[s];if(r)return`https://terrain.openglobus.org/poles/${r}/${i}/${e}/${t}.png`};class hc extends St{constructor(e,t){super(e||"GlobusEarthRgb",{maxNativeZoom:6,maxZoom:17,url:"https://{s}.terrain.openglobus.org/all/{z}/{x}/{y}.png",urlRewrite:lc,...t})}isReadyToLoad(e){return this._extent.overlaps(e.getExtentLonLat())}}const Vc=Object.freeze(Object.defineProperty({__proto__:null,BilTerrain:je,EmptyTerrain:Mi,GlobusRgbTerrain:hc,GlobusTerrain:gn,RgbTerrain:St},Symbol.toStringTag,{value:"Module"}));class cc extends Ai{constructor(e,t={}){super(e,t),this._sourceTexture=t.texture||null,t.texture&&(this._sourceReady=!0,this._sourceCreated=!0),this._frameWidth=null!=t.frameWidth?$e(t.frameWidth):256,this._frameHeight=null!=t.frameHeight?$e(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 dc extends Ai{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 uc extends _t{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),s=parseInt(e.slice(4,6),16);return`rgba(${parseInt(e.slice(6,8),16)},${s},${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")),s=i&&i.length>0?i[0].innerHTML.trim():"",{iconHeading:r,iconURL:n,iconColor:o,lineWidth:a,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,s,r]=i;h.push(new L(e,s,r)),e<t.southWest.lon&&(t.southWest.lon=e),s<t.southWest.lat&&(t.southWest.lat=s),e>t.northEast.lon&&(t.northEast.lon=e),s>t.northEast.lat&&(t.northEast.lat=s)}}if(1===h.length){const e=.01745329*r;return new G({name:s,lonlat:h[0],billboard:{src:n,size:[24,24],color:o,rotation:e},properties:{color:o,heading:r}})}return new G({name:s,polyline:{pathLonLat:[h],thickness:a,color:l,isClosed:!1},properties:{name:s}})}_extractStyle(e){let t,i,s,r,n;const o=e.getElementsByTagName("Style")[0];if(o){let e=o.getElementsByTagName("IconStyle")[0];if(e){let r=e.getElementsByTagName("color")[0];r&&(t=this._AGBRtoRGBA(r.innerHTML.trim()));let n=e.getElementsByTagName("heading")[0];if(n){const e=parseFloat(n.innerHTML.trim());e>=0&&e<=360&&(i=e%360)}let o=e.getElementsByTagName("Icon")[0];if(o){let e=o.getElementsByTagName("href")[0];e&&(s=e.innerHTML.trim())}}let a=o.getElementsByTagName("LineStyle")[0];if(a){let e=a.getElementsByTagName("color")[0];e&&(r=this._AGBRtoRGBA(e.innerHTML.trim()));let t=a.getElementsByTagName("width")[0];void 0!==t&&(n=parseFloat(t.innerHTML.trim()))}}return t||(t="#FFFFFF"),i||(i=0),s||(s="https://openglobus.org/examples/billboards/carrot.png"),r||(r="#FFFFFF"),n||(n=1),{iconHeading:i,iconURL:s,iconColor:t,lineWidth:n,lineColor:r}}_parseKML(e,t,i){if(i||(i=[]),"kml"!==e.documentElement.nodeName)return i;for(const s of e.getElementsByTagName("Placemark")){const e=this._kmlPlacemarkToEntity(s,t);e&&i.push(e)}return i}_convertKMLintoEntities(e){const t=new U(new L(180,90),new L(-180,-90));return{entities:this._parseKML(e,t),extent:t}}_convertCoordonatesIntoEntities(e,t,i){const s=new U(new L(180,90),new L(-180,-90)),r=e=>{const t=e[0],i=e[1];t<s.southWest.lon&&(s.southWest.lon=t),i<s.southWest.lat&&(s.southWest.lat=i),t>s.northEast.lon&&(s.northEast.lon=t),i>s.northEast.lat&&(s.northEast.lat=i)},n=[];return e.forEach((e=>e.forEach((e=>n.push(e))))),{entities:n.map((e=>{if(1===e.length){const t=e[0],s=new G({lonlat:t,billboard:i});return r(t),s}if(e.length>1){const i=e.map((e=>(r(e),new L(e[0],e[1],e[2]))));return new G({polyline:{pathLonLat:[i],thickness:3,color:t,isClosed:!1}})}})),extent:s}}_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 s=(await Promise.all(e.map(this._getXmlContent))).map(this._extractCoordonatesFromKml),{entities:r,extent:n}=this._convertCoordonatesIntoEntities(s,t||this._color,i||this._billboard);return this._extent=this._expandExtents(this._extent,n),r.forEach(this.add.bind(this)),{entities:r,extent:n}}setColor(e){this._color=e,this._billboard.color=e}_getKmlFromUrl(e){return new Promise(((t,i)=>{const s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="document",s.overrideMimeType("text/xml"),s.onload=()=>{s.readyState===s.DONE&&200===s.status?t(s.responseXML):i(new Error("no valid kml file"))},s.send()}))}async addKmlFromUrl(e,t,i){const s=await this._getKmlFromUrl(e),{entities:r,extent:n}=this._convertKMLintoEntities(s);return this._extent=this._expandExtents(this._extent,n),r.forEach(this.add.bind(this)),{entities:r,extent:n}}}class _c extends Ds{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 fc(e,t,i){var s="";for(let o=i;o>0;o--){var r=0,n=1<<o-1;e&n&&r++,t&n&&(r+=2),s+=r.toString()}return s}class gc extends Ds{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,textureFilter:"LINEAR",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)=>Dt(t,{s:this._getSubdomain(),quad:fc(e.tileX,e.tileY,e.tileZoom)}),specular:[63e-5,55e-5,32e-5],ambient:[.35,.35,.35],diffuse:[1.5,1.5,1.5],shininess:20,nightTextureCoefficient:2.7,...t})}}const Uc=Object.freeze(Object.defineProperty({__proto__:null,Bing:gc,CanvasTiles:ss,GeoImage:Ca,GeoTexture2d:cc,GeoVideo:dc,KML:uc,LAYER_EVENTS:Go,Layer:zt,Material:Uo,OpenStreetMap:_c,Vector:_t,WMS:me,XYZ:Ds},Symbol.toStringTag,{value:"Module"})),nr=function(e,t){return+(e.priority<t.priority)};class pc{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 s=this._getStamp(e,t,i._openglobus_id);i._openglobus_id&&this._stampCache[s]&&(delete this._stampCache[s],"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 s=Yr(i),r=this._getStamp(e,t,s);return!this._stampCache[r]&&(this._stampCache[r]=s,!0)}setActivity(e){this._active=e}releaseKeys(){this._currentlyPressedKeys={}}addEvent(e,t,i,s,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:s,priority:r}),this._unpressedKeysCallbacks[t].sort(nr);break;case"keypress":null==t?this._anykeyCallback={callback:i,sender:s||this}:(this._pressedKeysCallbacks[t]||(this._pressedKeysCallbacks[t]=[]),this._pressedKeysCallbacks[t].push({callback:i,sender:s,priority:r}),this._pressedKeysCallbacks[t].sort(nr));break;case"charkeypress":this._charkeysCallbacks[t]||(this._charkeysCallbacks[t]=[]),this._charkeysCallbacks[t].push({callback:i,sender:s,priority:r}),this._charkeysCallbacks[t].sort(nr)}}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!=W.KEY_ALT&&this._event.keyCode!=W.KEY_SHIFT||this._event.preventDefault()}handleKeyUp(){if(this._currentlyPressedKeys[this._event.keyCode]||this._event.keyCode===W.KEY_PRINTSCREEN)for(let e in this._unpressedKeysCallbacks)if(this._currentlyPressedKeys[e]||this._event.keyCode===W.KEY_PRINTSCREEN&&Number(e)===W.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 mc{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"mousewheel":this._htmlObject.addEventListener("wheel",(e=>{let s=e.deltaY||e.detail||e.wheelDelta||0;var r;null==e.wheelDelta&&(e.wheelDelta=-120*s),e.isTouchPad=0===(r=e).deltaMode&&Math.abs(r.deltaY)<50,i.call(t,e),e.preventDefault()}),!1);break;case"mousedown":this._htmlObject.addEventListener("mousedown",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-s.left,clientY:e.clientY-s.top})})),this._htmlObject.addEventListener("contextmenu",(function(e){return e.preventDefault(),!1}));break;case"mouseup":this._htmlObject.addEventListener("mouseup",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-s.left,clientY:e.clientY-s.top})}));break;case"mousemove":this._htmlObject.addEventListener("mousemove",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{clientX:e.clientX-s.left,clientY:e.clientY-s.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 vc{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"touchcancel":this._htmlObject.addEventListener("touchcancel",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,r)}));break;case"touchstart":this._htmlObject.addEventListener("touchstart",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,r)}));break;case"touchend":this._htmlObject.addEventListener("touchend",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,r)}));break;case"touchmove":this._htmlObject.addEventListener("touchmove",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,r)}))}}}let _e=new Uint8Array(4),ei=new Uint8Array(4),ii=new Uint8Array(4);class yc extends bi{constructor(e){super(xc),this.renderer=e,this._touchHandler=new vc(e.handler.canvas),this._mouseHandler=new mc(e.handler.canvas),this._keyboardHandler=new pc,this._active=!0,this.clickRadius=15,this.mouseState={clientX:0,clientY:0,pos:new H,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new v,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,isTouchPad:!1},this.touchState={touching:!1,moving:!1,touchEnd:!1,touchStart:!1,touchCancel:!1,doubleTouch:!1,doubleTouchDelay:550,doubleTouchRadius:10,clientX:0,clientY:0,pos:new H,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new v,sys:null,pickingObject:null,renderer:e},this._isMouseInside=!0,this._entityPickingEventsActive=!0,this._dblTchCoords=new H,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;return e.moving||e.justStopped||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,s,r){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.addEvent(e,t,i,s,r):super.on(e,t,i,s)}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.isTouchPad=e.isTouchPad||!1,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 s=t.clientX,r=t.clientY,n=this.clickRadius;if(Math.abs(this._lclickX-s)>=n&&Math.abs(this._lclickY-r)>=n&&(this._ldblClkBegins=0,this._lClkBegins=0),Math.abs(this._rclickX-s)>=n&&Math.abs(this._rclickY-r)>=n&&(this._rdblClkBegins=0,this._rClkBegins=0),Math.abs(this._mclickX-s)>=n&&Math.abs(this._mclickY-r)>=n&&(this._mdblClkBegins=0,this._mClkBegins=0),i.clientX===t.clientX&&i.clientY===t.clientY)return;i.clientX=t.clientX,i.clientY=t.clientY;let o=this.renderer.handler;i.pos.x=i.x=t.clientX*o.pixelRatio,i.pos.y=i.y=t.clientY*o.pixelRatio,i.nx=i.x/o.canvas.width,i.ny=i.y/o.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===W.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===W.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===W.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 s=window.performance.now();t.button===W.MB_LEFT?(i.leftButtonDown=!1,i.leftButtonUp=!0,Math.abs(this._lclickX-t.clientX)<this.clickRadius&&Math.abs(this._lclickY-t.clientY)<this.clickRadius&&s-this._lClkBegins<=i.clickDelay&&(this._ldblClkBegins?(window.performance.now()-this._ldblClkBegins<=i.doubleClickDelay&&(i.leftButtonDoubleClick=!0),this._ldblClkBegins=0):this._ldblClkBegins=window.performance.now(),i.leftButtonClick=!0,this._lClkBegins=0)):t.button===W.MB_RIGHT?(i.rightButtonDown=!1,i.rightButtonUp=!0,Math.abs(this._rclickX-t.clientX)<this.clickRadius&&Math.abs(this._rclickY-t.clientY)<this.clickRadius&&s-this._rClkBegins<=i.clickDelay&&(this._rdblClkBegins?(window.performance.now()-this._rdblClkBegins<=i.doubleClickDelay&&(i.rightButtonDoubleClick=!0),this._rdblClkBegins=0):this._rdblClkBegins=window.performance.now(),i.rightButtonClick=!0,this._rClkBegins=0)):t.button===W.MB_MIDDLE&&(i.middleButtonDown=!1,i.middleButtonUp=!0,Math.abs(this._mclickX-t.clientX)<this.clickRadius&&Math.abs(this._mclickY-t.clientY)<this.clickRadius&&s-this._mClkBegins<=i.clickDelay)&&(this._mdblClkBegins?(window.performance.now()-this._mdblClkBegins<=i.doubleClickDelay&&(i.middleButtonDoubleClick=!0),this._mdblClkBegins=0):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,t.touching=!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;t.sys=e,t.touchEnd=!0,0===e.touches.length&&(t.prev_x=t.x,t.prev_y=t.y,this._oneTouchStart)&&(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 s=t.x-t.prev_x,r=t.y-t.prev_y;(Math.abs(s)>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,s=_e,r=i.getPickingObjectArr(s);if(r){let i=r.rendererEvents;t.pickingObject=r,i&&i.dispatch(i.mouseleave,t),e.pickingObject=r,i&&i.dispatch(i.touchleave,e)}_e[0]=_e[1]=_e[2]=_e[3]=ii[0]=ii[1]=ii[2]=ii[3]=ei[0]=ei[1]=ei[2]=ei[3]=0}if(this._isMouseInside&&!(t.leftButtonHold||t.rightButtonHold||t.middleButtonHold)){let s=this.renderer,r=_e,n=ii,o=ei;e.x||e.y?s.readPickingColor(e.nx,1-e.ny,o):s.readPickingColor(t.nx,1-t.ny,o),n[0]=r[0],n[1]=r[1],n[2]=r[2],r[0]=o[0],r[1]=o[1],r[2]=o[2],t.pickingObject=null,e.pickingObject=null;let a=s.getPickingObjectArr(r);if(t.pickingObject=a,e.pickingObject=a,r[0]!==n[0]||r[1]!==n[1]||r[2]!==n[2])if((i=r)[0]||i[1]||i[2]){if((e=>!!(e[0]||e[1]||e[2]))(n)){let i=s.getPickingObjectArr(n);if(i){let s=i.rendererEvents;t.pickingObject=i,s&&s.dispatch(s.mouseleave,t),e.pickingObject=i,s&&s.dispatch(s.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)}}else{let i=s.getPickingObjectArr(n);if(i){let s=i.rendererEvents;t.pickingObject=i,s&&s.dispatch(s.mouseleave,t),e.pickingObject=i,s&&s.dispatch(s.touchleave,e)}}}var i}handleMouseEvents(){let e=this,t=this.mouseState,i=t.pickingObject,s=null;t.leftButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.lclick,t)),this.dispatch(e.lclick,t),t.leftButtonClick=!1),t.rightButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rclick,t)),this.dispatch(e.rclick,t),t.rightButtonClick=!1),t.middleButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mclick,t)),this.dispatch(e.mclick,t),t.middleButtonClick=!1),t.leftButtonDown&&(t.leftButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.lhold,t)),this.dispatch(e.lhold,t)):(t.leftButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.ldown,t)),this.dispatch(e.ldown,t))),t.rightButtonDown&&(t.rightButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.rhold,t)),this.dispatch(e.rhold,t)):(t.rightButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.rdown,t)),this.dispatch(e.rdown,t))),t.middleButtonDown&&(t.middleButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.mhold,t)),this.dispatch(e.mhold,t)):(t.middleButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.mdown,t)),this.dispatch(e.mdown,t))),t.leftButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.lup,t)),this.dispatch(e.lup,t),t.leftButtonUp=!1,t.leftButtonHold=!1),t.rightButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rup,t)),this.dispatch(e.rup,t),t.rightButtonUp=!1,t.rightButtonHold=!1),t.middleButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mup,t)),this.dispatch(e.mup,t),t.middleButtonUp=!1,t.middleButtonHold=!1),t.leftButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.ldblclick,t)),this.dispatch(e.ldblclick,t),t.leftButtonDoubleClick=!1),t.rightButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rdblclick,t)),this.dispatch(e.rdblclick,t),t.rightButtonDoubleClick=!1),t.middleButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mdblclick,t)),this.dispatch(e.mdblclick,t),t.middleButtonDoubleClick=!1),t.wheelDelta&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mousewheel,t)),this.dispatch(e.mousewheel,t)),t.moving&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.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,s=null;if(t.touchCancel&&(this.dispatch(e.touchcancel,t),t.touchCancel=!1),t.touchStart){let r=this.renderer;r.readPickingColor(t.nx,1-t.ny,_e);let n=r.getPickingObjectArr(_e);i=t.pickingObject=n,i&&(s=i.rendererEvents,s&&s.dispatch(s.touchstart,t)),this.dispatch(e.touchstart,t),t.touchStart=!1}t.doubleTouch&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.doubletouch,t)),this.dispatch(e.doubletouch,t),t.doubleTouch=!1),t.touchEnd&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.touchend,t)),this.dispatch(e.touchend,t),t.x=0,t.y=0,t.touchEnd=!1,t.touching=!1),t.moving&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.touchmove,t)),this.dispatch(e.touchmove,t),t.prev_x=t.x,t.prev_y=t.y)}}const xc=["projchanged","changerelativecenter","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 Ii{constructor(e=0,t=0,i=0,s=0){this.left=e,this.right=i,this.top=t,this.bottom=s}set(e=0,t=0,i=0,s=0){this.left=e,this.right=i,this.top=t,this.bottom=s}clone(){return new Ii(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 bc{constructor(){this.imagesCache={},this._counter=0,this._pendingsQueue=new dn,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 Vr{constructor(e=1024,t=1024){this.nodes=new Map,this.texture=null,this.canvas=new mi(e,t),this.clearCanvas(),this._handler=null,this._images=[],this._btree=null,this._imagesCacheManager=new bc,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(),s=this.canvas.getHeight(),r=t.image,n=t.rect,o=Math.round(.5*this.borderSize);this.canvas.drawImage(r,n.left+o,n.top+o,r.atlasWidth||0,r.atlasHeight||0);let a=t.texCoords;a[0]=(n.left+o)/i,a[1]=(n.top+o)/s,a[2]=(n.left+o)/i,a[3]=(n.bottom-o)/s,a[4]=(n.right-o)/i,a[5]=(n.bottom-o)/s,a[6]=(n.right-o)/i,a[7]=(n.bottom-o)/s,a[8]=(n.right-o)/i,a[9]=(n.top+o)/s,a[10]=(n.left+o)/i,a[11]=(n.top+o)/s,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 Bi(new Ii(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 Bi{constructor(e,t){this.childNodes=null,this.image=null,this.rect=e||new Ii,this.texCoords=t||[],this.atlas=null}insert(e){if(this.childNodes)return this.childNodes[0].insert(e)||this.childNodes[1].insert(e);{if(null!=this.image)return;let t=this.rect;const i=(e.atlasWidth||e.width)+this.atlas.borderSize,s=(e.atlasHeight||e.height)+this.atlas.borderSize;return i>t.getWidth()||s>t.getHeight()?void 0:t.fit(i,s)?(this.image=e,this):(this.childNodes=new Array(2),this.childNodes[0]=new Bi,this.childNodes[0].atlas=this.atlas,this.childNodes[1]=new Bi,this.childNodes[1].atlas=this.atlas,t.getWidth()-i>t.getHeight()-s?(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+s),this.childNodes[1].rect.set(t.left,t.top+s,t.right,t.bottom)),this.childNodes[0].insert(e))}}}class _o extends Vr{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 wc extends Bi{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 Tc{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 pi),this.atlasIndexesDeferred[t].promise}getFullIndex(e){return e.trim().toLowerCase()}_applyFontDataToAtlas(e,t,i=0){let s=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,n=e.height,o=e.gliphSize;this.sdfParamsArr[4*i]=r,this.sdfParamsArr[4*i+1]=n,this.sdfParamsArr[4*i+2]=o,this.sdfParamsArr[4*i+3]=e.distanceRange;let a={};for(let t=0;t<s.length;t++){let i=s[t],l=i.char;a[i.id]=l;let h=new Ii(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/n,c[2]=h.left/r,c[3]=h.bottom/n,c[4]=h.right/r,c[5]=h.bottom/n,c[6]=h.right/r,c[7]=h.bottom/n,c[8]=h.right/r,c[9]=h.top/n,c[10]=h.left/r,c[11]=h.top/n;let d=new wc(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/o,f.nHeight=d.metrics.height/o,f.nAdvance=d.metrics.xadvance/o,f.nXOffset=d.metrics.xoffset/o,f.nYOffset=1-d.metrics.yoffset/o,d.emptySize=1,e.nodes.set(_.charCodeAt(0),d)}e.kernings={};for(let i=0;i<t.kernings.length;i++){let s=t.kernings[i],r=s.first,n=s.second;e.kernings[r]||(e.kernings[r]={}),e.kernings[r][n]=s.amount/o}}initFont(e,t,i){let s=this.atlasesArr.length,r=this.getFullIndex(e);this.atlasIndexes[r]=s;let n=this.atlasIndexesDeferred[r];n||(n=this.atlasIndexesDeferred[r]=new pi),this.samplerArr[this.atlasesArr.length]=s;let o=new _o;o.height=0,o.width=0,o.gliphSize=0,o.distanceRange=0,o.kernings={},o.assignHandler(this._handler),this.atlasesArr[s]=o,this._applyFontDataToAtlas(o,t,s);let a=new Image;a.onload=()=>{this._createTexture(o,a),n.resolve(s)},a.src=i}_createTexture(e,t){e.createTexture(t)}loadFont(e,t,i){let s=this.atlasesArr.length,r=this.getFullIndex(e);this.atlasIndexes[r]=s;let n=this.atlasIndexesDeferred[r];n||(n=this.atlasIndexesDeferred[r]=new pi),this.samplerArr[this.atlasesArr.length]=s;let o=new _o;o.height=0,o.width=0,o.gliphSize=0,o.distanceRange=0,o.kernings={},o.assignHandler(this._handler),this.atlasesArr[s]=o,fetch(`${t}/${i}`).then((e=>{if(!e.ok)throw Error(`Unable to load "${t}/${i}"`);return e.json()})).then((e=>{this._applyFontDataToAtlas(o,e,s);let i=new Image;i.onload=()=>{this._createTexture(o,i),n.resolve(s)},i.src=`${t}/${e.pages[0]}`,i.crossOrigin="Anonymous"})).catch((e=>(n.reject(),{status:"error",msg:e.toString()})))}}let Cc=0,Ec=0,He=new Float32Array(2);class Ac{constructor(e,t={}){var i,s;if(this.div=null,this.handler=e instanceof Be?e:new Be(e,{pixelRatio:t.dpi||window.devicePixelRatio+.15,autoActivate:!0}),this.clearColor=new Float32Array(t.clearColor||[0,0,0,1]),this.exposure=t.exposure||3.01,this.gamma=t.gamma||.47,this.whitepoint=1,this.brightThreshold=.9,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=new Pi({width:null==(i=this.handler.canvas)?void 0:i.width,height:null==(s=this.handler.canvas)?void 0:s.height,eye:new v(0,0,0),look:new v(0,0,-1),up:new v(0,1,0)}),this.events=new yc(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._depthCallbacks=[],this.depthFramebuffer=null,this._depthRefreshRequired=!1;let r=new URLSearchParams(location.search),n=r.get("og_msaa");this._msaa=n?Number(r.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 Vr,this.fontAtlas=new Tc(t.fontsSrc),this.strokeTextureAtlas=new Vr,this._entityCollections=[[]],this._currentOutput="screen",this._fnScreenFrame=null,this.labelWorker=new Ka(4),this.screenDepthFramebuffer=null,this.screenFramePositionBuffer=null,this.screenTexture={},this.outputTexture=null,this._readPickingBuffer=this._readPickingBuffer_webgl2,(t.autoActivate||Gt(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)}setRelativeCenter(e){this.events.dispatch(this.events.changerelativecenter,e||this.activeCamera.eye)}setEventsActivity(e){this.events.active=e}addDepthCallback(e,t){let i=Ec++;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}}addPickingCallback(e,t){let i=Cc++;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,s=0,r="0_0_0";for(;!(t||i||s)||this.colorObjects.has(r);)t=Ni(1,255),i=Ni(1,255),s=Ni(1,255),r=`${t}_${i}_${s}`;e._pickingColor?e._pickingColor.set(t,i,s):e._pickingColor=new v(t,i,s),e._pickingColorU=new Float32Array([t/255,i/255,s/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 H(Math.round(.5*e.width),Math.round(.5*e.height))}getClientCenter(){let e=this.handler.canvas;return new H(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.fontAtlas.assignHandler(this.handler),this.strokeTextureAtlas.assignHandler(this.handler),this.handler.setFrameCallback((()=>{this.draw()})),this.events.initialize(),this.events.on("charkeypress",W.KEY_APOSTROPHE,(function(){ie.setVisibility(!ie.getVisibility())})),this.handler.addProgram(new X("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 Rt(this.handler,{width:640,height:480,targets:[{readAsync:!0}]}),this.pickingFramebuffer.init(),this.depthFramebuffer=new Rt(this.handler,{width:640,height:480,targets:[{internalFormat:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT",readAsync:!0},{internalFormat:"RGBA16F",type:"FLOAT",attachment:"COLOR_ATTACHMENT",readAsync:!0}],useDepth:!0}),this.depthFramebuffer.init(),this.screenDepthFramebuffer=new Rt(this.handler,{useDepth:!1}),this.screenDepthFramebuffer.init(),"webgl"===this.handler.gl.type)this._readPickingBuffer=this._readPickingBuffer_webgl1,this.sceneFramebuffer=new Rt(this.handler),this.sceneFramebuffer.init(),this._fnScreenFrame=this._screenFrameNoMSAA,this.screenTexture={screen:this.sceneFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0]};else{let e=this.getMaxMSAA(this._internalFormat);this._msaa>e&&(this._msaa=e),this.handler.addPrograms([new X("toneMapping",{uniforms:{hdrBuffer:"sampler2d",exposure:"float",gamma:"float",whitepoint:"float"},attributes:{corners:"vec3"},vertexShader:"#version 300 es\nin vec2 corners;out vec2 tc;void main(void){gl_Position=vec4(corners,0.0,1.0);tc=corners*0.5+0.5;}",fragmentShader:"#version 300 es\nprecision highp float;\n#ifndef saturate\n#define saturate(a) clamp(a, 0.0, 1.0)\n#endif\nuniform sampler2D hdrBuffer;uniform float whitepoint;uniform float exposure;uniform float gamma;vec3 LinearToneMapping(vec3 color){return exposure*color;}vec3 ReinhardToneMapping2(vec3 color){return vec3(1.0)-exp(-color*exposure);}vec3 ReinhardToneMapping(vec3 color){color*=exposure;return saturate(color/(vec3(1.0)+color));}\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))\nvec3 Uncharted2ToneMapping(vec3 color){color*=exposure;return saturate(Uncharted2Helper(color)/Uncharted2Helper(vec3(whitepoint)));}vec3 OptimizedCineonToneMapping(vec3 color){color*=exposure;color=max(vec3(0.0),color-0.004);return pow((color*(6.2*color+0.5))/(color*(6.2*color+1.7)+0.06),vec3(2.2));}vec3 ACESFilmicToneMapping(vec3 color){color*=exposure;return saturate((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14));}in vec2 tc;layout(location=0)out vec4 fragColor;void main(void){vec4 hdrColor=texture(hdrBuffer,tc);float oneByGamma=gamma/gamma;float oneByWhitePoint=whitepoint/whitepoint;vec3 mapped=ReinhardToneMapping2(hdrColor.rgb)*oneByGamma*oneByWhitePoint;mapped=pow(mapped,vec3(1.0/gamma));fragColor=vec4(mapped,hdrColor.a);}"})]),this.handler.addPrograms([new X("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 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 return texture(depthTexture, tc).r;\n }\n \n void main(void) {\n float c = LinearizeDepth(tc);\n fragColor = vec4(c, c, c, 1.0);\n }"})]),this.sceneFramebuffer=new Ta(this.handler,{size:1,msaa:this._msaa,internalFormat:this._internalFormat,filter:"LINEAR"}),this.sceneFramebuffer.init(),this.blitFramebuffer=new Rt(this.handler,{size:1,useDepth:!1,targets:[{internalFormat:this._internalFormat,format:this._format,type:this._type,filter:"NEAREST"}]}),this.blitFramebuffer.init(),this.toneMappingFramebuffer=new Rt(this.handler,{useDepth:!1}),this.toneMappingFramebuffer.init(),this._fnScreenFrame=this._screenFrameMSAA,this.screenTexture={screen:this.toneMappingFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0],frustum:this.depthFramebuffer.textures[0]}}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()}}_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.setViewportSize(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.setViewportSize(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.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.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.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]?ie.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])ie.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,t=0){this._entityCollections[t]||(this._entityCollections[t]=[]),this._entityCollections[t].push(...e)}markForDepthRefresh(){this._depthRefreshRequired=!0}_drawEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=this.handler.gl;this.enableBlendDefault();let i=t.length;for(;i--;)t[i]._fadingOpacity&&t[i].pointCloudHandler.draw();for(i=t.length;i--;){let e=t[i];t[i]._fadingOpacity&&(e.events.dispatch(e.events.draw,e),t[i].geoObjectHandler.draw())}for(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.billboardsTextureAtlas.texture),i=t.length;i--;){let e=t[i];e._fadingOpacity&&e.billboardHandler.draw()}let s=this.fontAtlas.atlasesArr;for(i=0;i<s.length;i++)e.activeTexture(e.TEXTURE0+i),e.bindTexture(e.TEXTURE_2D,s[i].texture);for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].labelHandler.draw();for(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.strokeTextureAtlas.texture),i=t.length;i--;)t[i]._fadingOpacity&&t[i].rayHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].polylineHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].stripHandler.draw()}}_drawPickingEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=t.length;for(;e--;)t[e]._fadingOpacity&&t[e].billboardHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].geoObjectHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].labelHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].rayHandler.drawPicking();for(e=t.length;e--;)t[e]._visibility&&t[e].polylineHandler.drawPicking();for(e=t.length;e--;)t[e]._visibility&&t[e].stripHandler.drawPicking()}}_drawDepthEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=t.length;for(;e--;)t[e]._fadingOpacity&&t[e].geoObjectHandler.drawDepth()}}_clearEntityCollectionQueue(e){this._entityCollections[e].length=0,this._entityCollections[e]=[]}draw(){this.activeCamera.checkMoveEnd();let e=this.events,t=e.pointerEvent(),i=!e.mouseState.leftButtonDown&&!e.mouseState.rightButtonDown,s=e.touchState.touchStart||e.touchState.touchEnd;const r=t&&i||s||this._depthRefreshRequired;this._depthRefreshRequired=!1,e.handleEvents();let n=this.sceneFramebuffer;n.activate();let o=this.handler.gl;o.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),o.clear(o.COLOR_BUFFER_BIT|o.DEPTH_BUFFER_BIT),this.enableBlendDefault(),e.dispatch(e.draw,this),this.activeCamera.checkFly();let a=this.activeCamera.frustums,l=this._renderNodesArr,h=a.length;for(;h--;){this.activeCamera.setCurrentFrustum(h),o.clear(o.DEPTH_BUFFER_BIT);let t=l.length;for(;t--;)l[t].preDrawNode();for(t=l.length;t--;)this.enableBlendDefault(),l[t].drawNode();this._drawEntityCollections(0),e.dispatch(e.drawtransparent,this),r&&this._drawPickingBuffer(0),this._drawDepthBuffer(0),this._clearEntityCollectionQueue(0)}for(let e=1;e<this._entityCollections.length;e++){o.clear(o.DEPTH_BUFFER_BIT);let t=a.length;for(;t--;)this.activeCamera.setCurrentFrustum(t),this._drawEntityCollections(e),r&&this._drawPickingBuffer(e),this._drawDepthBuffer(e);this._clearEntityCollectionQueue(e)}n.deactivate(),this.blitFramebuffer&&n.blitTo(this.blitFramebuffer,0),r&&(this._readPickingBuffer(),this._readDepthBuffer()),this._fnScreenFrame(),e.dispatch(e.postdraw,this),e.mouseState.wheelDelta=0,e.mouseState.justStopped=!1,e.mouseState.moving=!1,e.touchState.moving=!1}getImageDataURL(e="image/png",t=1){return this.draw(),this.handler.canvas?this.handler.canvas.toDataURL(e,t):""}_screenFrameMSAA(){let e=this.handler,t=e.programs.toneMapping,i=t._program,s=e.gl;s.disable(s.DEPTH_TEST),s.bindBuffer(s.ARRAY_BUFFER,this.screenFramePositionBuffer),s.vertexAttribPointer(i.attributes.corners,2,s.FLOAT,!1,0,0),this.toneMappingFramebuffer.activate(),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT),t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.blitFramebuffer.textures[0]),s.uniform1i(i.uniforms.hdrBuffer,0),s.uniform1f(i.uniforms.gamma,this.gamma),s.uniform1f(i.uniforms.exposure,this.exposure),s.uniform1f(i.uniforms.whitepoint,this.whitepoint),s.drawArrays(s.TRIANGLE_STRIP,0,4),this.toneMappingFramebuffer.deactivate(),t=e.programs.screenFrame,i=t._program,t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.outputTexture),s.uniform1i(i.uniforms.texture,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.enable(s.DEPTH_TEST)}_screenFrameNoMSAA(){let e=this.handler,t=e.programs.screenFrame,i=t._program,s=e.gl;s.disable(s.DEPTH_TEST),t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.outputTexture),s.uniform1i(i.uniforms.texture,0),s.bindBuffer(s.ARRAY_BUFFER,this.screenFramePositionBuffer),s.vertexAttribPointer(i.attributes.corners,2,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.enable(s.DEPTH_TEST)}_drawPickingBuffer(e){this.pickingFramebuffer.activate();let t=this.handler.gl;if(this.activeCamera.isFirstPass&&0===e?(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)):t.clear(t.DEPTH_BUFFER_BIT),t.disable(t.BLEND),0===e){let e=this._pickingCallbacks;for(let t=0,i=e.length;t<i;t++)e[t].callback.call(e[t].sender)}this._drawPickingEntityCollections(e),t.enable(t.BLEND),this.pickingFramebuffer.deactivate()}_drawDepthBuffer(e){this.depthFramebuffer.activate();let t=this.handler,i=t.gl;if(i.disable(i.BLEND),this.activeCamera.isFirstPass&&0===e?(i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT)):i.clear(i.DEPTH_BUFFER_BIT),0===e){let e=this._depthCallbacks,t=e.length;for(;t--;)e[t].callback.call(e[t].sender)}if(this._drawDepthEntityCollections(e),this.depthFramebuffer.deactivate(),"depth"===this._currentOutput||"frustum"===this._currentOutput){this.screenDepthFramebuffer.activate();let e=t.programs.depth,s=e._program;i.bindBuffer(i.ARRAY_BUFFER,this.screenFramePositionBuffer),i.vertexAttribPointer(s.attributes.corners,2,i.FLOAT,!1,0,0),e.activate(),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.depthFramebuffer.textures[1]),i.uniform1i(s.uniforms.depthTexture,0),i.drawArrays(i.TRIANGLE_STRIP,0,4),this.screenDepthFramebuffer.deactivate()}i.enable(i.BLEND)}_readDepthBuffer(e){this.depthFramebuffer.readPixelBuffersAsync(e)}_readPickingBuffer_webgl1(){this.pickingFramebuffer.readPixelBuffersAsync()}_readPickingBuffer_webgl2(){this.pickingFramebuffer.readPixelBuffersAsync()}readPickingColor(e,t,i){var s;let r=this.pickingFramebuffer.width,n=this.pickingFramebuffer.height;e=Math.round(e*r);let o=4*((t=Math.round(t*n))*r+e),a=null==(s=this.pickingFramebuffer)?void 0:s.pixelBuffers[0].data;a&&(i[0]=a[o],i[1]=a[o+1],i[2]=a[o+2])}readDepth(e,t,i){let s=new Float32Array(4),r=new Uint8Array(4);this.depthFramebuffer.readData(e,t,r,0),this.depthFramebuffer.readData(e,t,s,1),i[0]=s[0],i[1]=Math.round(r[0]/10)-1}getDistanceFromPixel(e){let t=this.activeCamera,i=this.handler.canvas,s=e.x/i.width,r=(i.height-e.y)/i.height;if(He[0]=He[1]=0,this.readDepth(s,r,He),-1===He[1])return;let n=He[0],o=t.frustums[He[1]];if(!o)return;let a=new et(2*s-1,2*r-1,2*n-1,1),l=o.inverseProjectionMatrix.mulVec4(a),h=-l.z/l.w;if(t.isOrthographic)return h;let c=e.direction||t.unproject(e.x,e.y);return h/Math.max(1e-6,c.dot(t.getForward()))}getCartesianFromPixel(e){let t=this.getDistanceFromPixel(e);if(t){if(this.activeCamera.isOrthographic){let i=new v;return this.activeCamera.unproject(e.x,e.y,t,i),i}return(e.direction||this.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.activeCamera.eye)}}getCartesianFromPixelAsync(e){return new Promise(((t,i)=>{this._readDepthBuffer((()=>{t(this.getCartesianFromPixel(e))}))}))}getDepthMinDistance(){let e=this.handler.canvas,t=e.width,i=e.height,s=or,r=i*t,n=new H;for(let e=0;e<r;e++){n.x=e%t,n.y=Math.floor(e/t);let i=this.getDistanceFromPixel(n);i&&i<s&&(s=i)}return s<or?s:0}getDepthMinDistanceAsync(){return new Promise(((e,t)=>{this._readDepthBuffer((()=>{e(this.getDepthMinDistance())}))}))}async setOrthographicProjection(e){if(e!==this.activeCamera.isOrthographic){let t=await this.getDepthMinDistanceAsync();t&&e&&(this.activeCamera.focusDistance=t),this.activeCamera.isOrthographic=e,this.events.dispatch(this.events.projchanged,this.activeCamera)}}start(){this._initialized||this.initialize(),this.handler.start()}destroy(){this.labelWorker.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.controls={},this.controlsBag={},this.colorObjects.clear(),this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=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._initialized=!1}}const fo="/res",Ye=class e{constructor(t){this.$target=null,this._instanceID=`__globus${e.__counter__++?e.__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"),t.attributionContainer?t.attributionContainer.appendChild(this.$inner.attributions):(this.$inner.attributions.classList.add("og-attribution"),this.$inner.appendChild(this.$inner.attributions)),t.target&&this.attachTo(t.target);const i=e=>{e.preventDefault()};this._canvas.onmouseenter=function(){document.addEventListener("mousewheel",i,{capture:!1,passive:!1})},this._canvas.onmouseleave=function(){document.removeEventListener("mousewheel",i)},this.renderer=new Ac(new Be(this._canvas,{autoActivate:!1,pixelRatio:t.dpi||window.devicePixelRatio+.15,context:{alpha:t.transparentBackground,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1}}),{autoActivate:!1,msaa:t.msaa,fontsSrc:t.fontsSrc,gamma:t.gamma,exposure:t.exposure,...t.transparentBackground&&{clearColor:[0,0,0,0]}}),this.renderer.div=this.$inner,t.skybox&&this.renderer.addNode(t.skybox),this._planetName=t.name?t.name:"globus_planet_"+e.__counter__,this.planet=new Ri({name:this._planetName,frustums:t.frustums,ellipsoid:t.ellipsoid,maxGridSize:t.maxGridSize,nightTextureSrc:null===t.nightTextureSrc?null:t.nightTextureSrc||`${t.resourcesSrc||fo}/night.png`,specularTextureSrc:null===t.specularTextureSrc?null:t.specularTextureSrc||`${t.resourcesSrc||fo}/spec.png`,minAltitude:t.minAltitude,maxAltitude:t.maxAltitude||15e6,maxEqualZoomAltitude:t.maxEqualZoomAltitude,minEqualZoomAltitude:t.minEqualZoomAltitude,minEqualZoomCameraSlope:t.minEqualZoomCameraSlope,quadTreeStrategyPrototype:t.quadTreeStrategyPrototype,maxLoadingRequests:t.maxLoadingRequests,atmosphereEnabled:t.atmosphereEnabled,transitionOpacityEnabled:t.transitionOpacityEnabled,atmosphereParameters:t.atmosphereParameters,minDistanceBeforeMemClear:t.minDistanceBeforeMemClear,vectorTileSize:t.vectorTileSize,maxNodesCount:t.maxNodesCount,transparentBackground:t.transparentBackground}),t.terrain?Array.isArray(t.terrain)?this.planet.setTerrain(t.terrain[0]):this.planet.setTerrain(t.terrain):this.planet.setTerrain(new Mi),this.renderer.addNode(this.planet),t.controls?this.planet.addControls(t.controls):this.planet.addControls([new ma,new Yi,new pa,new da,new fa,new Ho,new Fr]);const s=this.renderer.controls;let r,n;for(let e in s)s[e]instanceof Dr&&(r=s[e]),s[e]instanceof Yi&&(n=s[e]);r?this.sun=r:(this.sun=new Dr,this.planet.addControl(this.sun)),t.sun&&(void 0===t.sun.active||t.sun.active||this.sun.deactivate(),!0===t.sun.stopped&&this.sun.stop()),n?this.navigation=n:(this.navigation=new Yi,this.planet.addControl(this.navigation)),t.navigation&&(void 0===t.navigation.active||t.navigation.active||this.navigation.deactivate(),void 0!==t.navigation.inertia&&(this.navigation.inertia=t.navigation.inertia),void 0!==t.navigation.dragInertia&&(this.navigation.dragInertia=t.navigation.dragInertia),void 0!==t.navigation.minSlope&&(this.navigation.minSlope=t.navigation.minSlope),void 0!==t.navigation.mass&&(this.navigation.mass=t.navigation.mass),void 0!==t.navigation.zoomSpeed&&(this.navigation.zoomSpeed=t.navigation.zoomSpeed),void 0!==t.navigation.mode&&this.navigation.setMode(t.navigation.mode),void 0!==t.navigation.poleThreshold&&(this.navigation.poleThreshold=t.navigation.poleThreshold),void 0!==t.navigation.disableRotation&&(this.navigation.disableRotation=t.navigation.disableRotation),void 0!==t.navigation.disableTilt&&(this.navigation.disableTilt=t.navigation.disableTilt)),t.layers&&this.planet.addLayers(t.layers);let o=t.viewExtent;o&&(o instanceof Array?this.planet.viewExtentArr(o):this.planet.viewExtent(o)),(t.autoActivate||Gt(t.autoActivate))&&this.start()}start(){this.renderer.start(),this.fadeIn()}fadeIn(){this._canvas.style.opacity="1.0"}fadeOut(){this._canvas.style.opacity="0"}attachTo(e,t){let i;this.detach(),i=e instanceof HTMLElement?e:document.getElementById(e)||document.querySelector(e),i?(this.$target=i,t&&this.$target.firstChild?this.$target.insertBefore(this.$inner,this.$target.firstChild):i.appendChild(this.$inner)):console.warn(`Target container not found. Provided target: ${e}`)}detach(){this.$target&&(this.$target.removeChild(this.$inner),this.$target=null)}destroy(){this.detach(),this.planet.layers.forEach((e=>e.remove())),this.planet.destroy(),this.renderer.destroy(),window[this._instanceID]=null}};Ye.__counter__=0;let go=Ye;const Gc=new qr(3396200,3389508),jc=new qr(1737400,1737400),Lc=`<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">${Vo}</div>\n </div>\n <div class="og-popup-title">{title}</div>\n </div>`,Pc=["open","close"];class qc extends ut{constructor(e){super({template:Dt(Lc,{title:e.title||""}),classList:e.className?[e.className]:[],...e}),this.events=this.events.registerNames(Pc),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=vi(e.lonLat),this._cartPos=new v,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,s=this._planet.ellipsoid.equatorialSize+t,r=i._lonLat.height,n=e.sub(i.eye);Math.sqrt((s+r)*(s+r)-s*s)>n.length()&&i.getForward().dot(n.normalize())>0?(this.el.style.display="block",this.setScreen(i.project3v(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="")}}const po=5/Math.pow(2,5);class ki extends Hr{constructor(e,t,i,s){super(e,t,i,s),this._projection=_n,this.isPole=!1,this._tileGroup=0}_getMaxZoom(){let e;if(this._extent.northEast.lat>85){let t=Math.floor((90-this._extent.northEast.lat)/po);e=Math.floor(t/16)+5}else if(this._extent.southWest.lat<-85){let t=Math.floor((90+this._extent.southWest.lat)/po);e=Math.floor(t/16)+5}else e=50;return e}_assignTileYIndexes(e){const t=e.getCenter().lat;this.tileY=At(t,e.getHeight(),90),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_assignTileXIndexes(e){let t=e.getCenter().lon;this.tileX=At(t,e.getWidth(),-180);let i=2*(1<<this.tileZoom);this.tileXE=(this.tileX+1)%i,this.tileXW=(i+this.tileX-1)%i}getDefaultTexture(){return this.planet.solidTextureOne}}class Ee extends pe{constructor(e,t,i,s,r,n){super(e,t,i,s,r,n),this.strategy=e}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),r=t.northEast,n=t.southWest,o=new L(n.lon+i,n.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new Ee(e,0,this,new U(new L(n.lon,n.lat+s),new L(n.lon+i,r.lat)),l,h),a[1]=new Ee(e,1,this,new U(o,new L(r.lon,r.lat)),l,h),a[2]=new Ee(e,2,this,new U(new L(n.lon,n.lat),o),l,h),a[3]=new Ee(e,3,this,new U(new L(n.lon+i,n.lat),new L(r.lon,n.lat+s)),l,h)}_setExtentBounds(){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.strategy._renderingNodesWest[this.nodeId]||!!this.strategy._renderingNodesEast[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.extent.southWest.lon<0?this.strategy._renderingNodesWest[this.nodeId]=!0:this.strategy._renderingNodesEast[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.strategy._queueDeferredNode(this):this.applyCollection());const s=this.entityCollection;s._fadingOpacity=this.layer._fadingOpacity,s.scaleByDistance=this.layer.scaleByDistance,s.pickingScale=this.layer.pickingScale,s.isEmpty()||e.push(s)}}class Sc extends un{constructor(e,t,i){super(e,t,i);let s=t._planet;this._entityCollectionsTreeWest=new Ee(this,0,null,U.createFromArray([-180,-90,0,90]),s,0),this._entityCollectionsTreeEast=new Ee(this,0,null,U.createFromArray([0,-90,180,90]),s,0),this._renderingNodesWest={},this._renderingNodesEast={}}insertEntity(e,t=!1){e._lonLat.lon<0?(this._entityCollectionsTreeWest.__setLonLat__(e),this._entityCollectionsTreeWest.insertEntity(e,t)):(this._entityCollectionsTreeEast.__setLonLat__(e),this._entityCollectionsTreeEast.insertEntity(e,t))}setPickingEnabled(e){this._entityCollectionsTreeWest.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeEast.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)}))}dispose(){this._entityCollectionsTreeWest=null,this._entityCollectionsTreeEast=null,this._renderingNodesWest={},this._renderingNodesEast={}}insertEntities(e){let t=[],i=[];for(let s=0,r=e.length;s<r;s++){let r=e[s];r._lonLat.lon<0?(t.push(r),this._entityCollectionsTreeWest.__setLonLat__(r)):(i.push(r),this._entityCollectionsTreeEast.__setLonLat__(r))}this._entityCollectionsTreeWest.buildTree(t),this._entityCollectionsTreeEast.buildTree(i)}collectVisibleEntityCollections(e){this._renderingNodesWest={},this._renderingNodesEast={};let t=this._layer._planet.quadTreeStrategy;this._secondPASS=[],this._entityCollectionsTreeWest.collectRenderCollectionsPASS1(t._visibleNodesWest,e);let i=this._secondPASS.length;for(;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesWest,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeEast.collectRenderCollectionsPASS1(t._visibleNodesEast,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesEast,e,this._secondPASS[i].nodeId)}}class Rc extends Is{constructor(e){super({name:"Mars",proj:_n,...e}),this._westExtent=U.createFromArray([-180,-90,0,90]),this._eastExtent=U.createFromArray([0,-90,180,90]),this._visibleNodesWest={},this._visibleNodesEast={}}init(e){this._quadTreeList=[new qt(ki,this,0,null,0,this._westExtent),new qt(ki,this,0,null,0,this._eastExtent)],super.init(e)}getTileXY(e,t){let i,s,r=t,n=1<<r;return i=e.lon>0?At(e.lon,180/n,0)+n:At(e.lon,180/n,-180),s=At(e.lat,180/n,90),[i,s,r,0]}getLonLatTileOffset(e,t,i,s,r){let n;n=e.lon>0?Si(t-(1<<s),i,s,this._eastExtent):Si(t,i,s,this._westExtent);let o=n.getWidth()/(r-1),a=n.getHeight()/(r-1);return[r-Math.ceil((e.lat-n.southWest.lat)/a)-1,Math.floor((e.lon-n.southWest.lon)/o)]}createEntityCollectionsTreeStrategy(e,t){return new Sc(this,e,t)}collectVisibleNode(e){e.segment.getExtent().southWest.lon<0?this._visibleNodesWest[e.nodeId]=e:this._visibleNodesEast[e.nodeId]=e}_clearVisibleNodes(){this._visibleNodesWest={},this._visibleNodesEast={}}}class Mc extends Is{constructor(e){super({name:"wgs84",proj:zs,...e})}init(e){this._quadTreeList=[new qt(ki,this,0,null,0,U.createFromArray([-180,-90,180,90]))],super.init(e)}}const Yc={epsg4326:class extends Is{constructor(e){super({name:"EPSG4326",proj:zs,...e})}init(e){this._quadTreeList=[new qt(ki,this,0,null,0,U.createFromArray([-180,-90,0,90])),new qt(ki,this,0,null,0,U.createFromArray([0,-90,180,90]))],super.init(e)}},earth:La,equi:Rc,wgs84:Mc};class Bc{static async load(e){const t=await fetch(e);if(!t.ok)throw new Error(`Unable to load '${e}'`);const i=await t.arrayBuffer(),s=new DataView(i);if(1179937895!==s.getUint32(0,!0))throw new Error("Not a valid GLB");s.getUint32(4,!0);const r=this.getChunks(s);return this.parseChunks(r)}static getChunks(e){const t=[];let i=12;do{const s=this.getChunk(e,i);i+=8+s.length,t.push(s)}while(i<e.byteLength);return t}static getChunk(e,t){const i=e.getUint32(t,!0);return{length:i,type:this.getChunkType(e.getUint32(t+4,!0)),chunkData:e.buffer.slice(t+8,t+8+i)}}static getChunkType(e){switch(e){case 1313821514:return 0;case 5130562:return 1;default:return 2}}static parseChunks(e){let t,i=[];for(const s of e)switch(s.type){case 0:t=this.parseJsonChunk(s);break;case 1:i.push(s.chunkData)}if(void 0===t)throw new Error("GLB json data extraction failed");return{gltf:t,bin:i}}static parseJsonChunk(e){return JSON.parse((new TextDecoder).decode(e.chunkData))}}var we=(e=>(e[e.byte=5120]="byte",e[e.ubyte=5121]="ubyte",e[e.short=5122]="short",e[e.ushort=5123]="ushort",e[e.uint=5125]="uint",e[e.float=5126]="float",e))(we||{}),fe=(e=>(e.scalar="SCALAR",e.vec2="VEC2",e.vec3="VEC3",e.vec4="VEC4",e.mat2="MAT2",e.mat3="MAT3",e.mat4="MAT4",e))(fe||{}),Ur=(e=>(e[e.points=0]="points",e[e.lines=1]="lines",e[e.lineLoop=2]="lineLoop",e[e.lineStrip=3]="lineStrip",e[e.triangles=4]="triangles",e[e.triangleStrip=5]="triangleStrip",e[e.triangleFan=6]="triangleFan",e))(Ur||{});const Zt=class e{constructor(t){var i;if(this.gltf=t,this._materials=[],this._images=[],this.meshes=[],(null==(i=t.gltf.extensionsRequired)?void 0:i.includes("KHR_draco_mesh_compression"))&&null===e._dracoDecoderModule)throw new Error("Unable to import GLTF. Draco decoder module is not connected");this._initImages(),this._initMaterials(),this._initMeshes()}static connectDracoDecoderModule(t){e._dracoDecoderModule=t}static async loadGlb(t){const i=await Bc.load(t);return new e(i)}getObjects3d(){const e=[];for(let t=0;t<this.meshes.length;t++)for(let i=0;i<this.meshes[t].primitives.length;i++)void 0!==this.meshes[t].primitives[i].object3d&&e.push(this.meshes[t].primitives[i].object3d);return e}toEntities(){const e=[];for(const t of this.gltf.gltf.scenes){if(void 0===t||void 0===t.nodes)return[];for(const i of t.nodes){const t=this.gltf.gltf.nodes[i];void 0===t.mesh&&void 0===t.children||e.push(this._nodeToEntity(t))}}return e}_nodeToEntity(e,t){const i=new G({name:e.name,cartesian:new v(0,0,0),relativePosition:void 0!==t});let s=null;if(void 0!==e.mesh&&(s=this.meshToEntity(this.meshes[e.mesh],t),i.appendChild(s)),void 0!==e.matrix){const t=new tt;t.set(e.matrix),i.setCartesian3v(t.getPosition()),i.setDirectQuaternionRotation(t.getQuat()),i.setScale3v(t.getScaling())}if(void 0!==e.translation&&void 0===e.matrix&&(i.relativePosition=!0,i.setCartesian(e.translation[0],e.translation[1],e.translation[2])),void 0!==e.rotation&&void 0===e.matrix&&i.setDirectQuaternionRotation(new F(e.rotation[0],e.rotation[1],e.rotation[2],e.rotation[3])),void 0!==e.scale&&void 0===e.matrix&&i.setScale3v(new v(e.scale[0],e.scale[1],e.scale[2])),void 0!==e.children)for(const t of e.children){const e=this._nodeToEntity(this.gltf.gltf.nodes[t],i);s?s.appendChild(e):i.appendChild(e)}return i}meshToEntity(e,t){const i=new G({name:e.name,cartesian:new v(0,0,0),relativePosition:!0,independentPicking:!0});return e.primitives.map((e=>{i.appendChild(new G({name:e.name,relativePosition:!0,geoObject:{object3d:e.object3d,tag:e.name}}))})),i}_initImages(){if(this.gltf.gltf.images)for(const e of this.gltf.gltf.images)this._images.push({src:e.uri,element:this._getImage(e.mimeType,e.bufferView),mimeType:e.mimeType,name:e.name})}_getImage(e,t){if(t&&e){const i=this.gltf.gltf.bufferViews[t],s=URL.createObjectURL(new Blob([this.gltf.bin[i.buffer].slice(i.byteOffset,i.byteOffset+i.byteLength)],{type:e})),r=new Image;return r.src=s,r}}_initMaterials(){if(this.gltf.gltf.materials)for(const e of this.gltf.gltf.materials){const t={name:e.name,emissiveFactor:e.emissiveFactor,alphaMode:e.alphaMode,alphaCutoff:e.alphaCutoff,doubleSided:e.doubleSided};if(e.pbrMetallicRoughness){if(e.pbrMetallicRoughness.baseColorFactor&&(t.baseColorFactor=e.pbrMetallicRoughness.baseColorFactor),e.pbrMetallicRoughness.baseColorTexture){const i=this.gltf.gltf.textures[e.pbrMetallicRoughness.baseColorTexture.index].source;void 0!==i&&(t.baseColorTexture={image:this._images[i],texCoord:e.pbrMetallicRoughness.baseColorTexture.texCoord})}if(e.pbrMetallicRoughness.metallicRoughnessTexture){const i=this.gltf.gltf.textures[e.pbrMetallicRoughness.metallicRoughnessTexture.index].source;void 0!==i&&(t.metallicRoughnessTexture={image:this._images[i],texCoord:e.pbrMetallicRoughness.metallicRoughnessTexture.texCoord})}}if(e.normalTexture){const i=this.gltf.gltf.textures[e.normalTexture.index].source;void 0!==i&&(t.normalTexture={image:this._images[i],texCoord:e.normalTexture.texCoord,scale:e.normalTexture.scale})}if(e.occlusionTexture){const i=this.gltf.gltf.textures[e.occlusionTexture.index].source;void 0!==i&&(t.occlusionTexture={image:this._images[i],texCoord:e.occlusionTexture.texCoord,strength:e.occlusionTexture.strength})}if(e.emissiveTexture){const i=this.gltf.gltf.textures[e.emissiveTexture.index].source;void 0!==i&&(t.emissiveTexture={image:this._images[i],texCoord:e.emissiveTexture.texCoord})}this._materials.push(t)}}_initMeshes(){this.meshes=[];for(let e=0;e<this.gltf.gltf.meshes.length;e++){const t=this.gltf.gltf.meshes[e],i={name:t.name,primitives:[]};for(let s=0;s<t.primitives.length;s++)i.primitives.push(this._buildPrimitive(t,t.primitives[s],`${e}-${s}`));this.meshes.push(i)}}_buildPrimitive(t,i,s){var r,n;let o=null;const a=this._materials[i.material||0],l=null!=(r=a.baseColorTexture)&&r.texCoord?`TEXCOORD_${a.baseColorTexture.texCoord}`:"TEXCOORD_0";if(null!=(n=i.extensions)&&n.KHR_draco_mesh_compression){const r=i.extensions.KHR_draco_mesh_compression,n=this.gltf.gltf.bufferViews[r.bufferView],l=n.byteOffset||0,h=e._dracoDecoderModule,c=new h.Decoder,d=new h.DecoderBuffer;if(d.Init(new Int8Array(this.gltf.bin[n.buffer].slice(l,l+n.byteLength)),n.byteLength),c.GetEncodedGeometryType(d)!==h.TRIANGULAR_MESH)throw new Error("Draco compressed data is not a mesh");const _=new h.Mesh;if(!c.DecodeBufferToMesh(d,_).ok()||0===_.ptr)throw new Error("Failed to decode Draco mesh");const u=_.num_faces(),f=new Uint32Array(3*u),g=new h.DracoInt32Array;for(let e=0;e<u;e++)c.GetFaceFromMesh(_,e,g),f[3*e]=g.GetValue(0),f[3*e+1]=g.GetValue(1),f[3*e+2]=g.GetValue(2);h.destroy(g);const p={};for(const e in r.attributes){const t=r.attributes[e],i=c.GetAttributeByUniqueId(_,t),s=_.num_points(),n=i.num_components(),o=new h.DracoFloat32Array;c.GetAttributeFloatForAllPoints(_,i,o);const a=new Float32Array(s*n);for(let e=0;e<a.length;e++)a[e]=o.GetValue(e);h.destroy(o),p[e]=a}h.destroy(_),h.destroy(d),h.destroy(c),o={name:`${t.name}/${a.name}/${s}`,vertices:p.POSITION,indices:f,mode:i.mode?i.mode:Ur.triangles,material:this._materials[i.material||0]||void 0,normals:p.NORMAL,texCoords:void 0}}else{const r=l?i.attributes[l]:void 0,n=r?this.gltf.gltf.accessors[r]:void 0;o={name:`${t.name}/${a.name}/${s}`,indices:i.indices?e._access(this.gltf.gltf.accessors[i.indices],this.gltf):void 0,mode:i.mode?i.mode:Ur.triangles,material:this._materials[i.material||0]||void 0,vertices:e._access(this.gltf.gltf.accessors[i.attributes.POSITION],this.gltf),normals:e._access(this.gltf.gltf.accessors[i.attributes.NORMAL],this.gltf),texCoords:n?e._access(n,this.gltf):void 0}}if(null===o)throw new Error("Unable to build primitive");return o.object3d=e._toObject3d(o),o}static _toObject3d(e){var t,i,s,r,n,o,a,l,h,c,d,_,u;return new $({name:e.name,vertices:Array.from(e.vertices),normals:Array.from(e.normals),texCoords:e.texCoords?Array.from(e.texCoords):void 0,indices:Array.from(e.indices),normalTextureImage:null==(i=null==(t=e.material)?void 0:t.normalTexture)?void 0:i.image.element,normalTextureSrc:null==(r=null==(s=e.material)?void 0:s.normalTexture)?void 0:r.image.src,colorTextureImage:null==(o=null==(n=e.material)?void 0:n.baseColorTexture)?void 0:o.image.element,colorTextureSrc:null==(l=null==(a=e.material)?void 0:a.baseColorTexture)?void 0:l.image.src,metallicRoughnessTextureImage:null==(c=null==(h=e.material)?void 0:h.occlusionTexture)?void 0:c.image.element,metallicRoughnessTextureSrc:null==(_=null==(d=e.material)?void 0:d.occlusionTexture)?void 0:_.image.src,color:null==(u=e.material)?void 0:u.baseColorFactor})}static _access(e,t){const i=t.gltf.bufferViews[e.bufferView],s=t.bin[i.buffer];let r=i.byteOffset||0;void 0!==e.byteOffset&&(r+=e.byteOffset);const n=s.slice(r,r+i.byteLength);switch(e.type){case fe.scalar:return this._getTensor(n,e,1,i.byteStride);case fe.vec2:return this._getTensor(n,e,2,i.byteStride);case fe.vec3:return this._getTensor(n,e,3,i.byteStride);case fe.vec4:case fe.mat2:return this._getTensor(n,e,4,i.byteStride);case fe.mat3:return this._getTensor(n,e,9,i.byteStride);case fe.mat4:return this._getTensor(n,e,16,i.byteStride);default:throw new Error("Unknown accessor type")}}static _getTensor(e,t,i,s){if(t.componentType===we.ushort)return new Uint16Array(e,0,t.count*i);if(t.componentType===we.short)return new Int16Array(e,0,t.count*i);if(t.componentType===we.uint)return new Uint32Array(e,0,t.count*i);if(t.componentType===we.float)return new Float32Array(e,0,t.count*i);if(t.componentType===we.ubyte)return new Uint8Array(e,0,t.count*i);if(t.componentType===we.byte)return new Int8Array(e,0,t.count*i);throw new Error("Unknown component type")}};Zt._dracoDecoderModule=null;let mo=Zt;const Wc="0.28.3";(globalThis.og??(globalThis.og={})).version="0.28.3";export{_i as ALIGN,je as BilTerrain,Qa as Billboard,gc as Bing,Pi as Camera,ss as CanvasTiles,Nr as Clock,Q as Control,La as EarthQuadTreeStrategy,Or as Easing,qr as Ellipsoid,Mi as EmptyTerrain,G as Entity,se as EntityCollection,Rc as EquiQuadTreeStrategy,bi as Events,U as Extent,Rt as Framebuffer,Ca as GeoImage,yr as GeoObject,cc as GeoTexture2d,dc as GeoVideo,Pa as Geoid,vr as Geometry,ai as GeometryTypeEnum,go as Globe,hc as GlobusRgbTerrain,gn as GlobusTerrain,mo as Gltf,Be as Handler,uc as KML,Go as LAYER_EVENTS,tl as LOCAL_FORWARD,el as Label,zt as Layer,Il as LightSource,qi as Line2,Jt as Line3,Sa as Loader,L as LonLat,Se as Mat3,tt as Mat4,Uo as Material,ch as MoveAxisEntity,Ta as Multisample,$ as Object3d,_c as OpenStreetMap,vt as Plane,Ri as Planet,wa as PlanetCamera,xr as PointCloud,br as Polyline,qc as Popup,X as Program,Is as QuadTreeStrategy,F as Quat,V as Ray,de as RenderNode,Ac as Renderer,St as RgbTerrain,Tr as Strip,H as Vec2,v as Vec3,et as Vec4,_t as Vector,me as WMS,Mc as Wgs84QuadTreeStrategy,Ds as XYZ,Fc as bv,Nc as control,lt as createEvents,W as input,Dc as jd,Uc as layer,Gc as mars,kc as math,Ic as mercator,jc as moon,Yc as quadTreeStrategyType,Hc as scene,Vc as terrain,zc as utils,Wc as version,Oc as webgl,So as wgs84};
|
|
1
|
+
const Xi=2*Math.PI,vo=Math.PI/2,or=Number.MAX_VALUE||17976931348623157e292,pn=Math.log(2),Ae=2147483647,xt=549755748352,Ct=-549755748352,j=Math.PI/180,J=180/Math.PI,Gr=2*J,Qt=.5*j,yo=Math.sqrt(.5),xo=1e-5,ne=1e-10,ar=1e-12,lr=1e-14;function Zi(e,t,i){return Math.max(t,Math.min(e,i))}function Ki(e){return!(e&e-1)}function $e(e,t=4096){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1>t?t:e+1}function Ni(e=0,t=1){return Math.floor(Math.random()*(t-e))+e}function bo(e,t){return(e%t+t)%t}function Ue(e){const t=bo(e,Xi);return Math.abs(t)<lr&&Math.abs(e)>lr?Xi:t}function si(e){const t=Math.abs(e);return t-Math.floor(t)}function wo(e,t,i){return i+e*(t-i)}function Hs(e){return e*e*e}function Vs(e){return e*e}function hr(e){return e-360*Math.floor(e/360)}const kc=Object.freeze(Object.defineProperty({__proto__:null,ARCSECONDS_TO_RADIANS:484813681109536e-20,DEG2RAD:function(e){return e*j},DEGREES:J,DEGREES_DOUBLE:Gr,DEGREES_TO_HOURS:1/15,EPS1:.1,EPS10:ne,EPS11:1e-11,EPS12:ar,EPS13:1e-13,EPS14:lr,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:xo,EPS6:1e-6,EPS7:1e-7,EPS8:1e-8,EPS9:1e-9,HOURS_TO_DEGREES:15,HOURS_TO_RADIANS:.26179938779914946,LOG2:pn,MAX:xt,MAX32:Ae,MAX_FLOAT:or,MIN:Ct,PI_TWO:vo,RAD2DEG:function(e){return e*J},RADIANS:j,RADIANS_HALF:Qt,RADIANS_TO_HOURS:3.819718634205488,SQRT_HALF:yo,TWO_PI:Xi,W:3,X:0,Y:1,Z:2,bezier1v:function(e,t,i,s,r){return Hs(1-e)*t+3*Vs(1-e)*e*i+3*(1-e)*Vs(e)*s+Hs(e)*r},bezier3v:function(e,t,i,s,r){let n=1-e,o=e*e,a=n*n,l=a*n,h=o*e;return t.scaleTo(l).addA(i.scaleTo(3*a*e)).addA(s.scaleTo(3*n*o)).addA(r.scaleTo(h))},clamp:Zi,cube:Hs,degToDec:function(e,t,i,s){return s?e+t/60+i/3600:-e-t/60-i/3600},exp2:function(e){return Math.pow(2,e)},frac:si,getAngleBetweenAzimuths:function(e,t){return(((e=Ue(e))-(t=Ue(t)))%360+360+180)%360-180},isPowerOfTwo:Ki,lerp:wo,log:function(e,t){return Math.log(e)/Math.log(t)},log2:function(e){return Math.log(e)/pn},mod:bo,negativePItoPI:function(e){return Ue(e+Math.PI)-Math.PI},nextHighestPowerOfTwo:$e,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:Ni,rev:hr,slice:function(e,t,i){return e*(t-i)},solve_iteration:function(e,t,i,s=50){let r=0,n=t;for(let t=0;t<s;t++)if(r=n,n=e(r),Math.abs(n-r)<i)return n;return n},solve_iteration_fixed:function(e,t,i){let s=0,r=t;for(let t=0;t<i;t++)s=r,r=e(s);return r},square:Vs,step:function(e,t){return t<e?0:1},zeroTwoPI:Ue},Symbol.toStringTag,{value:"Module"})),Ba=.5*Math.PI,To=180/Math.PI,ka=2*To,Us=Math.PI/360,Ia=To*Ba;class L{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 s=e[i];t[i]=new L(s[0],s[1],s[2])}return t}static createFromArray(e){return new L(e[0],e[1],e[2])}static toArray(e){return[e.lon,e.lat,e.height]}toArray(){return L.toArray(this)}static forwardMercator(e,t,i){return new L(e*Hi,Math.log(Math.tan((90+t)*Us))*We,i)}static forwardMercatorRes(e,t){return t.lon=e.lon*Hi,t.lat=Math.log(Math.tan((90+e.lat)*Us))*We,t.height=e.height,t}static inverseMercator(e,t,i=0){return new L(e*Co,ka*Math.atan(Math.exp(t*jr))-Ia,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 L(this.lon,this.lat,this.height)}forwardMercator(){return L.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 L(this.lon*Hi,Math.log(Math.tan((90+e)*Us))*We)}inverseMercator(){return L.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 Lt=20037508.34,Qi=2*Lt,jr=Math.PI/Lt,We=Lt/Math.PI,za=.5*Math.PI,Hi=Lt/180,Co=180/Lt,Eo=Math.PI/360,mn=Math.PI/180,Da=180/Math.PI,Ao=2*Lt,ri=1/Ao;function Ji(e){return new L(e.lon*Lt/180,Math.log(Math.tan((90+e.lat)*Eo))*We,e.height)}function ni(e){return e*Lt/180}function oi(e){return Math.log(Math.tan((90+e)*Eo))*We}function Lo(e){return Da*(2*Math.atan(Math.exp(e*jr))-za)}function Ze(e,t,i){let s=Qi/(1<<i),r=new L(e*s-20037508.34,Lt-t*s-s);return new U(r,new L(r.lon+s,r.lat+s))}const ct=Lo(Lt),Ot=-ct,Ic=Object.freeze(Object.defineProperty({__proto__:null,INV_POLE_BY_180:Co,MAX_LAT:ct,MIN_LAT:Ot,ONE_BY_POLE_DOUBLE:ri,PI_BY_POLE:jr,POLE:Lt,POLE2:Qi,POLE_BY_180:Hi,POLE_BY_PI:We,POLE_DOUBLE:Ao,forward:Ji,forwardArray:function(e){let t=[];for(let i=0;i<e.length;i++)t.push(e[i].forwardMercator());return t},forward_lat:oi,forward_lon:ni,getTileExtent:Ze,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*mn)+1/Math.cos(e*mn))/Math.PI)*Math.pow(2,t))},inverse_lat:Lo,inverse_lon:function(e){return 180*e/Lt}},Symbol.toStringTag,{value:"Module"}));class U{constructor(e=new L,t=new L){this.southWest=e,this.northEast=t}static createFromArray(e){return new U(new L(e[0],e[1]),new L(e[2],e[3]))}static createByCoordinates(e){let t=xt,i=Ct,s=xt,r=Ct;for(let n=0;n<e.length;n++){const o=e[n];o.lon<t&&(t=o.lon),o.lon>i&&(i=o.lon),o.lat<s&&(s=o.lat),o.lat>r&&(r=o.lat)}return new U(new L(t,s),new L(i,r))}static createByCoordinatesArr(e){let t=xt,i=Ct,s=xt,r=Ct;for(let n=0;n<e.length;n++){const o=e[n];o[0]<t&&(t=o[0]),o[0]>i&&(i=o[0]),o[1]<s&&(s=o[1]),o[1]>r&&(r=o[1])}return new U(new L(t,s),new L(i,r))}static fromTile(e,t,i,s=40075016.68,r=40075016.68){const n=1<<i,o=s/n,a=r/n,l=.5*-s+e*o,h=.5*r-t*a,c=l+o;return new U(new L(l,h-a),new L(c,h))}setByCoordinates(e){let t=xt,i=Ct,s=xt,r=Ct;for(let n=0;n<e.length;n++){const o=e[n];o.lon<t&&(t=o.lon),o.lon>i&&(i=o.lon),o.lat<s&&(s=o.lat),o.lat>r&&(r=o.lat)}return this.southWest.lon=t,this.southWest.lat=s,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 U(this.southWest.clone(),this.northEast.clone())}getCenter(){const e=this.southWest,t=this.northEast;return new L(e.lon+.5*(t.lon-e.lon),e.lat+.5*(t.lat-e.lat))}getNorthWest(){return new L(this.southWest.lon,this.northEast.lat)}getNorthEast(){return new L(this.northEast.lon,this.northEast.lat)}getSouthWest(){return new L(this.southWest.lon,this.southWest.lat)}getSouthEast(){return new L(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 U(this.southWest.forwardMercator(),this.northEast.forwardMercator())}inverseMercator(){return new U(this.southWest.inverseMercator(),this.northEast.inverseMercator())}getCartesianBounds(e){let t=xt,i=Ct,s=xt,r=Ct,n=xt,o=Ct;const a=[new L(this.southWest.lon,this.southWest.lat),new L(this.southWest.lon,this.northEast.lat),new L(this.northEast.lon,this.northEast.lat),new L(this.northEast.lon,this.southWest.lat)];for(let l=0;l<a.length;l++){const h=e.lonLatToCartesian(a[l]),c=h.x,d=h.y,_=h.z;c<t&&(t=c),c>i&&(i=c),d<s&&(s=d),d>r&&(r=d),_<n&&(n=_),_>o&&(o=_)}return[t,s,n,i,r,o]}toString(){return`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`}}class Se{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 Se;return e.set(this._m),e}copy(e){return this.set(e._m)}transposeTo(){let e=new Se,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,s=e.z,r=this._m;return new v(r[0]*t+r[3]*i+r[6]*s,r[1]*t+r[4]*i+r[7]*s,r[2]*t+r[5]*i+r[8]*s)}getMat4(){let e=new tt,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 et{constructor(e=0,t=0,i=0,s=0){this.x=e,this.y=t,this.z=i,this.w=s}static get identity(){return new et(0,0,0,1)}static fromVec(e){return new et(e[0],e[1],e[2],e[3])}toVec3(){return new v(this.x,this.y,this.z)}clone(){return new et(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,s){return this.x=e,this.y=t,this.z=i,this.w=s,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 et(this.x*e,this.y*e,this.z*e,this.w*e)}getStep(e){return new et(this.x<e?0:1,this.y<e?0:1,this.z<e?0:1,this.w<e?0:1)}getFrac(e){return new et(si(e.x),si(e.y),si(e.z),si(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 tt{constructor(){this._m=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}static identity(){let e=new tt;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}static getRotationAroundPoint(e,t=v.ZERO,i=v.UP){let s=tt.getRotation(e,i),r=(new tt).setIdentity().translate(t),n=(new tt).setIdentity().translate(t.negateTo());return r.mul(s).mul(n)}static getRotation(e,t=v.UP){return(new tt).setRotation(t,e)}getPosition(){return new v(this._m[12],this._m[13],this._m[14])}getScaling(){let e=this._m[0],t=this._m[1],i=this._m[2],s=this._m[4],r=this._m[5],n=this._m[6],o=this._m[8],a=this._m[9],l=this._m[10];return new v(Math.sqrt(e*e+t*t+i*i),Math.sqrt(s*s+r*r+n*n),Math.sqrt(o*o+a*a+l*l))}getQuat(){let e=this.getScaling();const t=[0,0,0,1];let i=1/e.x,s=1/e.y,r=1/e.z,n=this._m[0]*i,o=this._m[1]*s,a=this._m[2]*r,l=this._m[4]*i,h=this._m[5]*s,c=this._m[6]*r,d=this._m[8]*i,_=this._m[9]*s,u=this._m[10]*r,f=n+h+u,g=0;return f>0?(g=2*Math.sqrt(f+1),t[3]=.25*g,t[0]=(c-_)/g,t[1]=(d-a)/g,t[2]=(o-l)/g):n>h&&n>u?(g=2*Math.sqrt(1+n-h-u),t[3]=(c-_)/g,t[0]=.25*g,t[1]=(o+l)/g,t[2]=(d+a)/g):h>u?(g=2*Math.sqrt(1+h-n-u),t[3]=(d-a)/g,t[0]=(o+l)/g,t[1]=.25*g,t[2]=(c+_)/g):(g=2*Math.sqrt(1+u-n-h),t[3]=(o-l)/g,t[0]=(d+a)/g,t[1]=(c+_)/g,t[2]=.25*g),new F(...t)}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 tt;return e.set(this._m),e}copy(e){return this.set(e._m)}getMat3(){let e=new Se,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,s=e.z;return new v(this._m[0]*t+this._m[4]*i+this._m[8]*s+this._m[12],this._m[1]*t+this._m[5]*i+this._m[9]*s+this._m[13],this._m[2]*t+this._m[6]*i+this._m[10]*s+this._m[14])}mulVec4(e){let t=e.x,i=e.y,s=e.z,r=e.w;return new et(this._m[0]*t+this._m[4]*i+this._m[8]*s+this._m[12]*r,this._m[1]*t+this._m[5]*i+this._m[9]*s+this._m[13]*r,this._m[2]*t+this._m[6]*i+this._m[10]*s+this._m[14]*r,this._m[3]*t+this._m[7]*i+this._m[11]*s+this._m[15]*r)}toInverseMatrix3(){let e=this._m,t=e[0],i=e[1],s=e[2],r=e[4],n=e[5],o=e[6],a=e[8],l=e[9],h=e[10],c=h*n-o*l,d=-h*r+o*a,_=l*r-n*a,u=t*c+i*d+s*_;if(!u)return;u=1/u;let f=new Se;return f._m[0]=c*u,f._m[1]=(-h*i+s*l)*u,f._m[2]=(o*i-s*n)*u,f._m[3]=d*u,f._m[4]=(h*t-s*a)*u,f._m[5]=(-o*t+s*r)*u,f._m[6]=_*u,f._m[7]=(-l*t+i*a)*u,f._m[8]=(n*t-i*r)*u,f}inverseTo(e=new tt){let t=this._m[0],i=this._m[1],s=this._m[2],r=this._m[3],n=this._m[4],o=this._m[5],a=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*o-i*n,v=t*a-s*n,y=t*l-r*n,x=i*a-s*o,b=i*l-r*o,w=s*l-r*a,T=h*f-c*u,C=h*g-d*u,E=h*p-_*u,A=c*g-d*f,L=c*p-_*f,P=d*p-_*g,S=1/(m*P-v*L+y*A+x*E-b*C+w*T);return e._m[0]=(o*P-a*L+l*A)*S,e._m[1]=(-i*P+s*L-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]=(-n*P+a*E-l*C)*S,e._m[5]=(t*P-s*E+r*C)*S,e._m[6]=(-u*w+g*y-p*v)*S,e._m[7]=(h*w-d*y+_*v)*S,e._m[8]=(n*L-o*E+l*T)*S,e._m[9]=(-t*L+i*E-r*T)*S,e._m[10]=(u*b-f*y+p*m)*S,e._m[11]=(-h*b+c*y-_*m)*S,e._m[12]=(-n*A+o*C-a*T)*S,e._m[13]=(t*A-i*C+s*T)*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 tt;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],s=this._m[2],r=this._m[3],n=this._m[4],o=this._m[5],a=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],E=e._m[8],A=e._m[9],L=e._m[10],P=e._m[11],S=e._m[12],R=e._m[13],M=e._m[14],B=e._m[15],k=new tt;return k._m[0]=m*t+v*n+y*h+x*u,k._m[1]=m*i+v*o+y*c+x*f,k._m[2]=m*s+v*a+y*d+x*g,k._m[3]=m*r+v*l+y*_+x*p,k._m[4]=b*t+w*n+T*h+C*u,k._m[5]=b*i+w*o+T*c+C*f,k._m[6]=b*s+w*a+T*d+C*g,k._m[7]=b*r+w*l+T*_+C*p,k._m[8]=E*t+A*n+L*h+P*u,k._m[9]=E*i+A*o+L*c+P*f,k._m[10]=E*s+A*a+L*d+P*g,k._m[11]=E*r+A*l+L*_+P*p,k._m[12]=S*t+R*n+M*h+B*u,k._m[13]=S*i+R*o+M*c+B*f,k._m[14]=S*s+R*a+M*d+B*g,k._m[15]=S*r+R*l+M*_+B*p,k}translate(e){let t=e.x,i=e.y,s=e.z,r=this._m;return r[12]=r[0]*t+r[4]*i+r[8]*s+r[12],r[13]=r[1]*t+r[5]*i+r[9]*s+r[13],r[14]=r[2]*t+r[6]*i+r[10]*s+r[14],r[15]=r[3]*t+r[7]*i+r[11]*s+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),s=Math.sin(t),r=new tt,n=r._m;return n[0]=i+(1-i)*e.x*e.x,n[1]=(1-i)*e.y*e.x-s*e.z,n[2]=(1-i)*e.z*e.x+s*e.y,n[3]=0,n[4]=(1-i)*e.x*e.y+s*e.z,n[5]=i+(1-i)*e.y*e.y,n[6]=(1-i)*e.z*e.y-s*e.x,n[7]=0,n[8]=(1-i)*e.x*e.z-s*e.y,n[9]=(1-i)*e.y*e.z+s*e.x,n[10]=i+(1-i)*e.z*e.z,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this.mul(r)}setRotation(e,t){let i=Math.cos(t),s=Math.sin(t),r=this._m;return r[0]=i+(1-i)*e.x*e.x,r[1]=(1-i)*e.y*e.x-s*e.z,r[2]=(1-i)*e.z*e.x+s*e.y,r[3]=0,r[4]=(1-i)*e.x*e.y+s*e.z,r[5]=i+(1-i)*e.y*e.y,r[6]=(1-i)*e.z*e.y-s*e.x,r[7]=0,r[8]=(1-i)*e.x*e.z-s*e.y,r[9]=(1-i)*e.y*e.z+s*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 F.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,s,r,n){let o=t-e,a=s-i,l=r-n,h=2*r,c=this._m;return c[0]=h/o,c[1]=0,c[2]=0,c[3]=0,c[4]=0,c[5]=h/a,c[6]=0,c[7]=0,c[8]=(t+e)/o,c[9]=(s+i)/a,c[10]=(n+r)/l,c[11]=-1,c[12]=0,c[13]=0,c[14]=h*n/l,c[15]=0,this}setOrthographic(e,t,i,s,r,n){let o=1/(e-t),a=1/(i-s),l=1/(r-n),h=this._m;return h[0]=-2*o,h[1]=0,h[2]=0,h[3]=0,h[4]=0,h[5]=-2*a,h[6]=0,h[7]=0,h[8]=0,h[9]=0,h[10]=2*l,h[11]=0,h[12]=(e+t)*o,h[13]=(s+i)*a,h[14]=(n+r)*l,h[15]=1,this}eulerToMatrix(e,t,i){let s=Math.cos(e),r=Math.sin(e),n=Math.cos(t),o=Math.sin(t),a=Math.cos(i),l=Math.sin(i),h=s*o,c=r*o,d=this._m;return d[0]=n*a,d[1]=-n*l,d[2]=-o,d[4]=-c*a+s*l,d[5]=c*l+s*a,d[6]=-r*n,d[8]=h*a+r*l,d[9]=-h*l+r*a,d[10]=s*n,d[3]=d[7]=d[11]=d[12]=d[13]=d[14]=0,d[15]=1,this}}class F{constructor(e=0,t=0,i=0,s=0){this.x=e,this.y=t,this.z=i,this.w=s}static get IDENTITY(){return new F(0,0,0,1)}static xRotation(e){return e*=.5,new F(Math.sin(e),0,0,Math.cos(e))}static yRotation(e){return e*=.5,new F(0,Math.sin(e),0,Math.cos(e))}static zRotation(e){return e*=.5,new F(0,0,Math.sin(e),Math.cos(e))}static axisAngleToQuat(e,t=0){let i=e.getNormal(),s=.5*t,r=Math.sin(s);return new F(i.x*r,i.y*r,i.z*r,Math.cos(s))}static getLookRotation(e,t){let i=e.getNormal().negate(),s=t.cross(i).normalize(),r=i.cross(s),n=1+s.x+r.y+i.z;if(n>1e-6){let e=1/(2*Math.sqrt(n));return new F((i.y-r.z)*e,(s.z-i.x)*e,(r.x-s.y)*e,.25/e)}if(s.x>r.y&&s.x>i.z){let e=1/(2*Math.sqrt(1+s.x-r.y-i.z));return new F(.25/e,(r.x+s.y)*e,(s.z+i.x)*e,(i.y-r.z)*e)}if(r.y>i.z){let e=1/(2*Math.sqrt(1+r.y-s.x-i.z));return new F((r.x+s.y)*e,.25/e,(i.y+r.z)*e,(s.z-i.x)*e)}let o=1/(2*Math.sqrt(1+i.z-s.x-r.y));return new F((s.z+i.x)*o,(i.y+r.z)*o,.25/o,(r.x-s.y)*o)}static getLookAtSourceDest(e,t){let i=t.subA(e).normalize(),s=v.FORWARD.dot(i);if(Math.abs(s- -1)<1e-6)return F.axisAngleToQuat(v.UP,Math.PI);if(Math.abs(s-1)<1e-6)return new F(0,0,0,1);let r=Math.acos(s),n=v.FORWARD.cross(i).normalize();return F.axisAngleToQuat(n,r)}static getRotationBetweenVectors(e,t){let i=e.cross(t);return new F(i.x,i.y,i.z,1+e.dot(t)).normalize()}static getRotationBetweenVectorsRes(e,t,i){let s=e.cross(t);return i.set(s.x,s.y,s.z,1+e.dot(t)),i.normalize()}static getRotationBetweenVectorsUp(e,t,i){let s=e.dot(t);if(Math.abs(s+1)<1e-6)return F.axisAngleToQuat(i,Math.PI);if(Math.abs(s-1)<1e-6)return new F(0,0,0,1);let r=Math.acos(s),n=e.cross(t).normalize();return F.axisAngleToQuat(n,r)}isZero(){return 0===this.x&&0===this.y&&0===this.z&&0===this.w}isNaN(){return isNaN(this.x)||isNaN(this.y)||isNaN(this.z)||isNaN(this.w)}clear(){return this.x=this.y=this.z=this.w=0,this}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,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 F(this.x,this.y,this.z,this.w)}add(e){return new F(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}addRes(e,t){return t.set(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}sub(e){return new F(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)}scaleTo(e){return new F(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]}get xyz(){return new v(this.x,this.y,this.z)}setLookRotation(e,t){let i=e.getNormal().negate(),s=t.cross(i).normalize(),r=i.cross(s),n=1+s.x+r.y+i.z;if(n>1e-6){let e=1/(2*Math.sqrt(n));this.x=(i.y-r.z)*e,this.y=(s.z-i.x)*e,this.z=(r.x-s.y)*e,this.w=.25/e}else if(s.x>r.y&&s.x>i.z){let e=1/(2*Math.sqrt(1+s.x-r.y-i.z));this.x=.25/e,this.y=(r.x+s.y)*e,this.z=(s.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-s.x-i.z));this.x=(r.x+s.y)*e,this.y=.25/e,this.z=(i.y+r.z)*e,this.w=(s.z-i.x)*e}else{let e=1/(2*Math.sqrt(1+i.z-s.x-r.y));this.x=(s.z+i.x)*e,this.y=(i.y+r.z)*e,this.z=.25/e,this.w=(r.x-s.y)*e}return this}setFromSphericalCoords(e,t,i){let s=Math.sin(i/2),r=Math.cos(i/2),n=Math.sin(e),o=Math.cos(e),a=Math.sin(t),l=Math.cos(t);return this.x=s*o*a,this.y=s*n,this.z=s*n*l,this.w=r,this}getSphericalCoords(){let e=this.w,t=Math.sqrt(1-e*e);Math.abs(t)<5e-4&&(t=1);let i,s=this.x/t,r=this.y/t,n=this.z/t,o=-Math.asin(r);return i=s*s+n*n<5e-4?0:Math.atan2(s,n),i<0&&(i+=360),{lat:o,lon:i,alpha:Math.acos(e)}}setFromAxisAngle(e,t){let i=e.getNormal(),s=.5*t,r=Math.sin(s);return this.set(i.x*r,i.y*r,i.z*r,Math.cos(s)),this}getAxisAngle(){let e,t,i=this.x,s=this.y,r=this.z,n=this.w,o=Math.sqrt(i*i+s*s+r*r);if(o>1e-7){let a=1/o;e=new v(i*a,s*a,r*a),t=n<0?2*Math.atan2(-o,-n):2*Math.atan2(o,n)}else e=new v(0,0,0),t=0;return{axis:e,angle:t}}getPitch(){let e=-2*(this.y*this.z-this.w*this.x);return Math.abs(e)>=1?Math.sign(e)*vo:Math.asin(e)}getYaw(){return-Math.atan2(2*(this.x*this.z+this.w*this.y),1-2*(this.y*this.y+this.x*this.x))}getRoll(){return Math.atan2(2*(this.x*this.y+this.w*this.z),1-2*(this.z*this.z+this.x*this.x))}setPitchYawRoll(e,t,i,s=F.IDENTITY){let r=F.xRotation(-e),n=F.yRotation(t),o=F.zRotation(-i);return this.copy(o.mul(r).mul(n).mul(s).conjugate())}setFromEulerAngles(e,t,i){let s=e*Qt,r=t*Qt,n=i*Qt,o=Math.cos(s),a=Math.cos(r),l=Math.cos(n),h=Math.sin(s),c=Math.sin(r),d=Math.sin(n),_=a*l,u=c*d;return this.w=o*_+h*u,this.x=h*_-o*u,this.y=o*c*l+h*a*d,this.z=o*a*d-h*c*l,this.normalize()}getEulerAngles(){let e=this.x,t=this.y,i=this.z,s=this.w,r=t*t,n=s*t-i*e;return n<-1?n=-1:n>1&&(n=1),{roll:Math.atan2(2*(s*e+t*i),1-2*(e*e+r)),pitch:Math.asin(2*n),yaw:Math.atan2(2*(s*i+e*t),1-2*(r+i*i))}}setFromMatrix4(e){let t,i,s,r,n,o=[],a=e._m,l=[1,2,0];return t=a[0]+a[5]+a[10],t>0?(i=Math.sqrt(t+1),this.w=i/2,i=.5/i,this.x=(a[6]-a[9])*i,this.y=(a[8]-a[2])*i,this.z=(a[1]-a[4])*i):(s=0,a[5]>a[0]&&(s=1),a[10]>a[5*s]&&(s=2),r=l[s],n=l[r],i=Math.sqrt(a[5*s]-(a[5*r]+a[5*n])+1),o[s]=.5*i,0!==i&&(i=.5/i),o[3]=(a[4*r+n]-a[4*n+r])*i,o[r]=(a[4*s+r]+a[4*r+s])*i,o[n]=(a[4*s+n]+a[4*n+s])*i,this.x=o[0],this.y=o[1],this.z=o[2],this.w=o[3]),this}getMat4(e=new tt){let t=this.x+this.x,i=this.y+this.y,s=this.z+this.z,r=this.w*t,n=this.w*i,o=this.w*s,a=this.x*t,l=this.x*i,h=this.x*s,c=this.y*i,d=this.y*s,_=this.z*s;return e.set([1-(c+_),l-o,h+n,0,l+o,1-(a+_),d-r,0,h-n,d+r,1-(a+c),0,0,0,0,1])}getMat3(){let e=new Se,t=e._m,i=this.x,s=this.y,r=this.z,n=this.w,o=i+i,a=s+s,l=r+r,h=i*o,c=i*a;i*=l;let d=s*a;return s*=l,r*=l,o*=n,a*=n,n*=l,t[0]=1-(d+r),t[1]=c-n,t[2]=i+a,t[3]=c+n,t[4]=1-(h+r),t[5]=s-o,t[6]=i-a,t[7]=s+o,t[8]=1-(h+d),e}mulVec3(e){let t=e.x,i=e.y,s=e.z,r=this.x,n=this.y,o=this.z,a=this.w,l=a*t+n*s-o*i,h=a*i+o*t-r*s,c=a*s+r*i-n*t;return t=-r*t-n*i-o*s,new v(l*a+t*-r+h*-o-c*-n,h*a+t*-n+c*-r-l*-o,c*a+t*-o+l*-n-h*-r)}mulVec3Res(e,t){let i=e.x,s=e.y,r=e.z,n=this.x,o=this.y,a=this.z,l=this.w,h=l*i+o*r-a*s,c=l*s+a*i-n*r,d=l*r+n*s-o*i;return i=-n*i-o*s-a*r,t.set(h*l+i*-n+c*-a-d*-o,c*l+i*-o+d*-n-h*-a,d*l+i*-a+h*-o-c*-n)}mul(e){let t=this.x,i=this.y,s=this.z,r=this.w,n=e.x,o=e.y,a=e.z,l=e.w;return new F(t*l+r*n+i*a-s*o,i*l+r*o+s*n-t*a,s*l+r*a+t*o-i*n,r*l-t*n-i*o-s*a)}mulRes(e,t){let i=this.x,s=this.y,r=this.z,n=this.w,o=e.x,a=e.y,l=e.z,h=e.w;return t.set(i*h+n*o+s*l-r*a,s*h+n*a+r*o-i*l,r*h+n*l+i*a-s*o,n*h-i*o-s*a-r*l)}mulA(e){let t=this.x,i=this.y,s=this.z,r=this.w,n=e.x,o=e.y,a=e.z,l=e.w;return this.x=t*l+r*n+i*a-s*o,this.y=i*l+r*o+s*n-t*a,this.z=s*l+r*a+t*o-i*n,this.w=r*l-t*n-i*o-s*a,this}conjugate(){return new F(-this.x,-this.y,-this.z,this.w)}inverse(){let e=1/this.magnitude2();return new F(-this.x*e,-this.y*e,-this.z*e,this.w*e)}magnitude(){let e=this.x,t=this.y,i=this.z,s=this.w;return Math.sqrt(e*e+t*t+i*i+s*s)}magnitude2(){let e=this.x,t=this.y,i=this.z,s=this.w;return e*e+t*t+i*i+s*s}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,s=this.w,r=Math.sqrt(e*e+t*t+i*i+s*s);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=s*r,this)}isEqual(e){let t=this.dot(e);return Math.abs(t-1)<.001}slerp(e,t){let i,s,r,n,o,a=this.x,l=this.y,h=this.z,c=this.w,d=e.x,_=e.y,u=e.z,f=e.w;return s=a*d+l*_+h*u+c*f,s<0&&(s=-s,d=-d,_=-_,u=-u,f=-f),1-s>1e-6?(i=Math.acos(s),r=Math.sin(i),n=Math.sin((1-t)*i)/r,o=Math.sin(t*i)/r):(n=1-t,o=t),new F(n*a+o*d,n*l+o*_,n*h+o*u,n*c+o*f)}}class v{constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}static get UP(){return new v(0,1,0)}static get DOWN(){return new v(0,-1,0)}static get RIGHT(){return new v(1,0,0)}static get LEFT(){return new v(-1,0,0)}static get FORWARD(){return new v(0,0,-1)}static get BACKWARD(){return new v(0,0,1)}static get ZERO(){return new v}static get UNIT_X(){return new v(1,0,0)}static get UNIT_Y(){return new v(0,1,0)}static get UNIT_Z(){return new v(0,0,1)}static get NORTH(){return v.UNIT_Z}static doubleToTwoFloats(e,t,i){let s=e.x,r=e.y,n=e.z;if(s>=0){let e=65536*Math.floor(s/65536);t.x=Math.fround(e),i.x=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.x=Math.fround(-e),i.x=Math.fround(s+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(n>=0){let e=65536*Math.floor(n/65536);t.z=Math.fround(e),i.z=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.z=Math.fround(-e),i.z=Math.fround(n+e)}}static doubleToTwoFloat32Array(e,t,i){let s=e.x,r=e.y,n=e.z;if(s>=0){let e=65536*Math.floor(s/65536);t[0]=Math.fround(e),i[0]=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t[0]=Math.fround(-e),i[0]=Math.fround(s+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(n>=0){let e=65536*Math.floor(n/65536);t[2]=Math.fround(e),i[2]=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t[2]=Math.fround(-e),i[2]=Math.fround(n+e)}}static fromVec(e){return new v(e[0],e[1],e[2])}static angle(e,t){let i=e.dot(t),s=e.cross(t).length();return Math.atan2(s,i)}static lerp(e,t,i){return new v(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 v(e.x,e.y,e.z);return i.addA(t),i}static sub(e,t){let i=new v(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 v(e.x,e.y,e.z);return i.mulA(t),i}static noncollinear(e,t){return!!(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 s=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&s.isZero()?new v(i.x,i.y,i.z):s}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 isOrthogonal(e,t,i=1e-6){const s=e.x*t.x+e.y*t.y+e.z*t.z;return Math.abs(s)<i}isOrthogonal(e,t=1e-6){const i=this.x*e.x+this.y*e.y+this.z*e.z;return Math.abs(i)<t}static div(e,t){let i=new v(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 et(this.x,this.y,this.z,1)}clone(){return new v(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 F(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 v(this.x+e.x,this.y+e.y,this.z+e.z)}addRes(e,t){return t.set(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 v(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 v(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 v(this.x*e.x,this.y*e.y,this.z*e.z)}mulRes(e,t){return t.set(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 v(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 v(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 v;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normal(){let e=new v;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegate(){let e=new v;e.copy(this);let t=-1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegateScale(e){let t=new v;t.copy(this);let i=-e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalScale(e){let t=new v;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,s=this.z-e.z;return Math.sqrt(t*t+i*i+s*s)}distance2(e){let t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return t*t+i*i+s*s}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 v(-this.x,-this.y,-this.z)}projToRay(e,t){let i=v.proj_b_to_a(v.sub(this,e),t);return i.addA(e),i}angle(e){return v.angle(this,e)}lerp(e,t){return new v(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 v(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,s,r,n,o=new v;if(t<=0)return o.copy(this),o;if(t>=1)return o.copy(e),o;let a=this.dot(e);return 1-a>v.LERP_DELTA?(i=Math.acos(a),s=Math.sin(i),r=Math.sin((1-t)*i)/s,n=Math.sin(t*i)/s):(r=1-t,n=t),v.add(this.scaleTo(r),e.scale(n))}mulVecA(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}getRotationTo(e,t){let i=this.clone(),s=e.clone();i.normalize(),s.normalize();let r=i.dot(s);if(r>=1)return F.IDENTITY.clone();if(r<-.999999){if(t.equal(v.ZERO)){let e=v.UNIT_X.cross(i);return e.isZero()&&(e=v.UNIT_Y.cross(i)),e.normalize(),F.axisAngleToQuat(e,Math.PI)}return F.axisAngleToQuat(t,Math.PI)}{let e=Math.sqrt(2*(1+r)),t=1/e,n=i.cross(s),o=new F(n.x*t,n.y*t,n.z*t,.5*e);return o.normalize(),o}}}class H{constructor(e=0,t=0){this.x=e,this.y=t}static get UP(){return new H(0,1)}static get DOWN(){return new H(0,-1)}static get RIGHT(){return new H(1,0)}static get LEFT(){return new H(-1,0)}static get ZERO(){return new H}static add(e,t){const i=new H(e.x,e.y);return i.addA(t),i}static sub(e,t){var i=new H(e.x,e.y);return i.subA(t),i}static scale(e,t){let i=new H(e.x,e.y);return i.scale(t),i}static mul(e,t){let i=new H(e.x,e.y);return i.mulA(t),i}static div(e,t){let i=new H(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()}static proj_b_to_plane(e,t,i){let s=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&s.isZero()?new H(i.x,i.y):s}toVector3(){return new v(this.x,this.y,0)}clone(){return new H(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 H(this.x+e.x,this.y+e.y)}subA(e){return this.x-=e.x,this.y-=e.y,this}sub(e){return new H(this.x-e.x,this.y-e.y)}scale(e){return this.x*=e,this.y*=e,this}scaleTo(e){return new H(this.x*e,this.y*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this}mul(e){return new H(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(){return this.getNormal()}getNormal(){let e=new H;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 H.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 H(-this.x,-this.y)}projToRay(e,t){let i=H.proj_b_to_a(H.sub(this,e),t);return i.add(e),i}angle(e){return H.angle(this,e)}lerp(e,t,i){let s=this.clone();return i<=0?s.copy(e):i>=1?s.copy(t):s=H.add(e,H.sub(t,e).scale(i)),s}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,s,r,n,o=new H;if(t<=0)return o.copy(this),o;if(t>=1)return o.copy(e),o;let a=this.dot(e);return 1-a>H.LERP_DELTA?(i=Math.acos(a),s=Math.sin(i),r=Math.sin((1-t)*i)/s,n=Math.sin(t*i)/s):(r=1-t,n=t),H.add(this.scale(r),e.scale(n))}isZero(){return!(this.x||this.y)}}const Po={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"};class qr{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 v(e,e,t),this._radii2=new v(this._a2,this._a2,this._b2),this._invRadii=new v(1/e,1/e,1/t),this._invRadii2=new v(1/this._a2,1/this._a2,1/this._b2)}rhumbDistanceTo(e,t){const i=e.lat*j,s=t.lat*j,r=s-i;let n=Math.abs(t.lon-e.lon)*j;Math.abs(n)>Math.PI&&(n=n>0?-(2*Math.PI-n):2*Math.PI+n);const o=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),a=Math.abs(o)>1e-11?r/o:Math.cos(i);return Math.sqrt(r*r+a*a*n*n)*this._a}getIntermediatePointOnGreatCircle(e,t,i){if(0==i)return e.clone();if(1==i)return t.clone();const s=this.inverse(e,t),r=s.distance,n=s.initialAzimuth;return isNaN(n)?e:this.getGreatCircleDestination(e,n,r*i)}static getBearing(e,t){let i=e.lat*j,s=e.lon*j,r=t.lat*j,n=t.lon*j,o=Math.sin(n-s)*Math.cos(r),a=Math.cos(i)*Math.sin(r)-Math.sin(i)*Math.cos(r)*Math.cos(n-s);return Math.atan2(o,a)*J}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,s=new v){let r=j*t,n=j*e,o=Math.sin(r),a=this._a/Math.sqrt(1-this._e2*o*o),l=(a+i)*Math.cos(r);return s.x=l*Math.cos(n),s.y=l*Math.sin(n),s.z=(a*(1-this._e2)+i)*o,s}projToSurface(e){let t=e.x||0,i=e.y||0,s=e.z||0,r=Math.sqrt(t*t+i*i+s*s);if(0===r)return this.lonLatToCartesian(new L);let n=this._invRadii2.x,o=this._invRadii2.y,a=this._invRadii2.z,l=t*t*n,h=i*i*o,c=s*s*a,d=l+h+c,_=Math.sqrt(1/d),u=e.scaleTo(_);if(d<.1)return Number.isFinite(_)?u:new v;let f=(1-_)*r/u.mulA(this._invRadii2).length(),g=0,p=0,m=0;for(;;){g=1/(1+f*n),p=1/(1+f*o),m=1/(1+f*a);let e=g*g,t=p*p,i=m*m,s=l*e+h*t+c*i-1;if(Math.abs(s)<ar)break;f+=.5*s/(l*(e*g)*n+h*(t*p)*o+c*(i*m)*a)}return new v(t*g,i*p,s*m)}cartesianToLonLat(e){return this.cartesianToLonLatRes(e)}cartesianToLonLatRes(e,t=new L){let i=this.projToSurface(e),s=this.getSurfaceNormal3v(i),r=e.sub(i);return t.lon=Math.atan2(s.y,s.x)*J,t.lat=Math.asin(s.z)*J,t.height=Math.sign(r.dot(e))*r.length(),t}getSurfaceNormal3v(e){let t=this._invRadii2,i=e.x*t.x,s=e.y*t.y,r=e.z*t.z,n=1/Math.sqrt(i*i+s*s+r*r);return new v(i*n,s*n,r*n)}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,s=this._b,r=this._flattening;const n=e.lat*j,o=e.lon*j,a=t.lat*j,l=t.lon*j-o,h=(1-r)*Math.tan(n),c=1/Math.sqrt(1+h*h),d=h*c,_=(1-r)*Math.tan(a),u=1/Math.sqrt(1+_*_),f=_*u,g=Math.abs(l)>Math.PI/2||Math.abs(a-n)>Math.PI/2;let p=l,m=null,v=null,y=g?Math.PI:0,x=0,b=g?-1:1,w=null,T=1,C=1,E=null,A=0;do{if(m=Math.sin(p),v=Math.cos(p),w=(u*m)**2+(c*f-d*u*v)**2,Math.abs(w)<1e-24)break;x=Math.sqrt(w),b=d*f+c*u*v,y=Math.atan2(x,b);const e=c*u*m/x;C=1-e*e,T=0!=C?b-2*d*f/C:0;const t=r/16*C*(4+r*(4-3*C));E=p,p=l+(1-t)*r*e*(y+t*x*(T+t*b*(2*T*T-1)))}while(Math.abs(p-E)>ar&&++A<1e3);const L=C*(i*i-s*s)/(s*s),P=L/1024*(256+L*(L*(74-47*L)-128)),S=s*(1+L/16384*(4096+L*(L*(320-175*L)-768)))*(y-P*x*(T+P/4*(b*(2*T*T-1)-P/6*T*(4*x*x-3)*(4*T*T-3)))),R=Math.abs(w)<Number.EPSILON?0:Math.atan2(u*m,c*f-d*u*v),M=Math.abs(w)<Number.EPSILON?Math.PI:Math.atan2(c*m,-d*u+c*f*v);return{distance:S,initialAzimuth:Math.abs(S)<Number.EPSILON?NaN:Ue(R)*J,finalAzimuth:Math.abs(S)<Number.EPSILON?NaN:Ue(M)*J}}direct(e,t,i){let s=e.lon,r=e.lat,n=this._a,o=this._b,a=this._flattening,l=i,h=t*j,c=Math.sin(h),d=Math.cos(h),_=(1-a)*Math.tan(r*j),u=1/Math.sqrt(1+_*_),f=_*u,g=Math.atan2(_,d),p=u*c,m=1-p*p,v=m*(n*n-o*o)/(o*o),y=1+v/16384*(4096+v*(v*(320-175*v)-768)),x=v/1024*(256+v*(v*(74-47*v)-128)),b=l/(o*y),w=2*Math.PI,T=0,C=0,E=0,A=0;for(;Math.abs(b-w)>1e-12;)T=Math.cos(2*g+b),C=Math.sin(b),E=Math.cos(b),A=x*C*(T+x/4*(E*(2*T*T-1)-x/6*T*(4*C*C-3)*(4*T*T-3))),w=b,b=l/(o*y)+A;let P=f*C-u*E*d,S=Math.atan2(f*E+u*C*d,(1-a)*Math.sqrt(p*p+P*P)),R=a/16*m*(4+a*(4-3*m)),M=Math.atan2(C*c,u*E-f*C*d)-(1-R)*a*p*(b+R*C*(T+R*E*(2*T*T-1))),B=Math.atan2(p,-P);return{destination:new L(s+M*J,S*J),finalAzimuth:B*J}}hitRay(e,t){let i,s,r,n,o,a=this._invRadii.mul(e),l=this._invRadii.mul(t),h=a.dot(a),c=a.dot(l);if(h>1){if(c>=0)return;var d=c*c;if(i=h-1,s=l.dot(l),r=s*i,Math.abs(d-r)>1e-15&&d<r)return;if(d>r){n=c*c-r,o=-c+Math.sqrt(n);var _=o/s,u=i/o;return _<u?e.add(t.scaleTo(_)):e.add(t.scaleTo(u))}var f=Math.sqrt(i/s);return e.add(t.scaleTo(f))}return h<1?(i=h-1,s=l.dot(l),r=s*i,n=c*c-r,o=-c+Math.sqrt(n),e.add(t.scaleTo(o/s))):c<0?(s=l.dot(l),e.add(t.scaleTo(-c/s))):void 0}getNorthFrameRotation(e){let t=this.getSurfaceNormal3v(e),i=v.proj_b_to_plane(v.NORTH,t);return F.getLookRotation(i,t)}getBearingDestination(e,t=0,i=0){t*=j;var s=(e.lon+540)%360-180,r=e.lat*j,n=s*j,o=i/this._a,a=Math.asin(Math.sin(r)*Math.cos(o)+Math.cos(r)*Math.sin(o)*Math.cos(t));return new L((n+Math.atan2(Math.sin(t)*Math.sin(o)*Math.cos(r),Math.cos(o)-Math.sin(r)*Math.sin(a)))*J,a*J)}static getIntermediatePointOnGreatCircle(e,t,i){var s=e.lat*j,r=e.lon*j,n=t.lat*j,o=t.lon*j,a=Math.sin(s),l=Math.cos(s),h=Math.sin(r),c=Math.cos(r),d=Math.sin(n),_=Math.cos(n),u=Math.sin(o),f=Math.cos(o),g=n-s,p=o-r,m=Math.sin(g/2)*Math.sin(g/2)+Math.cos(s)*Math.cos(n)*Math.sin(p/2)*Math.sin(p/2),v=2*Math.atan2(Math.sqrt(m),Math.sqrt(1-m)),y=Math.sin((1-i)*v)/Math.sin(v),x=Math.sin(i*v)/Math.sin(v),b=y*l*c+x*_*f,w=y*l*h+x*_*u,T=y*a+x*d,C=Math.atan2(T,Math.sqrt(b*b+w*w)),E=Math.atan2(w,b);return new L((E*J+540)%360-180,C*J)}static getRhumbBearing(e,t){var i=(t.lon-e.lon)*j,s=Math.log(Math.tan(t.lat*j/2+Math.PI/4)/Math.tan(e.lat*j/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,s)*J+360)%360}getLonLatVisibilitySimple(e,t,i){const s=this.lonLatToCartesian(t),r=t.height,n=this.polarSize+r,o=Math.max(e.length()-this.polarSize,0),a=s.sub(e);let l;return l=o>0?Math.sqrt((n+o)**2-n**2):n,l>a.length()&&(!i||i.dot(a.normalize())>0)}}const So=new qr(6378137,6356752.314245179);function Vi(e,t){return e??t}function Gt(e){return null==e}function vn(e){return void 0===e}let Fa=0;function Yr(e){let t=e._openglobus_id;return t||(t=e._openglobus_id=++Fa),t}function ks(e){return"string"==typeof e||e instanceof String}function ke(e){return e.toString(16).padStart(2,"0")}function cr(e){let t,i,s;return e instanceof Array?(t=ke(e[0]),i=ke(e[1]),s=ke(e[2])):(t=ke(e.x),i=ke(e.y),s=ke(e.z)),`#${t}${i}${s}`}function he(e,t){let i=Po[e];if(i&&(e=i),"#"===e[0]){let i=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,s=e.replace(i,(function(e,t,i,s){return t+t+i+i+s+s})),r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(s);return r?new et(parseInt(r[1],16)/255,parseInt(r[2],16)/255,parseInt(r[3],16)/255,Gt(t)?1:t):new et}{Gt(t)&&(t=1);let i=e.split(",");return new et(parseInt(i[0].split("(")[1])/255,parseInt(i[1])/255,parseInt(i[2])/255,Gt(i[3])?t:parseFloat(i[3]))}}function ve(e,t){let i=he(e,t);return new Float32Array([i.x,i.y,i.z,i.w])}function ts(e){let t=Po[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,s){return t+t+i+i+s+s})),s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return s?new v(parseInt(s[1],16)/255,parseInt(s[2],16)/255,parseInt(s[3],16)/255):new v}{let t=e.split(",");return new v(parseInt(t[0].split("(")[1])/255,parseInt(t[1])/255,parseInt(t[2])/255)}}function Dt(e,t){return e.replace(/{[^{}]+}/g,(function(e){return t[e.replace(/[{}]+/g,"")]||""}))}function di(e,t){return e.replace(/\$\{([^}]+)\}/g,((e,i)=>(null==t?void 0:t[i.trim()])??""))}function Wr(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 Ro(e,t,i,s){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=`${s}px`}function Mo(e){return"number"==typeof e}function Bo(e,t=""){return e?e.trim():t}function Yt(e,t){if(e){if(Mo(e))return new v(e,e,e);if(e instanceof v)return e.clone();if(e instanceof Array)return v.fromVec(e);if(e instanceof H)return new v(e.x,e.y,0)}else if(t)return t;return new v}function le(e,t){if(e){if(ks(e))return he(e);if(e instanceof Array)return et.fromVec(e);if(e instanceof et)return e.clone()}else if(t)return t;return new et(1,1,1,1)}function jt(e,t){if(e){if(ks(e))return ts(e);if(e instanceof Array)return v.fromVec(e);if(e instanceof v)return e.clone()}else if(t)return t;return new v(1,1,1)}function $r(e,t){if(e){if(e instanceof Array)return new U(vi(e[0]),vi(e[1]));if(e instanceof U)return e.clone()}else if(t)return t;return new U}function vi(e,t){if(e){if(e instanceof Array)return new L(e[0],e[1],e[2]);if(e instanceof L)return e.clone()}else if(t)return t;return new L}function Xr(e,t){let i=0,s=e.length-1;for(;i<=s;){let r=Math.floor(.5*(i+s));if(Math.abs(e[r]-t)<.001)return r;e[r]<t?i=r+1:s=r-1}return-1}function Re(e,t,i){let s=0,r=e.length-1;for(;s<=r;){let n=r+s>>1,o=i(t,e[n],n);if(o>0)s=n+1;else{if(!(o<0))return n;r=n-1}}return-s-1}function Zr(e,t,i){let s=Re(e,t,i);return s<0&&(s=~s),e.splice(s,0,t),s}function ko(e,t,i,s,r=!1){let n=new L(t.lon-e.lon,t.lat-e.lat),o=new L(s.lon-i.lon,s.lat-i.lat),a=-n.lat,l=+n.lon,h=-(a*e.lon+l*e.lat),c=-o.lat,d=+o.lon,_=-(c*i.lon+d*i.lat),u=c*e.lon+d*e.lat+_,f=c*t.lon+d*t.lat+_,g=a*i.lon+l*i.lat+h,p=a*s.lon+l*s.lat+h;if(r&&(u*f>0||g*p>0))return;let m=u/(u-f);return new L(e.lon+m*n.lon,e.lat+m*n.lat)}const Oa={string:function(e){return Gt(e)?e:e.toString()},date:function(e){return Gt(e)?e:new Date(1e3*e)},datetime:function(e){return Gt(e)?e:new Date(1e3*e)},time:function(e){return Gt(e)?e:parseInt(e)},integer:function(e){return Gt(e)?e:parseInt(e)},float:function(e){return Gt(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 yn(e,t=""){let i=1024,s=atob(e),r=s.length,n=Math.ceil(r/i),o=new Array(n);for(let e=0;e<n;++e){let t=e*i,n=Math.min(t+i,r),a=new Array(n-t);for(let e=t,i=0;e<n;++i,++e)a[i]=s[e].charCodeAt(0);o[e]=new Uint8Array(a)}return new Blob(o,{type:t})}function yi(e,t,i=!1){let s,r=0;return function(){const n=arguments;r?(i&&clearTimeout(s),s=setTimeout((()=>{Date.now()-r>=t&&(e.apply(null,n),r=Date.now())}),t-(Date.now()-r))):(e.apply(null,n),r=Date.now())}}function it(e,t){let i=new e.constructor(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function bt(e=[],t=[]){if(ArrayBuffer.isView(e))return it(e,t);for(let i=0;i<t.length;i++)e.push(t[i]);return e}function st(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 Et(e,t,i,s){if(ArrayBuffer.isView(e))return t<0&&(i=Math.abs(t),t+=e.length),ot(e,t,i,s);{let r;return r=t<0?e.splice(t):e.splice(t,i),s&&(s.result=r),e}}function ot(e,t,i,s){if(0===e.length)return e;const r=e.length-i,n=new e.constructor(r);return n.set(e.subarray(0,t)),n.set(e.subarray(t+i),t),s&&(s.result=e.subarray(t,t+i)),n}function Kr(e,t,i,s,r){const n=r+1,o=i+n,a=s+n;let l=new Float64Array(n*n*3),h=0;for(let r=i;r<o;r++)for(let i=s;i<a;i++){let s=3*(r*(t+1)+i);l[h++]=e[s],l[h++]=e[s+1],l[h++]=e[s+2]}return l}function Io(e,t,i,s,r){const n=r+1,o=i+n,a=s+n;let l=new Float32Array(n*n*3),h=0;for(let r=i;r<o;r++)for(let i=s;i<a;i++){let s=3*(r*(t+1)+i);l[h++]=e[s],l[h++]=e[s+1],l[h++]=e[s+2]}return l}function dr(e,t,i,s,r,n,o,a,l,h,c,d,_){const u=n+a+1,f=o+a+1;r+=1;let g=0,p=0;for(let a=n;a<u;a++)for(let n=o;n<f;n++){let o=a*r+n,u=3*o,f=e[u],m=e[u+1],v=e[u+2];s&&0!==s[o]?_[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 Qr(e){return e.map((e=>Array.isArray(e)?Qr(e):e))}async function Ui(e){return new Promise((t=>{const i=new Image;return i.addEventListener("load",(()=>{t(i)})),i.src=e,i.crossOrigin="",i}))}function ur(e){return e.complete&&0!==e.naturalHeight}function Ge(e){return e>1e3?e-Math.floor(e)!=0?[(e/1e3).toFixed(2),"km"]:[(e/1e3).toFixed(0),"km"]:e>9?[Math.round(e).toString(),"m"]:e<=.01?["0","m"]:[e.toFixed(1),"m"]}function zo(e){let t=new URLSearchParams(location.search).get(e);if(t)return Number(t)}function _r(e,t=-1){if(t<0)return e.toString();const i=Math.pow(10,t);return(Math.round(e*i)/i).toString()}const zc=Object.freeze(Object.defineProperty({__proto__:null,base64StringToBlog:function(e){let t=e.split(";"),i=t[0].split(":")[1];return yn(t[1].split(",")[1],i)},base64toBlob:yn,binaryInsert:Zr,binarySearch:Re,binarySearchFast:Xr,blerp:function(e,t,i,s,r,n,o=0,a=1,l=0,h=1){return(i*(a-e)*(h-t)+s*(e-o)*(h-t)+r*(a-e)*(t-l)+n*(e-o)*(t-l))/((a-o)*(h-l))},blerp2:function(e,t,i,s,r,n){return i*(1-e)*(1-t)+s*e*(1-t)+r*(1-e)*t+n*e*t},castType:Oa,cloneArray:Qr,concatArrays:bt,concatTypedArrays:it,createColorRGB:jt,createColorRGBA:le,createExtent:$r,createLonLat:vi,createVector3:Yt,createVector4:function(e,t){if(e){if(e instanceof et)return e.clone();if(e instanceof Array)return et.fromVec(e)}else if(t)return t;return new et},defaultString:Bo,distanceFormat:function(e){return e>1e3?`${(e/1e3).toFixed(2)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`},distanceFormatExt:Ge,extractElevationTiles:function(e,t,i){let s=Math.sqrt(t.length)-1,r=s+1,n=Math.sqrt(e.length/4),o=n/s,a=0,l=0;for(let h=0,c=0,d=e.length/4;h<d;h++){let d=e[4*h],_=Math.floor(h/n),u=h%n,f=Math.floor(u/s),g=Math.floor(_/s),p=i[g][f],m=_%s,v=u%s,y=(m+g)*r+v+f;if(p[y]=d,(_+g)%o==0&&(u+f)%o==0&&(t[c++]=d),(u+1)%s==0&&u!==n-1){a=e[4*(h+1)];let n=.5*(d+a);y=(m+g)*r+v+1,p[y]=n,(_+g)%o==0&&(t[c++]=n);let l=(m+g)*r+(v+1)%s;i[g][f+1][l]=n}if((_+1)%s==0&&_!==n-1){l=e[4*(h+n)];let a=.5*(d+l);y=(m+1)*r+v+f,p[y]=a,(u+f)%o==0&&(t[c++]=a);let _=(m+1)%s*r+v+f;i[g+1][f][_]=a}if((u+1)%s==0&&u!==n-1&&(_+1)%s==0&&_!==n-1){let o=.25*(d+a+l+e[4*(h+n+1)]);y=(m+1)*r+(v+1),p[y]=o,t[c++]=o;let _=(m+1)*r;i[g][f+1][_]=o;let u=s;i[g+1][f][u]=o;let x=0;i[g+1][f+1][x]=o}}},getDefault:Vi,getHTML:function(e,t){return Dt(e,t)},getLinesIntersection2v:function(e,t,i,s,r){let n=t.sub(e),o=s.sub(i),a=-n.y,l=+n.x,h=-(a*e.x+l*e.y),c=-o.y,d=+o.x,_=-(c*i.x+d*i.y),u=c*e.x+d*e.y+_,f=c*t.x+d*t.y+_,g=a*i.x+l*i.y+h,p=a*s.x+l*s.y+h;if(r&&(u*f>0||g*p>0))return;let m=u/(u-f);return new H(e.x+m*n.x,e.y+m*n.y)},getLinesIntersectionLonLat:ko,getMatrixSubArray32:Io,getMatrixSubArray64:Kr,getMatrixSubArrayBoundsExt:dr,getTileImageResolution:function(e,t,i,s=256,r=So){let n=Ze(e,t,i),o=n.getSouthWest().inverseMercator(),a=n.getNorthEast().inverseMercator();return[r.getGreatCircleDistance(o,new L(a.lon,o.lat))/s,r.getGreatCircleDistance(o,new L(o.lon,a.lat))/s]},getUrlParam:zo,htmlColorToFloat32Array:ve,htmlColorToRgb:ts,htmlColorToRgba:he,isEmpty:Gt,isImageLoaded:ur,isNumber:Mo,isString:ks,isUndef:vn,isUndefExt:function(e,t){return vn(e)?t:e},loadImage:Ui,makeArray:Ve,makeArrayTyped:st,parseHTML:Wr,print2d:Ro,rgbToStringHTML:cr,spliceArray:Et,spliceTypedArray:ot,stamp:Yr,stringTemplate:Dt,stringTemplate2:di,throttle:yi,toFixedMax:_r,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 s=t.attributes.item(e);i["@attributes"][s.nodeName]=s.nodeValue}}}else 3===t.nodeType&&(i=t.nodeValue);if(t.hasChildNodes())for(let s=0;s<t.childNodes.length;s++){let r=t.childNodes.item(s),n=r.nodeName;if(void 0===i[n])i[n]=e(r);else{if(void 0===i[n].push){let e=i[n];i[n]=[],i[n].push(e)}i[n].push(e(r))}}return i}},Symbol.toStringTag,{value:"Module"})),Gi=1e3,fr=1/60,xn=1/24,xi=3600,gr=1/xi,Jr=43200,ji=1440,Na=1/ji,ee=86400,Ha=864e5,tn=1.1574074074074074e-8,oe=1/ee,es=2451545;function Do(e,t,i){let s=(t-14)/12|0,r=e+4800+s;return(1461*r/4|0)+(367*(t-2-12*s)/12|0)-(3*((r+100)/100|0)/4|0)+i-32075}function is(e){let t=Do(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()),i=e.getUTCHours()-12;i<0&&(i+=24);let s=e.getUTCSeconds()+i*xi+60*e.getUTCMinutes()+.001*e.getUTCMilliseconds();s>=Jr&&t--;let r=s*oe|0;return t+=r,s-=ee*r,s<0&&(t--,s+=ee),t+s*oe}function pr(e){let t=Oo,i=Re(t,e,(function(e,t){return e-t.jd}));i<0&&(i=~i),i>=t.length&&(i=t.length-1);let s=t[i].leapSeconds;return 0!==i&&(t[i].jd-e)*ee>s&&(s=t[i-1].leapSeconds),e+s*oe}function Gs(e){let t=Oo,i=Re(t,e,(function(e,t){return e-t.jd}));if(i<0&&(i=~i),i>=t.length)return e-t[i-1].leapSeconds*oe;if(0===i)return e-t[0].leapSeconds*oe;let s=(t[i].jd-e)*ee;return 0===s?e-t[i].leapSeconds*oe:s<=1?void 0:e-t[i-1].leapSeconds*oe}function mr(e){let t=0|e,i=(e-t)*ee;i>=Jr&&t++;let s=t+68569|0,r=4*s/146097|0;s=s-((146097*r+3)/4|0)|0;let n=4e3*(s+1)/1461001|0;s=s-(1461*n/4|0)+31|0;let o=80*s/2447|0,a=s-(2447*o/80|0)|0;s=o/11|0;let l=o+2-12*s|0,h=100*(r-49)+n+s|0,c=i*gr|0,d=i-c*xi,_=d*fr|0;d-=60*_;let u=0|d,f=(d-u)*Gi|0;return c+=12,c>23&&(c-=24),new Date(Date.UTC(h,l-1,a,c,_,u,f))}function Fo(e,t){return e+t*tn}function bn(e,t){return e+t*oe}function nt(e,t){return{jd:e,leapSeconds:t}}const Oo=[nt(2441317.5,10),nt(2441499.5,11),nt(2441683.5,12),nt(2442048.5,13),nt(2442413.5,14),nt(2442778.5,15),nt(2443144.5,16),nt(2443509.5,17),nt(2443874.5,18),nt(2444239.5,19),nt(2444786.5,20),nt(2445151.5,21),nt(2445516.5,22),nt(2446247.5,23),nt(2447161.5,24),nt(2447892.5,25),nt(2448257.5,26),nt(2448804.5,27),nt(2449169.5,28),nt(2449534.5,29),nt(2450083.5,30),nt(2450630.5,31),nt(2451179.5,32),nt(2453736.5,33),nt(2454832.5,34),nt(2456109.5,35),nt(2457204.5,36)],Va=pr(es),Dc=Object.freeze(Object.defineProperty({__proto__:null,DAYS_PER_JULIAN_CENTURY:36525,DAYS_PER_JULIAN_YEAR:365.25,DateToTAI:function(e){return pr(is(e))},DateToUTC:is,HOURS_PER_DAY:24,J2000:es,J2000TAI:Va,MILLISECONDS_PER_DAY:Ha,MILLISECONDS_PER_SECOND:Gi,MINUTES_PER_DAY:ji,MINUTES_PER_HOUR:60,MODIFIED_JULIAN_DATE_DIFFERENCE:2400000.5,ONE_BY_HOURS_PER_DAY:xn,ONE_BY_MILLISECONDS_PER_DAY:tn,ONE_BY_MINUTES_PER_DAY:Na,ONE_BY_SECONDS_PER_DAY:oe,ONE_BY_SECONDS_PER_HOUR:gr,ONE_BY_SECONDS_PER_MINUTE:fr,PICOSECOND:1e-9,SECONDS_PER_12_HOURS:Jr,SECONDS_PER_DAY:ee,SECONDS_PER_HOUR:xi,SECONDS_PER_MILLISECOND:.001,SECONDS_PER_MINUTE:60,T:function(e){return(e-es)/36525},TAItoDate:function(e){let t=Gs(e);return t||(t=Gs(bn(e,-1)),console.trace(`TAItoDate - can't convert ${e.toString()} to utc.`)),mr(t)},TAItoUTC:Gs,UTCtoDate:mr,UTCtoTAI:pr,addDays:function(e,t){return e+t},addHours:function(e,t){return e+t*xn},addMilliseconds:Fo,addMinutes:function(e,t){return e+t*ji},addSeconds:bn,daysToSeconds:function(e){return e*ee},getDayNumber:Do,getDays:function(e){return 0|e},getHours:function(e){let t=(e-(0|e))*ee,i=t*gr|0,s=t-i*xi,r=s*fr|0;s-=60*r;let n=0|s;return i+=12+r/60+n/3600+((s-n)*Gi|0)/1e3,i>23&&(i-=24),i},getMilliseconds:function(e){let t=e-(0|e);return t*=ee,(t-(0|t))*Gi|0},getMinutes:function(e){return(e-(0|e))*ji|0},getSeconds:function(e){return(e-(0|e))*ee},secondsToDays:function(e){return e*oe}},Symbol.toStringTag,{value:"Module"}));class No{constructor(e){this.vertices=[new v,new v,new v,new v,new v,new v,new v,new v],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],s=e[1],r=e[4],n=e[2],o=e[5],a=this.vertices;a[0].set(t,s,n),a[1].set(i,s,n),a[2].set(i,s,o),a[3].set(t,s,o),a[4].set(t,r,n),a[5].set(i,r,n),a[6].set(i,r,o),a[7].set(t,r,o)}setFromExtent(e,t){this.setFromBoundsArr(t.getCartesianBounds(e))}}class Ft{constructor(e=0,t){this.radius=e,this.center=t?t.clone():new v}setFromBounds(e){let t=new v(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))}}const Fc=Object.freeze(Object.defineProperty({__proto__:null,Box:No,Sphere:Ft},Symbol.toStringTag,{value:"Module"}));function lt(e,t){return new bi(e,t)}const cs=class e{constructor(t,i){this.__id=e.__counter__++,this._eventNames=[],t&&this.registerNames(t),this._sender=i||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=Yr(t),s=this._getStamp(e,this.__id,i);return!this._stampCache[s]&&(this._stampCache[s]=i,!0)}on(e,t,i,s=0){if(this._stamp(e,t)&&this[e]){let r=t.bind(i||this._sender);r._openglobus_id=t._openglobus_id,r._openglobus_priority=s,Zr(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 s=this[e].handlers,r=s.length,n=-1;for(;r--;)if(s[r]._openglobus_id===t._openglobus_id){n=r;break}-1!==n&&(s.splice(n,1),this._stampCache[i]=void 0,delete this._stampCache[i])}}}dispatch(e,...t){let i=!0;if(e&&e.active&&!this._stopPropagation){let s=e.handlers.slice(0),r=s.length;for(;r--;)!1===s[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=[]}};cs.__counter__=0;let bi=cs;const Ua=["render"],Vt=class e{constructor(t={}){this.__id=e.__counter__++,this.events=lt(Ua),this.model=t.model||null,this.template=t.template||"",this.parent=t.parent||null,this._classList=t.classList||[],this.el=null,t.initRender&&this.render()}on(e,t,i,s){this.events.on(e,t,i,s)}off(e,t){this.events.off(e,t)}static getHTML(e,t){return Dt(e,t)}static parseHTML(e){return Wr(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(t){this.el||this.render(),this.el&&(t instanceof HTMLElement&&t.parentNode&&e.insertBefore(this.el,t),t instanceof e&&t.el&&t.el.parentNode&&e.insertBefore(this.el,t.el))}insertAfter(t){this.el||this.render(),this.el&&(t instanceof HTMLElement&&t.parentNode&&e.insertAfter(this.el,t),t instanceof e&&t.el&&t.el.parentNode&&e.insertAfter(this.el,t.el))}isEqual(e){return e.__id===this.__id}appendTo(t,i=!1,s=!1){return t&&(this.el||(this.beforeRender(t),this.render()),this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),i&&(t.innerHTML=""),this.el&&(s&&t.childNodes[0]?e.insertBefore(this.el,t.childNodes[0]):t.appendChild(this.el)),this.afterRender(t)),this}afterRender(e){}beforeRender(e){}stopPropagation(){this.events.stopPropagation()}renderTemplate(t){return e.parseHTML(e.getHTML(this.template,t||{}))[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,s=i.length;e<s;e++)t(i[e],e);return i}}remove(){this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el)}};Vt.__counter__=0;let ut=Vt;const Ga=["click","mousedown","mouseup","touchstart","touchend","touchcancel"];class ce extends ut{constructor(e={}){super({template:Dt('<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(Ga),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)}}const ds=class e{constructor(t={}){this.__id=e.__counter__++,this._name=t.name||`_control_${this.__id.toString()}`,this.planet=null,this._initialized=!1,this.renderer=null,this.autoActivate=t.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&&(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}};ds.__counter__=0;let Q=ds;class Ho extends Q{constructor(e={}){super(e),this._heading=0,this._svg=null}oninit(){let e=new ce({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),e.events.on("touchstart",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)),{amplitude:0,completeCallback:()=>{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 Vo='<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>',ja=["resize","focus","visibility","dragstart","dragend"],us=class e extends ut{constructor(e={}){super({template:Dt('<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:Vi(e.visible,!0)?"flex":"none",resize:Vi(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(ja),this._width=e.width||300,this._height=e.height||200,this._startPosX=0,this._startPosY=0,this.$header=null,this.$title=null,this.$container=null,this.$buttons=null,this._closeBtn=new ce({icon:Vo,classList:["og-button-size__20"]}),this.useHide=e.useHide||!1,this._visibility=Vi(e.visible,!0),this._right=null!=e.right?e.right:null}setContainer(e){this.$container.innerHTML=e}get container(){return this.$container}get width(){return this.el?parseFloat(this.el.style.width):this._width}get height(){return this.el?parseFloat(this.el.style.height):this._height}bringToFront(){this.el.style.zIndex=String(e.__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(),null!=this._right&&(this.el.style.visibility="hidden",new IntersectionObserver(((e,t)=>{e.forEach((e=>{e.isIntersecting&&(this.el.style.visibility="visible",this.el.parentNode&&(this.setPosition(this.el.parentNode.clientWidth-this.el.clientWidth-this._right),t.disconnect()))}))})).observe(this.el)),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()}getVisibility(){return this._visibility}_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)}};us.__zIndex__=0;let Kt=us;const qa=["change"];class dt extends ce{constructor(e){super({...e}),this._onMouseClick=e=>{this.preventClick||(this._mouseClickHandler(e),this.setActive(!this.isActive))},this.events=this.events.registerNames(qa),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 ui=[2,3,0,1],wn=[[-1,-1,0,1],[1,-1,3,-1],[2,3,-1,-1],[-1,0,-1,2]],Ya=[[2,3,0,1],[1,0,3,2],[2,3,0,1],[1,0,3,2]],Wa=[[0,1,0,0],[1,0,0,0],[0,1,0,1],[1,1,1,1]];class Uo{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 _s=class e{constructor(t,i={}){if(this.isVector=!1,this.__id=e.__counter__++,this._iconSrc=i.iconSrc||null,this.events=lt(Go,this),this.name=t||"noname",this.properties=i.properties||{},this.hideInLayerSwitcher=i.hideInLayerSwitcher||!1,this._hasImageryTiles=!0,this._opacity=null!=i.opacity?i.opacity:1,this.minZoom=i.minZoom||0,this.maxZoom=null!=i.maxZoom?i.maxZoom:50,this._planet=null,this.isVector=!1,this._attribution=i.attribution||"",this._zIndex=i.zIndex||0,this._isBaseLayer=i.isBaseLayer||!1,this._defaultTextures=i.defaultTextures||[null,null],this._visibility=void 0===i.visibility||i.visibility,this._fading=i.fading||!1,this._fadingFactor=this._opacity/30,this._fading?this._fadingOpacity=0:this._fadingOpacity=this._opacity,this._height=i.height||0,this._extent=new U,this.createTexture=null,this._textureFilter=i.textureFilter?i.textureFilter.trim().toUpperCase():"MIPMAP",this._isSRGB=null!=i.isSRGB&&i.isSRGB,this._internalFormat=null,this._extentMerc=new U,this.setExtent($r(i.extent,new U(new L(-180,-90),new L(180,90)))),this._pickingColor=new v,this._pickingEnabled=void 0===i.pickingEnabled||i.pickingEnabled,this._isPreloadDone=!1,this._preLoadZoomLevels=i.preLoadZoomLevels||[0,1],this._ambient=null,this._diffuse=null,this._specular=null,i.ambient){let e=jt(i.ambient,new v(.2,.2,.2));this._ambient=new Float32Array([e.x,e.y,e.z])}if(i.diffuse){let e=jt(i.diffuse,new v(.8,.8,.8));this._diffuse=new Float32Array([e.x,e.y,e.z])}if(i.specular){let e=jt(i.specular,new v(3e-4,3e-4,3e-4)),t=i.shininess||20;this._specular=new Float32Array([e.x,e.y,e.z,t])}this.nightTextureCoefficient=i.nightTextureCoefficient||1}get iconSrc(){return this._iconSrc}set iconSrc(e){this._iconSrc=e}set diffuse(e){if(e){let t=jt(e);this._diffuse=new Float32Array(t.toArray())}else this._diffuse=null}set ambient(e){if(e){let t=jt(e);this._ambient=new Float32Array(t.toArray())}else this._ambient=null}set specular(e){if(e){let t=jt(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,s){return`${s}::${e}_${t}_${i}`}get instanceName(){return"Layer"}get rendererEvents(){return this.events}set opacity(e){e!==this._opacity&&(this._fading?e>this._opacity?this._fadingFactor=(e-this._opacity)/30:e<this._opacity&&(this._fadingFactor=(this._opacity-e)/30):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.quadTreeStrategy._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||(e.quadTreeStrategy._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,s=e.nodes.length;i<s;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,s=e.quadTreeStrategy.quadTreeList.length;i<s;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<Ot&&(t.lat=Ot),i.lat>ct&&(i.lat=ct),this._extent=e.clone(),this._extentMerc=new U(t.forwardMercator(),i.forwardMercator()),this._correctFullExtent()}getExtent(){return this._extent}getExtentMerc(){return this._extentMerc}flyExtent(){var e;null==(e=this._planet)||e.flyExtent(this.getExtent())}viewExtent(){var e;null==(e=this._planet)||e.viewExtent(this.getExtent())}_correctFullExtent(){}get opacity(){return this._opacity}get screenOpacity(){return this._fading?this._fadingOpacity:this._opacity}_refreshFadingOpacity(e,t){let i=this._planet;return this._visibility&&i.getViewExtent().overlaps(this._extent)&&t>=this.minZoom&&e<=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-=this._fadingFactor,this._fadingOpacity<=0&&(this._fadingOpacity=0),!1)}createMaterial(e){return new Uo(e,this)}redraw(){var e;null==(e=this._planet)||e.quadTreeStrategy.clearLayerMaterial(this)}abortMaterialLoading(e){}abortLoading(){}};_s.__counter__=0;let zt=_s;const Go=["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"],$a=["load","loadend"],Ut=class e extends zt{constructor(e,t){super(e,t),this.events=this.events.registerNames($a),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.quadTreeStrategy._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(t){let i=t.segment;this._isBaseLayer?t.texture=i.getDefaultTexture():t.texture=i.planet.transparentTexture,(this._planet.layerLock.isFree()||t.segment.tileZoom<2)&&(t.isReady=!1,t.isLoading=!0,e.__requestsCounter>=e.MAX_REQUESTS&&this._counter?this._pendingsQueue.push(t):this._exec(t))}_exec(t){e.__requestsCounter++,this._counter++;const i=this.events.load;i.handlers.length&&this.events.dispatch(i,t),requestAnimationFrame((()=>{this.drawTile(t,(i=>{this._counter--,e.__requestsCounter--,this._correctCounter(),t.isLoading&&t.applyImage(i),this._dequeueRequest()}))}))}_correctCounter(){this._counter<0&&(this._counter=0),e.__requestsCounter<0&&(e.__requestsCounter=0)}abortMaterialLoading(t){t.isLoading&&(this._counter--,e.__requestsCounter--,this._correctCounter(),this._dequeueRequest()),t.isLoading=!1,t.isReady=!1}_dequeueRequest(){if(this._pendingsQueue.length){if(e.__requestsCounter<e.MAX_REQUESTS){const e=this._whilePendings();e&&this._exec(e)}}else 0===this._counter&&this._planet&&this._planet.quadTreeStrategy._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,s=!1,r=e.layer.maxNativeZoom;t.passReady&&!e.isLoading&&t.tileZoom<=r&&this.loadMaterial(e);let n=this._id,o=e;for(;i.parentNode;)if(i=i.parentNode,o=i.segment.materials[n],o&&o.textureExists){s=!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 s=i.segment.materials[n];s?!s.isLoading&&!s.isReady&&this.loadMaterial(s):(s=i.segment.materials[e.layer._id]=e.layer.createMaterial(i.segment),this.loadMaterial(s))}if(s){e.layer.animated&&requestAnimationFrame((()=>{e.segment&&this.drawTile(e,(function(t){e.applyImage(t)}))})),e.appliedNodeId=i.nodeId,e.texture=o.texture;let s=1/(2<<t.tileZoom-i.segment.tileZoom-1);e.texOffset[0]=t.tileX*s-i.segment.tileX,e.texOffset[1]=t.tileY*s-i.segment.tileY,e.texOffset[2]=s,e.texOffset[3]=s}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}};Ut.MAX_REQUESTS=20,Ut.__requestsCounter=0;let ss=Ut;const Xa=["change"];class jo{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=lt(Xa),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 en{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){if(ks(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)}}else for(let t=0;t<this._numWorkers;t++){let t=new e;t.onmessage=e=>{this._onMessage(e),this._workerQueue&&this._workerQueue.unshift(e.target),this.check()},this._workerQueue.push(t)}}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=[],this._workerQueue=[]}get pendingQueue(){return this._pendingQueue}}const qo='(function(){"use strict";function n(i,f,u){let o=u.length,b=f*o;for(let A=0;A<o;A++)i[b+A]=u[A]}self.onmessage=function(i){var f=i.data.labelData,u=f[0],o=f[1],b=f[2],A=f[3],z=f[4],D=f[5],H=f[6],I=f[7],L=f[8],M=f[9],P=f[10],j=f[11],q=f[12],B=f[13],E=f[14],G=f[15],J=f[16],K=f[17],N=f[18],O=f[19],Q=f[20],R=f[21],S=f[22],T=f[23],U=f[24],Z=f[25],_=f[26],$=f[27],V=f[28],X=f[29];let w=new Float32Array(12*o),s=new Float32Array(24*o),y=new Float32Array(24*o),F=new Float32Array(18*o),g=new Float32Array(18*o),c=new Float32Array(6*o),d=new Float32Array(18*o),p=new Float32Array(24*o),x=new Float32Array(6*o),h=new Float32Array(18*o),v=new Float32Array(6*o),C=new Float32Array(6*o),m=new Float32Array(24*o),k=new Float32Array(18*o);for(let t=0;t<o;t++){n(w,t,b!==0?[0,0,0,-1,1,-1,1,-1,1,0,0,0]:[0,0,0,0,0,0,0,0,0,0,0,0]),n(s,t,[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(y,t,[1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0]);var l,r=A,e=z,a=D;n(F,t,[r,e,a,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a]),n(g,t,[r=H,e=I,a=L,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a]),n(c,t,[r=M,r,r,r,r,r]),n(d,t,[r=P,e=j,a=q,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a]),n(p,t,[r=B,e=E,a=G,l=J,r,e,a,l,r,e,a,l,r,e,a,l,r,e,a,l,r,e,a,l]),n(x,t,[r=K,r,r,r,r,r]),n(h,t,[r=N,e=O,a=Q,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a]),n(v,t,[r=R,r,r,r,r,r]),n(C,t,[r=S,r,r,r,r,r]),n(m,t,[r=T,e=U,a=Z,l=_,r,e,a,l,r,e,a,l,r,e,a,l,r,e,a,l,r,e,a,l]),n(k,t,[r=$/255,e=V/255,a=X/255,r,e,a,r,e,a,r,e,a,r,e,a,r,e,a])}self.postMessage({id:u,vertexArr:w,texCoordArr:s,gliphParamArr:y,positionHighArr:F,positionLowArr:g,sizeArr:c,offsetArr:d,rgbaArr:p,rotationArr:x,alignedAxisArr:h,fontIndexArr:v,outlineArr:C,outlineColorArr:m,pickingColorArr:k},[w.buffer,s.buffer,y.buffer,F.buffer,g.buffer,c.buffer,d.buffer,p.buffer,x.buffer,h.buffer,v.buffer,C.buffer,m.buffer,k.buffer])}})();\n//# sourceMappingURL=LabelWorker.worker-BT1uJgYn.js.map\n',Tn=typeof self<"u"&&self.Blob&&new Blob([qo],{type:"text/javascript;charset=utf-8"});function Za(e){let t;try{if(t=Tn&&(self.URL||self.webkitURL).createObjectURL(Tn),!t)throw"";const i=new Worker(t,{name:null==e?void 0:e.name});return i.addEventListener("error",(()=>{(self.URL||self.webkitURL).revokeObjectURL(t)})),i}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(qo),{name:null==e?void 0:e.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}const Mt=-2,mt=-1;class Ka extends en{constructor(e=4){super(e,Za)}_onMessage(e){let t=this._source.get(e.data.id);-2===t.label._lockId?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 s=this._workerQueue.pop();this._source.set(this._sourceId,e),t._lockId=this._sourceId,this._sourceId++,s.postMessage({labelData:i},[i.buffer])}else this._pendingQueue.push(e)}}}const fs=class e{constructor(t={}){this.__id=e.__counter__++,this._position=Yt(t.position),this._positionHigh=new v,this._positionLow=new v,v.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._rotation=t.rotation||0,this._color=le(t.color),this._alignedAxis=Yt(t.alignedAxis),this._offset=Yt(t.offset),this._visibility=null==t.visibility||t.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1,this._isReady=!1,this._lockId=-1}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,v.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):-1!==this._lockId&&(this._lockId=-2)}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z,v.doubleToTwoFloats(e,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):-1!==this._lockId&&(this._lockId=-2)}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):-1!==this._lockId&&(this._lockId=-2)}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):-1!==this._lockId&&(this._lockId=-2))}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):-1!==this._lockId&&(this._lockId=-2))}setColor(e,t,i,s){s===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!=s&&(this._color.w=s),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):-1!==this._lockId&&(this._lockId=-2))}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(he(e))}getColor(){return this._color}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._isReady&&this._handler?this._handler.setVisibility(this._handlerIndex,e):-1!==this._lockId&&(this._lockId=-2))}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):-1!==this._lockId&&(this._lockId=-2)}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):-1!==this._lockId&&(this._lockId=-2)}serializeWorkerData(e){return this._handler?new Float32Array([]):null}};fs.__counter__=0;let rs=fs;class Qa extends rs{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 s=i.renderer.billboardsTextureAtlas,r=this;s.loadImage(e,(function(e){null!=e.__nodeIndex&&s.get(e.__nodeIndex)?(r._image=e,t.setTexCoordArr(r._handlerIndex,s.get(r._image.__nodeIndex).texCoords)):(s.addImage(e),s.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=(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",e))(ai||{});const Ja={POINT:1,LINESTRING:2,POLYGON:3,MULTIPOLYGON:4,MULTILINESTRING:5},ue=class e{constructor(t={}){this.__id=e.__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=t.type&&e.getType(t.type)||1,this._coordinates=t.coordinates||[],this._extent=e.getExtent({type:t.type||"POINT",coordinates:t.coordinates||[]},this._coordinates),t.style=t.style||{},this._style={fillColor:le(t.style.fillColor,new et(.19,.62,.85,.4)),lineColor:le(t.style.lineColor,new et(.19,.62,.85,1)),strokeColor:le(t.style.strokeColor,new et(1,1,1,.95)),lineWidth:t.style.lineWidth||3,strokeWidth:t.style.strokeWidth||0},this._visibility=t.visibility||!0,this._pickingReady=!1}get id(){return this.__id}get type(){return this._type}static getType(e){return Ja[e.toUpperCase()]}static getExtent(t,i){let s=new U(new L(180,90),new L(-180,-90)),r=e.getType(t.type);if(1===r){let e=t.coordinates[0],r=t.coordinates[1];s.southWest.lon=e,s.southWest.lat=r,s.northEast.lon=e,s.northEast.lat=r,i&&(i[0]=e)&&(i[1]=r)}else if(2===r){let e=t.coordinates;for(let t=0;t<e.length;t++){let r=e[t][0],n=e[t][1];r<s.southWest.lon&&(s.southWest.lon=r),n<s.southWest.lat&&(s.southWest.lat=n),r>s.northEast.lon&&(s.northEast.lon=r),n>s.northEast.lat&&(s.northEast.lat=n),i&&(i[t]=[r,n])}}else if(3===r){let e=t.coordinates;for(let t=0;t<e.length;t++){let r=e[t];i&&(i[t]=[]);for(let e=0;e<r.length;e++){let n=r[e],o=n[0],a=n[1];o<s.southWest.lon&&(s.southWest.lon=o),a<s.southWest.lat&&(s.southWest.lat=a),o>s.northEast.lon&&(s.northEast.lon=o),a>s.northEast.lat&&(s.northEast.lat=a),i&&(i[t][e]=[o,a])}}}else if(4===r){let e=t.coordinates;for(let t=0;t<e.length;t++){let r=e[t];i&&(i[t]=[]);for(let e=0;e<r.length;e++){let n=r[e];i&&(i[t][e]=[]);for(let r=0;r<n.length;r++){let o=n[r],a=o[0],l=o[1];a<s.southWest.lon&&(s.southWest.lon=a),l<s.southWest.lat&&(s.southWest.lat=l),a>s.northEast.lon&&(s.northEast.lon=a),l>s.northEast.lat&&(s.northEast.lat=l),i&&(i[t][e][r]=[a,l])}}}}else if(5===r){let e=t.coordinates;for(let t=0;t<e.length;t++){let r=e[t];i&&(i[t]=[]);for(let e=0;e<r.length;e++){let n=r[e],o=n[0],a=n[1];o<s.southWest.lon&&(s.southWest.lon=o),a<s.southWest.lat&&(s.southWest.lat=a),o>s.northEast.lon&&(s.northEast.lon=o),a>s.northEast.lat&&(s.northEast.lat=a),i&&(i[t][e]=[o,a])}}}else s.southWest.lon=s.southWest.lat=s.northEast.lon=s.northEast.lat=0,i&&(i[0]=0)&&(i[1]=0);return s}setGeometry(t){let i=this._handler;return i&&(this.remove(),this._type=e.getType(t.type||"Point"),this._extent=e.getExtent(t,this._coordinates),i.add(this)),this}setFillColor(e,t,i,s=1){let r=this._style.fillColor;return(0===r.w&&0!==s||0!==r.w&&0===s)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=s,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,s=1){let r=this._style.strokeColor;return(0===r.w&&0!==s||0!==r.w&&0===s)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=s,this._handler&&this._handler.setLineStrokeColorArr(this,r),this}setLineColor(e,t,i,s=1){let r=this._style.lineColor;return(0===r.w&&0!==s||0!==r.w&&0===s)&&(this._pickingReady=!1),r.x=e,r.y=t,r.z=i,r.w=s,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}};ue.__counter__=0;let vr=ue;class qi{constructor(e=0,t=0,i=0){this.a=e,this.b=t,this.c=i}static get(e,t){return new qi(t.y-e.y,e.x-t.x,t.x*e.y-e.x*t.y)}static getParallel(e,t){return new qi(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 H(i,-(e.c+e.a*i)/e.b)}intersects(e){return qi.getIntersection(this,e)}}class Jt{constructor(e,t){this.p0=e||new v,this.p1=t||new v}getMagnitude(){return this.p0.distance(this.p1)}getSphereIntersection(e){let t=this.p0,i=this.p1,s=e.center.x,r=e.center.y,n=e.center.z,o=t.x,a=t.y,l=t.z,h=i.x-o,c=i.y-a,d=i.z-l,_=h*h+c*c+d*d,u=2*(o*h+a*c+l*d-h*s-c*r-d*n),f=u*u-4*_*(o*o-2*o*s+s*s+a*a-2*a*r+r*r+l*l-2*l*n+n*n-e.radius*e.radius);if(f<0)return[];let g=(-u-Math.sqrt(f))/(2*_),p=new v(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*_),y=new v(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,y]:[y,p]}intersects(e,t,i){let s=this.p0.sub(e.p0),r=e.p1.sub(e.p0);if(Math.abs(r.x)<ne&&Math.abs(r.y)<ne&&Math.abs(r.z)<ne)return!1;let n=this.p1.sub(this.p0);if(Math.abs(n.x)<ne&&Math.abs(n.y)<ne&&Math.abs(n.z)<ne)return!1;let o=s.x*r.x+s.y*r.y+s.z*r.z,a=r.x*n.x+r.y*n.y+r.z*n.z,l=s.x*n.x+s.y*n.y+s.z*n.z,h=r.x*r.x+r.y*r.y+r.z*r.z,c=(n.x*n.x+n.y*n.y+n.z*n.z)*h-a*a;if(Math.abs(c)<ne)return!1;let d=(o*a-l*h)/c;if(t.x=this.p0.x+d*n.x,t.y=this.p0.y+d*n.y,t.z=this.p0.z+d*n.z,i){let t=(o+a*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,s=this.p1,r=this.getMagnitude(),n=((e.x-i.x)*(s.x-i.x)+(e.y-i.y)*(s.y-i.y)+(e.z-i.z)*(s.z-i.z))/(r*r);return t.x=i.x+n*(s.x-i.x),t.y=i.y+n*(s.y-i.y),t.z=i.z+n*(s.z-i.z),!(n<0||n>1)}}class vt{constructor(e,t){this.p=e?e.clone():new v,this.n=t?t.clone():this.p.isZero()?v.UP:this.p.getNormal()}setByPoints(e,t,i){let s=v.sub(t,e),r=v.sub(i,e);return this.n=s.cross(r),this.p.copy(e),this}static fromPoints(e,t,i){return(new vt).setByPoints(e,t,i)}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 v.proj_b_to_plane(e,this.n,t)}getProjectionPoint(e,t){let i=e.sub(this.p),s=this.n,r=i.dot(s);return t?t.copy(s.scale(r)):t=s.scale(r),e.sub(t)}getIntersection(e,t,i){let s,r=e.n.cross(t.n),n=r.x>=0?r.x:-r.x,o=r.y>=0?r.y:-r.y,a=r.z>=0?r.z:-r.z;if(n+o+a<xo){let i=t.p.sub(e.p);return 0==e.n.dot(i)?1:0}s=n>o?n>a?1:3:o>a?2:3;let l,h,c=new v;return l=-e.n.dot(e.p),h=-t.n.dot(t.p),1===s?(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===s?(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===s&&(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 V=class e{constructor(e=v.ZERO,t=v.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 v.add(this.origin,this.direction.scaleTo(e))}hitTriangleRes(t,i,s,r){let n=i.sub(t),o=s.sub(t),a=n.cross(o),l=this.origin.sub(t),h=-a.dot(l),c=a.dot(this.direction);if(Math.abs(c)<ne)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 _=n.dot(n),u=n.dot(o),f=o.dot(o),g=r.sub(t),p=g.dot(n),m=g.dot(o),v=u*u-_*f,y=(u*m-f*p)/v;if(y<0||y>1)return e.OUTSIDE;let x=(u*p-_*m)/v;return x<0||y+x>1?e.OUTSIDE:e.INSIDE}hitPlaneRes(t,i){const s=this.direction.dot(t.n);if(Math.abs(s)<ne)return e.OUTSIDE;const r=t.p.sub(this.origin).dot(t.n)/s;return r<0?e.AWAY:(i.copy(this.getPoint(r)),e.INSIDE)}hitSphere(e){const t=v.sub(this.origin,e.center),i=this.direction.dot(this.direction),s=2*t.dot(this.direction),r=s*s-4*i*(t.dot(t)-e.radius*e.radius);if(r<0)return null;const n=Math.sqrt(r);let o=(-s-n)/(2*i);return o<0&&(o=(-s+n)/(2*i)),o<0?null:v.add(this.origin,this.direction.scaleTo(o))}hitBox(e){}};function js(e){let t=e.split("/"),i=t[t.length-1],s=t[t.length-2];return`${s?s+"/":""}${i}`}class Cn{constructor(){this.objPositions=[],this.objTexcoords=[],this.objNormals=[],this.objVertexData=[this.objPositions,this.objTexcoords,this.objNormals],this.vertexData=[[],[],[]],this._materialLibs=[],this.geometries=[],this.geometry=null,this.materials={},this.material={},this.object="default",this.groups=["default"],this._path="",this.keywords={v:e=>{this.objPositions.push(e.map(parseFloat))},vn:e=>{this.objNormals.push(e.map(parseFloat))},vt:e=>{this.objTexcoords.push([parseFloat(e[0]),1-parseFloat(e[1])])},f:e=>{this.setGeometry();const t=e.length-2;for(let i=0;i<t;++i)this.addVertex(e[0]),this.addVertex(e[i+1]),this.addVertex(e[i+2])},s:()=>{},mtllib:(e,t)=>{this._materialLibs.push(t)},usemtl:(e,t)=>{this.newGeometry(),this.setGeometry(),this.geometry&&(this.geometry.material=t)},g:e=>{this.groups=e,this.newGeometry()},o:(e,t)=>{this.object=t,this.newGeometry()},newmtl:(e,t)=>{const i={};this.material=i,this.materials[t]=i},Ns:(e,t)=>{this.material.shininess=parseFloat(t)},Ni:(e,t)=>{},Ka:(e,t)=>{this.material.ambient=e.map((e=>parseFloat(e)))},Kd:(e,t)=>{this.material.diffuse=e.map((e=>parseFloat(e)))},Ks:(e,t)=>{this.material.specular=e.map((e=>parseFloat(e)))},Ke:(e,t)=>{this.material.color=e.map((e=>parseFloat(e)))},illum:(e,t)=>{this.material.illum=parseFloat(t)},d:(e,t)=>{this.material.opacity=parseFloat(t)},Tr:(e,t)=>{this.material.opacity=parseFloat(t)},Tf:(e,t)=>{},map_Ka:(e,t)=>{},map_Kd:(e,t)=>{this.material.colorTexture=`${this._path}/${js(t)}`},map_Bump:(e,t)=>{this.material.normalTexture=`${this._path}/${js(t)}`},map_Ns:(e,t)=>{this.material.metallicRoughnessTexture=`${this._path}/${js(t)}`}}}newGeometry(){this.geometry&&this.geometry.data.vertices.length&&(this.geometry=null)}setGeometry(){if(!this.geometry){const e=[],t=[],i=[];this.vertexData=[e,t,i],this.geometry={object:this.object,groups:this.groups,material:"",data:{vertices:e,texCoords:t,normals:i}},this.geometries.push(this.geometry)}}addVertex(e){let t=e.split("/");for(let e=0;e<t.length;e++){let i=t[e];if(!i)continue;let s=parseInt(i)-1,r=this.vertexData[e],n=r.length,o=this.objVertexData[e][s],a=o.length;this.vertexData[e].length=n+a;for(let e=0;e<a;e++)r[n+e]=o[e]}}_innerParser(e,t){const i=/(\w*)(?: )*(.*)/,s=e.split("\n");for(let e=0;e<s.length;++e){const r=s[e].trim();if(""===r||r.startsWith("#"))continue;const n=i.exec(r);if(!n)continue;const[,o,a]=n,l=r.split(/\s+/).slice(1),h=this.keywords[o];h?h(l,a):console.warn(`Unknown keyword '${o}' in '${t}:${e}'`)}}get data(){return{geometries:this.geometries,materials:this.materials}}async load(e){this._path=e.substring(0,e.lastIndexOf("/"));const t=await fetch(e);if(!t.ok)throw new Error(`Unable to load '${e}'`);const i=t.body.getReader(),s=new TextDecoder;let{value:r,done:n}=await i.read(),o="";for(;!n;){const t=(o+s.decode(r,{stream:!0})).split("\n");o=t.pop();for(const i of t)this._innerParser(i,e);({value:r,done:n}=await i.read())}o&&this._innerParser(o,e),this._cleanupGeometryArrays();let a=this._materialLibs.map((e=>(e=`${this._path}/${e}`,fetch(e).then((e=>e.text())).then((t=>({text:t,filename:e}))))));return await Promise.all(a).then((e=>{e.forEach((e=>this._innerParser(e.text,e.filename)))})),this.data}async _readAndParse(e){const t=e.stream().getReader(),i=new TextDecoder;let{value:s,done:r}=await t.read(),n="";for(;!r;){const o=(n+i.decode(s,{stream:!0})).split("\n");n=o.pop();for(const t of o)this._innerParser(t,e.name);({value:s,done:r}=await t.read())}n&&this._innerParser(n,e.name)}async readFile(e,t){return this._path="",await this._readAndParse(e),this._cleanupGeometryArrays(),t&&await this._readAndParse(t),this.data}_cleanupGeometryArrays(){for(const e of this.geometries)e.data=Object.fromEntries(Object.entries(e.data).filter((([e,t])=>t.length>0)))}}function Ie(e){let t=new Float32Array([1,1,1]);if(e instanceof Array)t[0]=e[0],t[1]=e[1],t[2]=e[2];else if("string"==typeof e){let i=ve(e);t[0]=i[0],t[1]=i[1],t[2]=i[2]}return t}class ${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),this.color=(t=e.color)instanceof Array?new Float32Array(t):"string"==typeof t?ve(t):new Float32Array([.5,.5,.5,1]),this.ambient=Ie(e.ambient),this.diffuse=Ie(e.diffuse),this.specular=Ie(e.specular),this.shininess=e.shininess||100,this.colorTextureSrc=e.colorTextureSrc||null,this.colorTextureImage=e.colorTextureImage||null,this.normalTextureSrc=e.normalTextureSrc||null,this.normalTextureImage=e.normalTextureImage||null,this.metallicRoughnessTextureSrc=e.metallicRoughnessTextureSrc||null,this.metallicRoughnessTextureImage=e.metallicRoughnessTextureImage||null,e.scale){let t,i=e.scale;t="number"==typeof i?new v(i,i,i):i,$.scale(this._vertices,t)}if(e.center&&$.centering(this._vertices),this.center=$.getCenter(this._vertices),e.indices)this._indices=e.indices,this._normals=e.normals||[];else{this._normals=e.normals||$.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 getCenter(e){let t=xt,i=xt,s=xt,r=Ct,n=Ct,o=Ct;for(let a=0,l=e.length;a<l;a+=3){let l=e[a],h=e[a+1],c=e[a+2];l<t&&(t=l),h<i&&(i=h),c<s&&(s=c),l>r&&(r=l),h>n&&(n=h),c>o&&(o=c)}return new v(t+.5*(r-t),i+.5*(n-i),s+.5*(o-s))}static centering(e){let t=$.getCenter(e);for(let i=0,s=e.length;i<s;i+=3)e[i]-=t.x,e[i+1]-=t.y,e[i+2]-=t.z}setMaterial(e){return e.ambient&&(this.ambient=Ie(e.ambient)),e.diffuse&&(this.diffuse=Ie(e.diffuse)),e.specular&&(this.specular=Ie(e.specular)),void 0!==e.shininess&&(this.shininess=e.shininess),this}centering(){return $.centering(this._vertices),this}applyMat4(e){for(let t=0,i=this._vertices.length;t<i;t+=3){let i=new v(this._vertices[t],this._vertices[t+1],this._vertices[t+2]),s=new v(this._normals[t],this._normals[t+1],this._normals[t+2]);i=e.mulVec3(i),s=e.mulVec3(s),this._vertices[t]=i.x,this._vertices[t+1]=i.y,this._vertices[t+2]=i.z,this._normals[t]=s.x,this._normals[t+1]=s.y,this._normals[t+2]=s.z}return this}scale(e){return $.scale(this._vertices,e),this}translate(e){for(let t=0,i=this._vertices.length;t<i;t+=3)this._vertices[t]+=e.x,this._vertices[t+1]+=e.y,this._vertices[t+2]+=e.z;return this}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+=3)e[i]*=t.x,e[i+1]*=t.y,e[i+2]*=t.z}static centroid(e){let t=1e3,i=1e3,s=1e3,r=-1e3,n=-1e3,o=-1e3;for(let a=0;a<e.length;a+=3){let l=e[a],h=e[a+1],c=e[a+2];l<t&&(t=l),h<i&&(i=h),c<s&&(s=c),l>r&&(r=l),h>n&&(n=h),c>o&&(o=c)}return[t+.5*(r-t),i+.5*(n-i),s+.5*(o-s)]}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 s=i,r=i+3,n=i+6,o=e[s],a=e[s+1],l=e[s+2],h=e[r]-o,c=e[r+1]-a,d=e[r+2]-l,_=e[n]-o,u=e[n+1]-a,f=e[n+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[s]=g,t[s+1]=p,t[s+2]=m,t[r]=g,t[r+1]=p,t[r+2]=m,t[n]=g,t[n+1]=p,t[n+2]=m}return t}static createSphere(e=16,t=16,i=1,s=0,r=0,n=0){let o=[],a=[],l=[];for(let a=0;a<=t;a++){let h=a*Math.PI/t,c=Math.sin(h),d=Math.cos(h);for(let t=0;t<=e;t++){let a=2*t*Math.PI/e,h=Math.sin(a),_=Math.cos(a)*c+s,u=d+r,f=h*c+n;l.push(_),l.push(u),l.push(f),o.push(i*_),o.push(i*u),o.push(i*f)}}for(let i=0;i<t;i++)for(let t=0;t<e;t++){let s=i*(e+1)+t,r=s+e+1;a.push(s),a.push(s+1),a.push(r),a.push(r),a.push(s+1),a.push(r+1)}return new $({vertices:o,normals:l,indices:a})}static createDisc(e=1,t=0,i=8,s=!0,r=0,n=0,o=0,a=0){let l=[],h=[],c=[],d=2*Math.PI,_=s?1:-1,u=r;for(let e=1;e<=i;e++)l.push(n,t*_+o,a),c.push(0,_,0),r++;let f=r;for(let s=0;s<=i;s++){let h=s/i*d+0,u=Math.cos(h),f=Math.sin(h);l.push(e*f+n,t*_+o,e*u+a),c.push(0,_,0),r++}for(let e=0;e<i;e++){let t=u+e,i=f+e;s?h.push(i,i+1,t):h.push(i+1,i,t)}return new $({vertices:l,normals:c,indices:h})}static getFrustumScaleByCameraAngles(e,t,i){return new v(2*e*Math.tan(Qt*t),2*e*Math.tan(Qt*i),e)}static getFrustumScaleByCameraAspectRatio(e,t,i){let s=Gr*Math.atan(Math.tan(Qt*t)/i);return $.getFrustumScaleByCameraAngles(e,t,s)}static createFrustum(e=1,t=1,i=1,s=0,r=0,n=0){return new $({vertices:[0+s,0+r,0+n,-1*(t*=.5)+s,1*(i*=.5)+r,-1*e+n,1*t+s,1*i+r,-1*e+n,0+s,0+r,0+n,1*t+s,-1*i+r,-1*e+n,-1*t+s,-1*i+r,-1*e+n,0+s,0+r,0+n,1*t+s,1*i+r,-1*e+n,1*t+s,-1*i+r,-1*e+n,0+s,0+r,0+n,-1*t+s,-1*i+r,-1*e+n,-1*t+s,1*i+r,-1*e+n,0+s,0+r,0+n,1*t+s,1*i+r,-1*e+n,-1*t+s,1*i+r,-1*e+n,0+s,0+r,0+n,-1*t+s,-1*i+r,-1*e+n,1*t+s,-1*i+r,-1*e+n,0+s,0+r,0+n,1*t+s,-1*i+r,-1*e+n,1*t+s,1*i+r,-1*e+n,0+s,0+r,0+n,-1*t+s,1*i+r,-1*e+n,-1*t+s,-1*i+r,-1*e+n]})}static createCylinder(e=1,t=1,i=1,s=32,r=1,n=!0,o=!0,a=0,l=0,h=0){let c=[],d=[],_=[],u=2*Math.PI,f=0,g=[],p=new v,m=(t-e)/i;for(let n=0;n<=r;n++){let o=[],d=n/r,v=d*(t-e)+e;for(let e=0;e<=s;e++){let t=e/s*u+0,r=Math.sin(t),n=Math.cos(t);c.push(v*r+a,-d*i+i+l,v*n+h),p.set(r,m,n).normalize(),_.push(p.x,p.y,p.z),o.push(f++)}g.push(o)}for(let e=0;e<s;e++)for(let t=0;t<r;t++){let i=g[t][e],s=g[t+1][e],r=g[t+1][e+1],n=g[t][e+1];d.push(i,s,n),d.push(s,r,n)}if(0!==e&&n){let t=$.createDisc(e,i,s,!0,f,a,l,h);c.push(...t.vertices),_.push(...t.normals),d.push(...t.indices)}if(0!==t&&o){let e=$.createDisc(t,0,s,!1,f+(n?1+2*s:0),a,l,h);c.push(...e.vertices),_.push(...e.normals),d.push(...e.indices)}return new $({vertices:c,normals:_,indices:d})}static createCube(e=1,t=1,i=1,s=0,r=0,n=0){let o=.5*e+s,a=.5*t+r,l=.5*i+n;return new $({vertices:[-o,-a,l,o,-a,-l,o,-a,l,-o,-a,l,-o,-a,-l,o,-a,-l,-o,a,l,o,a,l,o,a,-l,-o,a,l,o,a,-l,-o,a,-l,-o,-a,l,o,-a,l,-o,a,l,-o,a,l,o,-a,l,o,a,l,-o,-a,-l,-o,a,-l,o,-a,-l,-o,a,-l,o,a,-l,o,-a,-l,o,-a,l,o,-a,-l,o,a,l,o,a,l,o,-a,-l,o,a,-l,-o,-a,l,-o,a,l,-o,-a,-l,-o,a,l,-o,a,-l,-o,-a,-l]})}static createPlane(e=1,t=1,i=0,s=0,r=0){let n=.5*e,o=.5*t;return new $({vertices:[-n+i,s,o+r,n+i,s,-o+r,n+i,s,o+r,-n+i,s,o+r,-n+i,s,-o+r,n+i,s,-o+r,-n+i,s,o+r,n+i,s,o+r,n+i,s,-o+r,-n+i,s,o+r,n+i,s,-o+r,-n+i,s,-o+r]})}static createArrow(e=0,t=2.1,i=-15){return new $({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 readFileObj(e,t,i){const s=await(new Cn).readFile(e,t);let r=s.materials;return s.geometries.map((e=>{let t=r[e.material]||{};return new $({name:e.object,vertices:e.data.vertices,normals:e.data.normals,texCoords:e.data.texCoords,ambient:t.ambient,diffuse:t.diffuse,specular:t.specular,shininess:t.shininess,color:t.color,colorTextureSrc:i?`${i}/${t.colorTexture}`:t.colorTexture,normalTextureSrc:i?`${i}/${t.normalTexture}`:t.normalTexture,metallicRoughnessTextureSrc:i?`${i}/${t.metallicRoughnessTexture}`:t.metallicRoughnessTexture})}))}static async loadObj(e){const t=await(new Cn).load(e);let i=t.materials;return t.geometries.map((e=>{let t=i[e.material]||{};return new $({name:e.object,vertices:e.data.vertices,normals:e.data.normals,texCoords:e.data.texCoords,ambient:t.ambient,diffuse:t.diffuse,specular:t.specular,shininess:t.shininess,color:t.color,colorTextureSrc:t.colorTexture,normalTextureSrc:t.normalTexture,metallicRoughnessTextureSrc:t.metallicRoughnessTexture})}))}merge(e){const t=this._vertices.length/3;let i=this._vertices.length;this._vertices.length=i+e._vertices.length;for(let t=0;t<e._vertices.length;t++)this._vertices[i+t]=e._vertices[t];i=this._normals.length,this._normals.length=i+e._normals.length;for(let t=0;t<e._normals.length;t++)this._normals[i+t]=e._normals[t];i=this._texCoords.length,this._texCoords.length=i+e._texCoords.length;for(let t=0;t<e._texCoords.length;t++)this._texCoords[i+t]=e._texCoords[t];i=this._indices.length,this._indices.length=i+e._indices.length;for(let s=0;s<e._indices.length;s++)this._indices[i+s]=e._indices[s]+t;return this._numVertices=this._vertices.length/3,this}static merge(e,t){let i=new $,s=t||e.length;for(let t=0;t<s;t++)i.merge(e[t]);return i}}const tl=new v(0,0,-1),gs=class e{constructor(t){var i,s;this._handlerIndex=-1,this._tag=t.tag||"tag_"+e.__counter__++,this._entity=null,this._position=Yt(t.position),this._rtcPositionHigh=new v,this._rtcPositionLow=new v,this._scale=Yt(t.scale,new v(1,1,1)),this._translate=Yt(t.translate,new v),this._localPosition=new v;const[r=.15,n=.15,o=.15,a=1]=null!=(i=t.object3d)&&i.color?Array.from(t.object3d.color):[];this._color=le(t.color,new et(r,n,o,a)),this._handler=null,this._handlerIndex=-1,this._tagData=null,this._tagDataIndex=-1;let l=t.object3d;t.object3d&&0!==(null==(s=t.object3d)?void 0:s.vertices.length)||(l=new $),t.objSrc&&(this.setObjectSrc(t.objSrc),this._objectSrc=t.objSrc),this._object3d=l,this._visibility=null==t.visibility||t.visibility,this._children=[],this._direction=new v,this._qFrame=new F,this._qRot=F.IDENTITY}get tag(){return this._tag}getPosition(){return this._position}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)}getOpacity(){return this._color.w}setColor(e,t,i,s){this._color.x=e,this._color.y=t,this._color.z=i,null!=s&&(this._color.w=s),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,this.updateRTCPosition(),this.updateRotation()}updateRTCPosition(){this._handler&&(this._handler.getRTCPosition(this._position,this._rtcPositionHigh,this._rtcPositionLow),this._handler.setRTCPositionArr(this._tagData,this._tagDataIndex,this._rtcPositionHigh,this._rtcPositionLow))}setPosition3v(e){this.setPosition(e.x,e.y,e.z)}setObject(e){this._object3d=e}setObjectSrc(e){this._objectSrc=e,this._handler&&this._handler.setObjectSrc(e,this.tag)}setColorHTML(e){this.setColor4v(he(e))}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}setTranslate3v(e){this._translate.copy(e),this._handler&&this._handler.setTranslateArr(this._tagData,this._tagDataIndex,e)}getTranslate(){return this._translate.clone()}setLocalPosition3v(e){this._localPosition.copy(e),this._handler&&this._handler.setLocalPositionArr(this._tagData,this._tagDataIndex,e)}getLocalPosition(){return this._localPosition.clone()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._tagData,this._tagDataIndex,e)}setRotation(e){this._qRot.copy(e),this._qRot.mulVec3Res(tl,this._direction).normalize(),this.updateRotation()}getRotation(){return this._qRot}updateRotation(){this._handler&&this._handler.setQRotArr(this._tagData,this._tagDataIndex,this._qRot)}getDirection(){return this._direction.clone()}};gs.__counter__=0;let yr=gs;const _i={RIGHT:0,LEFT:1,CENTER:2},En={left:_i.LEFT,right:_i.RIGHT,center:_i.CENTER};class el extends rs{constructor(e={}){super(e),this._handler=null,this._text=e.text||"",this._face=Bo(e.face,"arial"),this._size=e.size||24,this._outline=null!=e.outline?e.outline:0,this._outlineColor=le(e.outlineColor,new et(0,0,0,1)),this._align=e.align&&En[e.align.trim().toLowerCase()]||_i.RIGHT,this._fontIndex=0,this._fontAtlas=null,this._isRTL=e.isRTL||!1,this._letterSpacing=e.letterSpacing||0}setText(e){this._text=e.toString(),this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,e,this._fontIndex,this._align,this._letterSpacing,this._isRTL)}setLetterSpacing(e){this._letterSpacing=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,e,this._isRTL)}getLetterSpacing(){return this._letterSpacing}setRtl(e){this._isRTL=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL)}getText(){return this._text}setAlign(e){this._align=En[e.trim().toLowerCase()],this._isReady&&this._handler?this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL):-1!==this._lockId&&(this._lockId=-2)}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):-1!==this._lockId&&(this._lockId=-2))}getSize(){return this._size}setOutline(e){this._outline=e,this._isReady&&this._handler?this._handler.setOutlineArr(this._handlerIndex,e):-1!==this._lockId&&(this._lockId=-2)}getOutline(){return this._outline}setOpacity(e){super.setOpacity(e),this.setOutlineOpacity(e)}setOutlineColor(e,t,i,s){s===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=s,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):-1!==this._lockId&&(this._lockId=-2))}setOutlineColor4v(e){this.setOutlineColor(e.x,e.y,e.z,e.w)}setOutlineColorHTML(e){this.setOutlineColor4v(he(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):-1!==this._lockId&&(this._lockId=-2))}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._letterSpacing,this._isRTL)):-1!==this._lockId&&(this._lockId=-2)}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}}const ps=class e{constructor(t={}){this.__id=e.__counter__++,this.visibility=null==t.visibility||t.visibility,this.pointSize=t.pointSize||3,this.pickingScale=t.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),t.points&&this.setPoints(t.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],s=new v(i[0],i[1],i[2]),r=new et(i[3],i[4],i[5],null==i[6]?255:i[6]);this._coordinatesData.push(s.x,s.y,s.z),this._colorData.push(r.x/255,r.y/255,r.z/255,r.w/255);let n={_entity:this._entity,_pickingColor:new v,_entityCollection:this._entity?this._entity._entityCollection:null,index:t,position:s,color:r,pointCloud:this,properties:i[7]||{}};this._points.push(n),this._renderNode&&this._renderNode.renderer&&(this._renderNode.renderer.assignPickingColor(n),this._pickingColorData.push(n._pickingColor.x/255,n._pickingColor.y/255,n._pickingColor.z/255,1))}this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}setPointPosition(e,t,i,s){this._changedBuffers[0]=!0}setPointColor(e,t,i,s,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,s=e.handler.gl,r=i.attributes,n=i.uniforms;t.activate(),s.uniformMatrix4fv(n.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),s.uniform1f(n.opacity,this._handler._entityCollection._fadingOpacity),s.uniform1f(n.pointSize,this.pointSize),s.bindBuffer(s.ARRAY_BUFFER,this._coordinatesBuffer),s.vertexAttribPointer(r.coordinates,this._coordinatesBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._colorBuffer),s.vertexAttribPointer(r.colors,this._colorBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.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,s=e.handler.gl,r=i.attributes,n=i.uniforms;t.activate(),s.uniformMatrix4fv(n.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),s.uniform1f(n.opacity,this._handler._entityCollection._fadingOpacity),s.uniform1f(n.pointSize,this.pointSize+this.pickingScale),s.bindBuffer(s.ARRAY_BUFFER,this._coordinatesBuffer),s.vertexAttribPointer(r.coordinates,this._coordinatesBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._pickingColorBuffer),s.vertexAttribPointer(r.colors,this._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.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}}};ps.__counter__=0;let xr=ps;const qe=class e{constructor(t={}){this.__id=e.__counter__++,this.__doubleToTwoFloats=v.doubleToTwoFloats,this.altitude=t.altitude||0,this.thickness=t.thickness||1.5,this._opacity=null!=t.opacity?t.opacity:1,this._defaultColor=ve(t.color||"#0000FF",t.opacity),this.visibility=null==t.visibility||t.visibility,this._closedLine=t.isClosed||!1,this._path3v=[],this._pathLengths=[],this._pathLonLat=[],this._pathLonLatMerc=[],this._pathColors=t.pathColors?Qr(t.pathColors):[],this._extent=new U,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._texCoordArr=[],this._atlasTexCoords=[],this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null,this._texCoordBuffer=null,this._pickingColor=[0,0,0],this._renderNode=null,this._entity=null,this._handler=null,this._handlerIndex=-1,this._image=t.image||null,this._src=t.src||null,this._texOffset=t.texOffset||0,this._strokeSize=null!=t.strokeSize?t.strokeSize:32,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createVerticesBuffer,this._buffersUpdateCallbacks[1]=this._createIndexBuffer,this._buffersUpdateCallbacks[2]=this._createColorsBuffer,this._buffersUpdateCallbacks[3]=this._createTexCoordBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length);let i=Yt(t.visibleSpherePosition).toArray(),s=t.visibleSphereRadius||0;this._visibleSphere=new Float32Array([...i,s]),t.pathLonLat?this.setPathLonLat(t.pathLonLat):t.path3v&&this.setPath3v(t.path3v),this._refresh()}get texOffset(){return this._texOffset}set texOffset(e){this._texOffset=e}get strokeSize(){return this._strokeSize}set strokeSize(e){this._strokeSize=e}setSrc(e){this._src=e;let t=this._handler;if(t){let i=t._entityCollection.renderNode;if(i&&i.renderer){let t=i.renderer.strokeTextureAtlas;e&&e.length?t.loadImage(e,(e=>{if(null!=e.__nodeIndex&&t.get(e.__nodeIndex)){this._image=e;let i=t.get(e.__nodeIndex);this._setTexCoordArr(i.texCoords)}else t.addImage(e),t.createTexture(),this._image=e,i.updateStrokeTexCoords()})):(this.setTextureDisabled(),i.updateStrokeTexCoords())}}}getSrc(){return this._src}setImage(e){this.setSrc(e.src)}getImage(){return this._image}_setTexCoordArr(t){this._texCoordArr=[],this._atlasTexCoords=t,e.setPathTexCoords(this._path3v,t,this._texCoordArr),this._changedBuffers[3]=!0}setTextureDisabled(){this._strokeSize=0}__appendLineData3v(e,t,i,s,r,n,o,a,l,h,c,d,_,u){var f=0,g=new v,p=new v;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),a.length>0?(f=a[a.length-5]+9,a.push(f,f)):a.push(0,0);for(let L=0,P=e.length;L<P;L++){var m=e[L],y=t[L];if(h[L]=[],d[L]=[],c[L]=[],0===m.length)continue;var x,b=f;if(s)(x=m[m.length-1])instanceof Array&&(x=new v(x[0],x[1],x[2]));else{var w=m[0],T=m[1]||w;w instanceof Array&&(w=new v(w[0],w[1],w[2])),T instanceof Array&&(T=new v(T[0],T[1],T[2])),x=new v(w.x+w.x-T.x,w.y+w.y-T.y,w.z+w.z-T.z)}let P=i;y&&y[0]&&(P=y[0]),this.__doubleToTwoFloats(x,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),n.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 S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1;L>0&&u.push(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.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 v(C[0],C[1],C[2])),c[L].push(C),l){var E=l.cartesianToLonLat(C);h[L].push(E),d[L].push(E.forwardMercator()),E.lon<_.southWest.lon&&(_.southWest.lon=E.lon),E.lat<_.southWest.lat&&(_.southWest.lat=E.lat),E.lon>_.northEast.lon&&(_.northEast.lon=E.lon),E.lat>_.northEast.lat&&(_.northEast.lat=E.lat)}y&&y[e]&&(P=y[e]),S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1,this.__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),n.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(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),a.push(f++,f++,f++,f++)}var A;if(s)(A=m[0])instanceof Array&&(A=new v(A[0],A[1],A[2])),a.push(b,b+1,b+1,b+1);else{let e=m[m.length-1],t=m[m.length-2]||e;e instanceof Array&&(e=new v(e[0],e[1],e[2])),t instanceof Array&&(t=new v(t[0],t[1],t[2])),A=new v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),a.push(f-1,f-1,f-1,f-1)}y&&y[m.length-1]&&(P=y[m.length-1]),S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1,this.__doubleToTwoFloats(A,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),n.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(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),L<e.length-1&&0!==e[L+1].length&&(f+=8,a.push(f,f))}}__appendPoint3v(e,t,i,s,r,n,o,a,l,h,c,d,_,u){var f=new v,g=new v,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 y=e[e.length-1],x=y.length;y.push(t);let b=s[0],w=s[1],T=s[2],C=null!=s[3]?s[3]:1,E=i[e.length-1];if(E[x]?(E[x][0]=b,E[x][1]=w,E[x][2]=T,E[x][3]=C):E.push(s),1===x){var A;if(r)(A=y[x-1])instanceof Array&&(A=new v(A[0],A[1],A[2]));else{let e=y[0],t=y[1]||e;e instanceof Array&&(e=new v(e[0],e[1],e[2])),t instanceof Array&&(t=new v(t[0],t[1],t[2])),A=new v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(A,f,g);let e=n.length-36;n[e]=f.x,n[e+1]=f.y,n[e+2]=f.z,n[e+3]=f.x,n[e+4]=f.y,n[e+5]=f.z,n[e+6]=f.x,n[e+7]=f.y,n[e+8]=f.z,n[e+9]=f.x,n[e+10]=f.y,n[e+11]=f.z,o[e]=g.x,o[e+1]=g.y,o[e+2]=g.z,o[e+3]=g.x,o[e+4]=g.y,o[e+5]=g.z,o[e+6]=g.x,o[e+7]=g.y,o[e+8]=g.z,o[e+9]=g.x,o[e+10]=g.y,o[e+11]=g.z}var L=m;if(c){0===d.length&&d.push([]),0===_.length&&_.push([]);var P=d[d.length-1],S=_[_.length-1];let e=c.cartesianToLonLat(t);P.push(e),S.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)}this.__doubleToTwoFloats(t,f,g);let R=n.length-12;n[R]=f.x,n[R+1]=f.y,n[R+2]=f.z,n[R+3]=f.x,n[R+4]=f.y,n[R+5]=f.z,n[R+6]=f.x,n[R+7]=f.y,n[R+8]=f.z,n[R+9]=f.x,n[R+10]=f.y,n[R+11]=f.z,o[R]=g.x,o[R+1]=g.y,o[R+2]=g.z,o[R+3]=g.x,o[R+4]=g.y,o[R+5]=g.z,o[R+6]=g.x,o[R+7]=g.y,o[R+8]=g.z,o[R+9]=g.x,o[R+10]=g.y,o[R+11]=g.z;let M=a.length-16;var B;if(a[M]=b,a[M+1]=w,a[M+2]=T,a[M+3]=C,a[M+4]=b,a[M+5]=w,a[M+6]=T,a[M+7]=C,a[M+8]=b,a[M+9]=w,a[M+10]=T,a[M+11]=C,a[M+12]=b,a[M+13]=w,a[M+14]=T,a[M+15]=C,h[p]=m++,h[p+1]=m++,h[p+2]=m++,h[p+3]=m++,r)B=y[0],h.push(L,L+1,L+1,L+1);else{let e=y[y.length-1],t=y[y.length-2]||e;B=new v(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)}this.__doubleToTwoFloats(B,f,g),n.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),o.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),a.push(b,w,T,C,b,w,T,C,b,w,T,C,b,w,T,C),l.push(1,-1,2,-2)}static setPathTexCoords(e,t,i){let s=t[1],r=t[3]-s,n=new H(t[4],t[5]),o=new H(t[2],t[3]),a=new H(t[8],t[9]),l=new H(t[0],t[1]);for(let t=0,c=e.length;t<c;t++){var h=e[t];if(0!==h.length){t>0&&i.push(n.x,n.y,s,r,o.x,o.y,s,r,a.x,a.y,s,r,l.x,l.y,s,r);for(let e=0,t=h.length;e<t;e++)i.push(n.x,n.y,s,r,o.x,o.y,s,r,a.x,a.y,s,r,l.x,l.y,s,r);i.push(n.x,n.y,s,r,o.x,o.y,s,r,a.x,a.y,s,r,l.x,l.y,s,r)}}}static setPathColors(e,t,i,s){for(let o=0,a=e.length;o<a;o++){var r=e[o],n=t[o];if(0===r.length)continue;let a=i;n&&n[0]&&(a=n[0]);let l=a[0],h=a[1],c=a[2],d=null!=a[3]?a[3]:1;o>0&&s.push(l,h,c,d,l,h,c,d,l,h,c,d,l,h,c,d);for(let e=0,t=r.length;e<t;e++)n&&n[e]&&(a=n[e]),l=a[0],h=a[1],c=a[2],d=null!=a[3]?a[3]:1,s.push(l,h,c,d,l,h,c,d,l,h,c,d,l,h,c,d);n&&n[r.length-1]&&(a=n[r.length-1]),l=a[0],h=a[1],c=a[2],d=null!=a[3]?a[3]:1,s.push(l,h,c,d,l,h,c,d,l,h,c,d,l,h,c,d)}}__appendLineDataLonLat(e,t,i,s,r,n,o,a,l,h,c,d,_,u,f){var g=0,p=new v,m=new v;u&&(u.southWest.set(180,90),u.northEast.set(-180,-90)),a.length>0?(g=a[a.length-5]+9,a.push(g)):a.push(0);for(let A=0,P=e.length;A<P;A++){var y=e[A],x=t[A];if(c[A]=[],_[A]=[],d[A]=[],0===y.length)continue;var b,w=g;if(s){let e=y[y.length-1];b=e instanceof Array?h.lonLatToCartesian(new L(e[0],e[1],e[2])):h.lonLatToCartesian(e)}else{let e,t,i=y[0];e=i instanceof Array?h.lonLatToCartesian(new L(i[0],i[1],i[2])):h.lonLatToCartesian(i),i=y[1],i||(i=y[0]),t=i instanceof Array?h.lonLatToCartesian(new L(i[0],i[1],i[2])):h.lonLatToCartesian(i),b=new v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}let P=i;x&&x[0]&&(P=x[0]),this.__doubleToTwoFloats(b,p,m),r.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),n.push(m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z);let S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1;A>0&&f.push(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),l.push(0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0);for(let e=0,t=y.length;e<t;e++){var T=y[e];T instanceof Array&&(T=new L(T[0],T[1],T[2])),x&&x[e]&&(P=x[e]),S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1;var C=h.lonLatToCartesian(T);c[A].push(C),d[A].push(T),_[A].push(T.forwardMercator()),this.__doubleToTwoFloats(C,p,m),r.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),n.push(m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z),f.push(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),a.push(g++,g++,g++,g++),l.push(0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0),T.lon<u.southWest.lon&&(u.southWest.lon=T.lon),T.lat<u.southWest.lat&&(u.southWest.lat=T.lat),T.lon>u.northEast.lon&&(u.northEast.lon=T.lon),T.lat>u.northEast.lat&&(u.northEast.lat=T.lat)}var E;if(s){let e=y[0];E=e instanceof Array?h.lonLatToCartesian(new L(e[0],e[1],e[2])):h.lonLatToCartesian(e),a.push(w,w+1,w+1,w+1)}else{let e,t,i=y[y.length-1];e=i instanceof Array?h.lonLatToCartesian(new L(i[0],i[1],i[2])):h.lonLatToCartesian(i),i=y[y.length-2],i||(i=y[0]),t=i instanceof Array?h.lonLatToCartesian(new L(i[0],i[1],i[2])):h.lonLatToCartesian(i),E=new v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),a.push(g-1,g-1,g-1,g-1)}x&&x[y.length-1]&&(P=x[y.length-1]),S=P[0],R=P[1],M=P[2],B=null!=P[3]?P[3]:1,this.__doubleToTwoFloats(E,p,m),r.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),n.push(m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z,m.x,m.y,m.z),f.push(S,R,M,B,S,R,M,B,S,R,M,B,S,R,M,B),o.push(1,-1,2,-2),l.push(0,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0),A<e.length-1&&0!==e[A+1].length&&(g+=8,a.push(g,g))}}_setEqualPath3v(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new v,s=new v,r=this._verticesHigh,n=this._verticesLow,o=this._pathLonLat,a=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 v(_[0].x+_[0].x-_[1].x,_[0].y+_[0].y-_[1].y,_[0].z+_[0].z-_[1].z),this.__doubleToTwoFloats(c,i,s),r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.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,o[m][e]=g,a[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)}this.__doubleToTwoFloats(u,i,s),r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z}if(this._closedLine)d=_[0];else{var p=_.length-1;d=new v(_[p].x+_[p].x-_[p-1].x,_[p].y+_[p].y-_[p-1].y,_[p].z+_[p].z-_[p-1].z)}this.__doubleToTwoFloats(d,i,s),r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z,r[l]=i.x,n[l++]=s.x,r[l]=i.y,n[l++]=s.y,r[l]=i.z,n[l++]=s.z}}_setEqualPathLonLat(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new v,s=new v,r=this._verticesHigh,n=this._verticesLow,o=this._pathLonLat,a=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 v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(d,i,s),r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z;for(let e=0;e<u.length;e++){var f=u[e],g=c.lonLatToCartesian(f);l[p][e]=g,a[p][e]=f.forwardMercator(),o[p][e]=f,this.__doubleToTwoFloats(g,i,s),r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.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 v(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(_,i,s),r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z,r[h]=i.x,n[h++]=s.x,r[h]=i.y,n[h++]=s.y,r[h]=i.z,n[h++]=s.z}}setPointLonLat(e,t,i){if(this._renderNode&&this._renderNode.ellipsoid){let a=this._pathLonLat,l=this._pathLonLatMerc;a[i][t]=e,l[i][t]=e.forwardMercator();var s=this._extent;s.southWest.set(180,90),s.northEast.set(-180,-90);for(let e=0;e<a.length;e++){var r=a[e];for(let e=0;e<r.length;e++){var n=r[e].lon,o=r[e].lat;n>s.northEast.lon&&(s.northEast.lon=n),o>s.northEast.lat&&(s.northEast.lat=o),n<s.southWest.lon&&(s.southWest.lon=n),o<s.southWest.lat&&(s.southWest.lat=o)}}this.setPoint3v(this._renderNode.ellipsoid.lonLatToCartesian(e),t,i,!0)}else{let s=this._pathLonLat[i];s[t].lon=e.lon,s[t].lat=e.lat,s[t].height=e.height}}setPoint3v(e,t=0,i=0,s=!1){if(this._renderNode){var r,n=new v,o=new v,a=this._verticesHigh,l=this._verticesLow,h=this._pathLonLat,c=this._pathLonLatMerc,d=0;r=12*this._pathLengths[i]+24*i;let b=this._path3v[i];b[t].x=e.x,b[t].y=e.y,b[t].z=e.z;let w=this._closedLine||1===b.length;var _;if((0===t||1===t)&&(_=w?b[b.length-1]:new v(b[0].x+b[0].x-b[1].x,b[0].y+b[0].y-b[1].y,b[0].z+b[0].z-b[1].z),d=r,this.__doubleToTwoFloats(_,n,o),a[d]=n.x,a[d+1]=n.y,a[d+2]=n.z,a[d+3]=n.x,a[d+4]=n.y,a[d+5]=n.z,a[d+6]=n.x,a[d+7]=n.y,a[d+8]=n.z,a[d+9]=n.x,a[d+10]=n.y,a[d+11]=n.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z),!s&&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,this.__doubleToTwoFloats(e,n,o),a[d]=n.x,a[d+1]=n.y,a[d+2]=n.z,a[d+3]=n.x,a[d+4]=n.y,a[d+5]=n.z,a[d+6]=n.x,a[d+7]=n.y,a[d+8]=n.z,a[d+9]=n.x,a[d+10]=n.y,a[d+11]=n.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z,t===b.length-1||t===b.length-2){var y;if(w)y=b[0];else{var x=b.length-1;y=new v(b[x].x+b[x].x-b[x-1].x,b[x].y+b[x].y-b[x-1].y,b[x].z+b[x].z-b[x-1].z)}d=r+12*b.length+12,this.__doubleToTwoFloats(y,n,o),a[d]=n.x,a[d+1]=n.y,a[d+2]=n.z,a[d+3]=n.x,a[d+4]=n.y,a[d+5]=n.z,a[d+6]=n.x,a[d+7]=n.y,a[d+8]=n.z,a[d+9]=n.x,a[d+10]=n.y,a[d+11]=n.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z}this._changedBuffers[0]=!0}else{let s=this._path3v[i];s[t].x=e.x,s[t].y=e.y,s[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,s=0){let r=[].concat(this._path3v),n=r[s];if(n){let o=[].concat(this._pathColors);if(n.splice(t,0,e),i){let e=o[s];e||(e=new Array(n.length)),e.splice(t,0,i)}this.setPath3v(r,o)}else this.addPoint3v(e,s)}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),this.__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 s=this._pathColors[i];if(!s){if(!(this._path3v[i]&&t<this._path3v[i].length))return;this._pathColors[i]=new Array(this._path3v[i].length)}s[t]?(s[t][0]=e[0],s[t][1]=e[1],s[t][2]=e[2],s[t][3]=e[3]||1):s[t]=[e[0],e[1],e[2],e[3]||1];let r=this._colors,n=16*t+16*this._pathLengths[i]+32*i;r[n]=r[n+4]=r[n+8]=r[n+12]=e[0],r[n+1]=r[n+5]=r[n+9]=r[n+13]=e[1],r[n+2]=r[n+6]=r[n+10]=r[n+14]=e[2],r[n+3]=r[n+7]=r[n+11]=r[n+15]=e[3]||1,this._changedBuffers[2]=!0}else this._pathColors[i][t]=e}setOpacity(e){this._opacity=e}getOpacity(){return this._opacity}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._texCoordArr=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._texCoordArr=[],this._path3v.length=0,this._pathLonLat.length=0,this._pathLonLatMerc.length=0,this._path3v=[],this._pathLonLat=[],this._pathLonLatMerc=[]}_createData3v(e){this._clearData(),this.__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(),this.__appendLineDataLonLat(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._texCoordArr,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._texCoordArr=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._texCoordArr=[],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(t){t&&(this._colors=[],this._pathColors=[].concat(t),e.setPathColors(this._pathLonLat,t,this._defaultColor,this._colors),this._changedBuffers[2]=!0)}setColorHTML(e){this._defaultColor=ve(e);let t=he(e),i=this._pathColors;for(let e=0,s=i.length;e<s;e++){let s=i[e];for(let e=0,i=s.length;e<i;e++)s[e][0]=t.x,s[e][1]=t.y,s[e][2]=t.z,s[e][3]=t.w}let s=this._colors;for(let e=0,i=s.length;e<i;e+=4)s[e]=t.x,s[e+1]=t.y,s[e+2]=t.z,s[e+3]=t.w;this._changedBuffers[2]=!0}setPathLonLatFast(e,t){this.setPathLonLat(e,t,!0)}setPath3vFast(e,t){this.setPath3v(e,t,!0)}setPathLonLat(e,t,i=!1){t&&(this._pathColors=[].concat(t)),this._renderNode&&this._renderNode.ellipsoid?i?(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)}getSize(e=0){return this._path3v[e].length}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.renderer,t=e.handler.programs.polyline_screen,i=t._program,s=e.handler.gl,r=i.attributes,n=i.uniforms,o=this._handler._entityCollection;t.activate(),s.disable(s.CULL_FACE),s.uniform1f(n.depthOffset,o.polygonOffsetUnits),s.uniformMatrix4fv(n.proj,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(n.view,!1,e.activeCamera.getViewMatrix()),s.uniform3fv(n.rtcEyePositionHigh,this._handler._rtcEyePositionHigh),s.uniform3fv(n.rtcEyePositionLow,this._handler._rtcEyePositionLow),s.uniform4fv(n.visibleSphere,this._visibleSphere),s.uniform2fv(n.viewport,[e.handler.canvas.width,e.handler.canvas.height]),s.uniform1f(n.thickness,.5*this.thickness),s.uniform1f(n.opacity,this._opacity*o._fadingOpacity),s.uniform1f(n.texOffset,this._texOffset),s.uniform1f(n.strokeSize,this._strokeSize),s.bindBuffer(s.ARRAY_BUFFER,this._colorsBuffer),s.vertexAttribPointer(r.color,this._colorsBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._texCoordBuffer),s.vertexAttribPointer(r.texCoord,this._texCoordBuffer.itemSize,s.FLOAT,!1,0,0);let a=this._verticesHighBuffer;s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(r.prevHigh,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(r.currentHigh,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(r.nextHigh,a.itemSize,s.FLOAT,!1,12,96),a=this._verticesLowBuffer,s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(r.prevLow,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(r.currentLow,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(r.nextLow,a.itemSize,s.FLOAT,!1,12,96),s.bindBuffer(s.ARRAY_BUFFER,this._ordersBuffer),s.vertexAttribPointer(r.order,this._ordersBuffer.itemSize,s.FLOAT,!1,4,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexesBuffer.numItems,s.UNSIGNED_INT,0),s.enable(s.CULL_FACE)}}drawPicking(){if(this.visibility&&this._path3v.length){let e=this._renderNode.renderer,t=e.handler.programs.polyline_picking,i=t._program,s=e.handler.gl,r=i.attributes,n=i.uniforms,o=this._handler._entityCollection;t.activate(),s.disable(s.CULL_FACE),s.uniform1f(n.depthOffset,o.polygonOffsetUnits),s.uniformMatrix4fv(n.proj,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(n.view,!1,e.activeCamera.getViewMatrix()),s.uniform4fv(n.color,[this._pickingColor[0],this._pickingColor[1],this._pickingColor[2],1]),s.uniform3fv(n.rtcEyePositionHigh,this._handler._rtcEyePositionHigh),s.uniform3fv(n.rtcEyePositionLow,this._handler._rtcEyePositionLow),s.uniform4fv(n.visibleSphere,this._visibleSphere),s.uniform2fv(n.viewport,[e.handler.canvas.width,e.handler.canvas.height]),s.uniform1f(n.thickness,.5*this.thickness*o.pickingScale[0]);let a=this._verticesHighBuffer;s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(r.prevHigh,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(r.currentHigh,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(r.nextHigh,a.itemSize,s.FLOAT,!1,12,96),a=this._verticesLowBuffer,s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(r.prevLow,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(r.currentLow,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(r.nextLow,a.itemSize,s.FLOAT,!1,12,96),s.bindBuffer(s.ARRAY_BUFFER,this._ordersBuffer),s.vertexAttribPointer(r.order,this._ordersBuffer.itemSize,s.FLOAT,!1,4,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexesBuffer.numItems,s.UNSIGNED_INT,0),s.enable(s.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),e.deleteBuffer(this._texCoordBuffer),this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null,this._texCoordBuffer=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=st(this._verticesHigh),this._verticesLow=st(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=st(this._orders),this._ordersBuffer=e.createArrayBuffer(this._orders,1,this._orders.length/2),this._indexes=st(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=st(this._colors),this._colorsBuffer=e.createArrayBuffer(this._colors,4,this._colors.length/4)}_createTexCoordBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordArr=st(this._texCoordArr),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,4,this._texCoordArr.length/4)}setVisibleSphere(e,t){this._handler&&(this._visibleSphere[0]=e.x-this._handler._relativeCenter.x,this._visibleSphere[1]=e.y-this._handler._relativeCenter.y,this._visibleSphere[2]=e.z-this._handler._relativeCenter.z),this._visibleSphere[3]=t}updateRTCPosition(){this._handler&&this._renderNode&&(this._visibleSphere[0]=this._visibleSphere[0]-this._handler._relativeCenter.x,this._visibleSphere[1]=this._visibleSphere[1]-this._handler._relativeCenter.y,this._visibleSphere[2]=this._visibleSphere[2]-this._handler._relativeCenter.z,this._setEqualPath3v(this._path3v)),this._changedBuffers[0]=!0}};qe.__counter__=0;let br=qe;const ms=class e{constructor(t={}){this.__id=e.__counter__++,this._thickness=t.thickness||2,this._startPosition=Yt(t.startPosition),this._startPositionHigh=new v,this._startPositionLow=new v,v.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._endPosition=Yt(t.endPosition),this._endPositionHigh=new v,this._endPositionLow=new v,v.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._startColor=le(t.startColor),this._endColor=le(t.endColor),this._visibility=null==t.visibility||t.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1,this._image=t.image||null,this._src=t.src||null,this._texOffset=t.texOffset||0,this._strokeSize=null!=t.strokeSize?t.strokeSize:32}setStartPosition(e,t,i){this._startPosition.x=e,this._startPosition.y=t,this._startPosition.z=i,v.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)}setSrc(e){this._src=e;let t=this._handler;if(t){let i=t._entityCollection.renderNode;if(i&&i.renderer){let s=i.renderer.strokeTextureAtlas;e&&e.length?s.loadImage(e,(e=>{if(null!=e.__nodeIndex&&s.get(e.__nodeIndex)){this._image=e;let i=s.get(e.__nodeIndex);t.setTexCoordArr(this._handlerIndex,i.texCoords)}else s.addImage(e),s.createTexture(),this._image=e,i.updateStrokeTexCoords()})):(t.setTextureDisabled(this._handlerIndex),i.updateStrokeTexCoords())}}}getSrc(){return this._src}setImage(e){this.setSrc(e.src)}getImage(){return this._image}setStartPosition3v(e){this._startPosition.x=e.x,this._startPosition.y=e.y,this._startPosition.z=e.z,v.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,v.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,v.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=he(e)),t&&(this._endColor=he(t)),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}get texOffset(){return this._texOffset}set texOffset(e){this._texOffset=e,this._handler&&this._handler.setTexOffsetArr(this._handlerIndex,e)}get strokeSize(){return this._strokeSize}set strokeSize(e){this._strokeSize=e,this._handler&&this._handler.setStrokeSizeArr(this._handlerIndex,e)}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)}};ms.__counter__=0;let wr=ms,ft=new v,gt=new v;const vs=class e{constructor(t={}){if(this.__id=e.__counter__++,this.visibility=null==t.visibility||t.visibility,this.color=new Float32Array([1,1,1,.5]),t.color){let e=le(t.color);this.setColor(e.x,e.y,e.z,e.w)}t.opacity&&this.setOpacity(t.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,t.path&&this.setPath(t.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(he(e))}setColor(e,t,i,s){s=s||this.color[3],this.color[0]=e,this.color[1]=t,this.color[2]=i,this.color[3]=s}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,s=i._program,r=s.attributes,n=s.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),t.uniform4fv(n.uColor,this.color),t.uniform1f(n.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,s=i._program,r=s.attributes,n=s.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),t.uniform1f(n.uOpacity,0!=this._entity._entityCollection._fadingOpacity?1:0),t.uniform4fv(n.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 s=this._path[i-1][0],r=this._path[i-1][1];this._path.push([e.clone(),t.clone()]);let n=this._verticesHigh,o=this._verticesLow,a=this._gridSize,l=a+1,h=new v,c=this._verticesHigh.length/3,d=c,_=Math.abs(s.sub(r).normal().dot(e.sub(s).normal()));for(let i=0;i<l;i++){let u=i/a,f=s.lerp(e,u),g=r.lerp(t,u);for(let u=0;u<l;u++){let p=u/a,m=s.lerp(r,p),y=e.lerp(t,p);1!==_?new Jt(f,g).intersects(new Jt(m,y),h):h=y,d=c+i*l+u,v.doubleToTwoFloats(h,ft,gt);let x=3*d;n[x]=ft.x,n[x+1]=ft.y,n[x+2]=ft.z,o[x]=gt.x,o[x+1]=gt.y,o[x+2]=gt.z,i<a&&this._indexes.push(d,d+l)}i<a&&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 s=this._gridSize,r=s+1,n=r*r,o=new v,a=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-n,_=d,u=Math.abs(h.sub(c).normal().dot(e.sub(h).normal()));for(let i=0;i<r;i++){let n=i/s,f=h.lerp(e,n),g=c.lerp(t,n);for(let n=0;n<r;n++){let p=n/s,m=h.lerp(c,p),y=e.lerp(t,p);1!==u?new Jt(f,g).intersects(new Jt(m,y),o):o=y,_=d+i*r+n,v.doubleToTwoFloats(o,ft,gt);let x=3*_;a[x]=ft.x,a[x+1]=ft.y,a[x+2]=ft.z,l[x]=gt.x,l[x+1]=gt.y,l[x+2]=gt.z}}}else if(0===i){let i=0,n=e,h=t;e=this._path[1][0],t=this._path[1][1];for(let c=0;c<r;c++){let d=c/s,_=n.lerp(e,d),u=h.lerp(t,d);for(let d=0;d<r;d++){let f=d/s,g=n.lerp(h,f),p=e.lerp(t,f);new Jt(_,u).intersects(new Jt(g,p),o),i=c*r+d,v.doubleToTwoFloats(o,ft,gt);let m=3*i;a[m]=ft.x,a[m+1]=ft.y,a[m+2]=ft.z,l[m]=gt.x,l[m+1]=gt.y,l[m+2]=gt.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*n,f=(i-1)*n,g=f;for(let i=0;i<r;i++){let n=i/s,p=h.lerp(e,n),m=t.lerp(_,n),y=e.lerp(d,n),x=c.lerp(t,n);for(let n=0;n<r;n++){let b=n/s,w=h.lerp(c,b),T=e.lerp(t,b);new Jt(p,x).intersects(new Jt(w,T),o);let C=i*r+n;g=f+C,v.doubleToTwoFloats(o,ft,gt);let E=3*g;a[E]=ft.x,a[E+1]=ft.y,a[E+2]=ft.z,l[E]=gt.x,l[E+1]=gt.y,l[E+2]=gt.z;let A=d.lerp(_,b);T=e.lerp(t,b),new Jt(y,m).intersects(new Jt(T,A),o),g=u+C,v.doubleToTwoFloats(o,ft,gt),E=3*g,a[E]=ft.x,a[E+1]=ft.y,a[E+2]=ft.z,l[E]=gt.x,l[E+1]=gt.y,l[E+2]=gt.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],s=e[t][1];i instanceof Array&&(i=new v(i[0],i[1],i[2])),s instanceof Array&&(s=new v(s[0],s[1],s[2])),this.addEdge3v(i,s)}}insertEdge3v(e,t,i){if(i<this._path.length){let s=[].concat(this._path);s.splice(i,0,[e,t]),this.setPath(s)}else i===this._path.length&&this.addEdge3v(e,t)}};vs.__counter__=0;let Tr=vs;const ys=class e{constructor(t={}){t.properties=t.properties||{},this.__id=e.__counter__++,this._name=t.name||`entity:${this.__id}`,this.properties=t.properties||{},this.childEntities=[],this.parent=null,this.forceGlobalPosition=t.forceGlobalPosition||!1,this.forceGlobalRotation=t.forceGlobalRotation||!1,this.forceGlobalScale=t.forceGlobalScale||!1,this._cartesian=Yt(t.cartesian),this._rootCartesian=new v,this._localPosition=Yt(t.localPosition),this._absoluteLocalPosition=new v,this._lonLat=vi(t.lonlat),this._lonLatMerc=new L,this._altitude=t.altitude||0,this._visibility=null==t.visibility||t.visibility,this._entityCollection=null,this._entityCollectionIndex=-1,this._layer=null,this._layerIndex=-1,this._pickingColor=new v(0,0,0),this._independentPicking=t.independentPicking||!1,this._relativePosition=t.relativePosition||!1,this._pitchRad=t.pitch||0,this._yawRad=t.yaw||0,this._rollRad=t.roll||0,this._scale=Yt(t.scale,new v(1,1,1)),this._absoluteScale=new v,this._qFrame=F.IDENTITY,this._qRot=F.IDENTITY,this._absoluteQRot=F.IDENTITY,this._useDirectQuaternion=!1,this._featureConstructorArray={billboard:[Qa,this.setBillboard],label:[el,this.setLabel],polyline:[br,this.setPolyline],pointCloud:[xr,this.setPointCloud],geometry:[vr,this.setGeometry],geoObject:[yr,this.setGeoObject],strip:[Tr,this.setStrip],ray:[wr,this.setRay]},this.billboard=this._createOptionFeature("billboard",t.billboard),this.label=this._createOptionFeature("label",t.label),this.polyline=this._createOptionFeature("polyline",t.polyline),this.ray=this._createOptionFeature("ray",t.ray),this.pointCloud=this._createOptionFeature("pointCloud",t.pointCloud),this.geometry=this._createOptionFeature("geometry",t.geometry),this.geoObject=this._createOptionFeature("geoObject",t.geoObject),this.strip=this._createOptionFeature("strip",t.strip)}get name(){return this._name}set name(e){e!==this._name&&(this._name=e)}get isEmpty(){return!(this.strip||this.polyline||this.ray||this.geoObject||this.geometry||this.billboard||this.label||this.pointCloud)}get rootEntity(){let e=this;for(;e;){if(!e.parent)return e;e=e.parent}return this}set relativePosition(e){if(e!==this._relativePosition){let t=this.getAbsoluteCartesian(),i=this.getAbsolutePitch(),s=this.getAbsoluteYaw(),r=this.getAbsoluteRoll();this._relativePosition=e,this.parent&&this._rootCartesian.copy(this.parent._rootCartesian),e?this.parent&&(this.setAbsoluteCartesian3v(t),this.setAbsolutePitch(i),this.setAbsoluteYaw(s),this.setAbsoluteRoll(r)):(this.setCartesian3v(t),this.setPitch(i),this.setYaw(s),this.setRoll(r))}}get relativePosition(){return this._relativePosition}get entityCollection(){return this._entityCollection}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){return e.add(this),this}remove(){return this._layer&&this._layer.removeEntity(this),this._entityCollection&&this._entityCollection.removeEntity(this),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.childEntities.length;t++)this.childEntities[t].setVisibility(e)}getVisibility(){return this._visibility}setCartesian3v(e){this.setCartesian(e.x,e.y,e.z)}getScale(){return this._scale}setScale3v(e){this._scale.copy(e),this._updateAbsolutePosition();for(let e=0;e<this.childEntities.length;e++){let t=this.childEntities[e];t.forceGlobalScale?t.setScale3v(this._scale):t.setScale3v(this.childEntities[e].getScale())}}setScale(e){this.setScale3v(new v(e,e,e))}getAbsoluteRotation(){return this._absoluteQRot.clone()}getRotation(){return this._qRot}setLook3v(e){let t,i=new F,s=this.getAbsoluteCartesian();if(this._entityCollection){let r=this._entityCollection.renderNode.ellipsoid.getSurfaceNormal3v(s);t=i.setLookRotation(e.sub(s),r).conjugate()}else t=i.setLookRotation(e.sub(s),v.UP).conjugate();this.setAbsoluteRotation(t)}setLookLonLat(e){if(this._entityCollection){let t=this._entityCollection.renderNode.ellipsoid.lonLatToCartesian(e);this.setLook3v(t)}}setAbsoluteRotation(e){this._absoluteQRot.copy(e),this._updatePitchYawRoll()}setRotation(e){this._useDirectQuaternion=!1,this._pitchRad=e.getPitch(),this._yawRad=e.getYaw(),this._rollRad=e.getRoll(),this._updateAbsolutePosition()}setDirectQuaternionRotation(e){this._qRot.copy(e),this._useDirectQuaternion=!0,this._pitchRad=this._qRot.getPitch(),this._yawRad=this._qRot.getYaw(),this._rollRad=this._qRot.getRoll(),this._updateAbsolutePosition()}setPitch(e){this._useDirectQuaternion=!1,this._pitchRad=e,this._updateAbsolutePosition()}setYaw(e){this._useDirectQuaternion=!1,this._yawRad=e,this._updateAbsolutePosition()}setRoll(e){this._useDirectQuaternion=!1,this._rollRad=e,this._updateAbsolutePosition()}getPitch(){return this._pitchRad}getYaw(){return this._yawRad}getRoll(){return this._rollRad}setAbsolutePitch(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(e,this.getAbsoluteYaw(),this.getAbsoluteRoll(),this._qFrame),this._updatePitchYawRoll()):this.setPitch(e)}setAbsoluteYaw(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(),e,this.getAbsoluteRoll(),this._qFrame),this._updatePitchYawRoll()):this.setYaw(e)}setAbsoluteRoll(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(),this.getAbsoluteYaw(),e,this._qFrame),this._updatePitchYawRoll()):this.setRoll(e)}getAbsolutePitch(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getPitch():this._pitchRad}getAbsoluteYaw(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getYaw():this._yawRad}getAbsoluteRoll(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getRoll():this._rollRad}_getScaleByDistance(){let e=1;if(this._entityCollection){let t=this._entityCollection.scaleByDistance,i=1;this._entityCollection.renderNode&&this._entityCollection.renderNode.renderer&&(i=this._entityCollection.renderNode.renderer.activeCamera.eye.distance(this._rootCartesian)),e=t[2]*Zi(i,t[0],t[1])/t[0]}return e}setAbsoluteCartesian(e,t,i){this.setAbsoluteCartesian3v(new v(e,t,i))}setAbsoluteCartesian3v(e){let t=e;if(this.parent&&this._relativePosition){let i=this._getScaleByDistance();t=e.sub(this.parent.getAbsoluteCartesian()).scale(1/i).divA(this.parent._absoluteScale),t=this.parent._absoluteQRot.conjugate().mulVec3(t)}this.setCartesian3v(t)}getAbsoluteCartesian(){if(this.parent&&this._relativePosition){let e=this._getScaleByDistance();return this._rootCartesian.add(this._absoluteLocalPosition.scaleTo(e))}return this._cartesian.clone()}setCartesian(e,t,i){this._cartesian.set(e,t,i),this._updateAbsolutePosition();for(let s=0;s<this.childEntities.length;s++){let r=this.childEntities[s];r._relativePosition?r.setCartesian3v(r.getCartesian()):r.forceGlobalPosition&&r.setCartesian(e,t,i)}this._updateLonLat()}_updatePitchYawRoll(){if(this.parent){this._qRot=this.parent._absoluteQRot.conjugate().mul(this._absoluteQRot),this._pitchRad=this._qRot.getPitch(),this._yawRad=this._qRot.getYaw(),this._rollRad=this._qRot.getRoll(),this.geoObject&&this.geoObject.setRotation(this._absoluteQRot);for(let e=0;e<this.childEntities.length;e++)this.childEntities[e]._updateAbsolutePosition()}}_updateAbsolutePosition(){let e=this.parent;if(e&&this._relativePosition){this._scale.mulRes(e._absoluteScale,this._absoluteScale),this._qFrame.copy(e._qFrame),this._rootCartesian.copy(e._rootCartesian),this._useDirectQuaternion||(e&&this.forceGlobalRotation?this._qRot.setPitchYawRoll(e._pitchRad,e._yawRad,e._rollRad):this._qRot.setPitchYawRoll(this._pitchRad,this._yawRad,this._rollRad)),e._absoluteQRot.mulRes(this._qRot,this._absoluteQRot);let t=e._absoluteQRot.mulVec3(this._cartesian.add(this._localPosition)).mulA(e._absoluteScale);e._absoluteLocalPosition.addRes(t,this._absoluteLocalPosition)}else this._qFrame=F.IDENTITY,this._entityCollection&&this._entityCollection.renderNode&&(this._qFrame=this._entityCollection.renderNode.getFrameRotation(this._cartesian)),this._useDirectQuaternion?this._qFrame.isEqual(F.IDENTITY)||(this._qRot=this._qRot.mul(this._qFrame)):e&&this.forceGlobalRotation?this._qRot.setPitchYawRoll(e._pitchRad,e._yawRad,e._rollRad,this._qFrame):this._qRot.setPitchYawRoll(this._pitchRad,this._yawRad,this._rollRad,this._qFrame),this._absoluteScale.copy(this._scale),this._absoluteQRot.copy(this._qRot),this._rootCartesian.copy(this._cartesian),this._absoluteLocalPosition.copy(this._localPosition);this.geoObject&&(this.geoObject.setScale3v(this._absoluteScale),this.geoObject.setRotation(this._absoluteQRot),this.geoObject.setPosition3v(this._rootCartesian),this.geoObject.setLocalPosition3v(this._absoluteLocalPosition)),this.billboard&&this.billboard.setPosition3v(this._rootCartesian),this.label&&this.label.setPosition3v(this._rootCartesian);for(let e=0,t=this.childEntities.length;e<t;e++)this.childEntities[e]._updateAbsolutePosition();this._updateLonLat()}_setCartesian3vSilent(e,t=!1){this._cartesian.copy(e),this._updateAbsolutePosition();for(let e=0;e<this.childEntities.length;e++)this.childEntities[e].setCartesian(this._cartesian.x,this._cartesian.y,this._cartesian.z);t||this._updateLonLat()}_updateLonLat(){let e=this._entityCollection;e&&e.renderNode&&e.renderNode.ellipsoid&&(this._lonLat=e.renderNode.ellipsoid.cartesianToLonLat(this.getAbsoluteCartesian()),Math.abs(this._lonLat.lat)<ct?this._lonLatMerc=this._lonLat.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=0)}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;if(i&&i.renderNode&&i.renderNode.ellipsoid){Math.abs(t.lat)<ct&&(this._lonLatMerc=t.forwardMercator());let e=new v;i.renderNode.ellipsoid.lonLatToCartesianRes(t,e),this.setAbsoluteCartesian3v(e)}}setLonLat2(e,t,i){let s=this._lonLat;s.lon=e,s.lat=t,s.height=i??s.height;let r=this._entityCollection;if(r&&r.renderNode&&r.renderNode.ellipsoid){Math.abs(s.lat)<ct?this._lonLatMerc=s.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=this._lonLatMerc.height=0;let e=new v;r.renderNode.ellipsoid.lonLatToCartesianRes(s,e),this.setAbsoluteCartesian3v(e)}}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}appendChildren(e,t){for(let i=0;i<e.length;i++)void 0!==t&&(e[i].relativePosition=t),this.appendChild(e[i])}appendChild(e){e._entityCollection=this._entityCollection,e._independentPicking||(e._pickingColor=this._pickingColor),e.parent=this,this.childEntities.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.childEntities.length;e++)this.childEntities[e].setPickingColor()}getExtent(){let e,t=this._lonLat;e=this.billboard||this.label?new U(new L(t.lon,t.lat),new L(t.lon,t.lat)):new U(new L(180,90),new L(-180,-90));let i=e.southWest,s=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>s.lon&&(s.lon=e.northEast.lon),e.northEast.lat>s.lat&&(s.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>s.lon&&(s.lon=e.northEast.lon),e.northEast.lat>s.lat&&(s.lat=e.northEast.lat)}for(let e=0;e<this.childEntities.length;e++){let t=this.childEntities[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>s.lon&&(s.lon=t.northEast.lon),t.northEast.lat>s.lat&&(s.lat=t.northEast.lat)}return e}};ys.__counter__=0;let G=ys;const xs=class e{constructor(t){this.__id=e.__counter__++,this._name=t||`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}};xs.__counter__=0;let Cr=xs;class de extends Cr{constructor(e){super(e),this.childNodes=[],this.renderer=null,this.drawMode=0,this.show=!0,this._isActive=!0,this.lightEnabled=!1,this._lightPosition=new Float32Array([100,100,100]),this._lightParams=new Float32Array(9),this._lightShininess=100,this.entityCollections=[],this._entityCollectionsByDepthOrder=[],this._pickingId=-1}getFrameRotation(e){return F.IDENTITY}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){e.renderNode||(e.renderNode=this,t||(this.entityCollections.push(e),this.updateEntityCollectionsDepthOrder()),this.ellipsoid&&e._updateGeodeticCoordinates(this.ellipsoid),e.bindRenderNode(this),e.events.dispatch(e.events.add,this))}removeEntityCollection(e){for(let t=0;t<this.entityCollections.length;t++)if(this.entityCollections[t].isEqual(e))return this.entityCollections.splice(t,1),void this.updateEntityCollectionsDepthOrder()}updateEntityCollectionsDepthOrder(){let e={0:[]};for(const t of this.entityCollections)t.getVisibility()&&(e[t.depthOrder]||(e[t.depthOrder]=[]),e[t.depthOrder].push(t));this._entityCollectionsByDepthOrder.length=0,this._entityCollectionsByDepthOrder=[],this._entityCollectionsByDepthOrder=Object.keys(e).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[Number(t)]))}addLight(e){return e.addTo(this),this}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)}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr()}updateStrokeTexCoords(){for(let e=0;e<this.entityCollections.length;e++){let t=this.entityCollections[e];t.rayHandler.refreshTexCoordsArr(),t.polylineHandler.refreshTexCoordsArr()}}frame(){}preFrame(){}_preDrawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._preDrawNodes();if(this.show){this.preFrame();for(let e=0;e<this._entityCollectionsByDepthOrder.length;e++)this.drawEntityCollections(this._entityCollectionsByDepthOrder[e],e)}}_drawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._drawNodes();this.show&&this.frame()}drawEntityCollections(e,t=0){this.renderer.enqueueEntityCollectionsToDraw(e,t)}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(){}}const ie=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 fi=["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 ht={};for(let e=0;e<fi.length;e++)ht[fi[e]]=e;const Er={};for(let e=0;e<fi.length;e++)Er[fi[e].toLowerCase()]=ht[fi[e]];const Pt={u:[],a:[]};Pt.u[ht.MAT4]=function(e,t){e.gl.uniformMatrix4fv(t._pName,!1,t.value)},Pt.u[ht.MAT3]=function(e,t){e.gl.uniformMatrix3fv(t._pName,!1,t.value)},Pt.u[ht.FLOAT]=function(e,t){e.gl.uniform1f(t._pName,t.value)},Pt.u[ht.INT]=function(e,t){e.gl.uniform1i(t._pName,t.value)},Pt.u[ht.VEC2]=function(e,t){e.gl.uniform2fv(t._pName,t.value)},Pt.u[ht.VEC3]=function(e,t){e.gl.uniform3fv(t._pName,t.value)},Pt.u[ht.VEC4]=function(e,t){e.gl.uniform4fv(t._pName,t.value)},Pt.u[ht.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++},Pt.u[ht.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++},Pt.u[ht.SAMPLER2DARRAY]=function(e,t){let i=t.value,s=e.gl,r=i.length,n=new Int32Array(r);for(let t=0;t<r;t++)s.activeTexture(s.TEXTURE0+e._textureID+t),s.bindTexture(s.TEXTURE_2D,i[t]),n[t]=t;s.uniform1iv(t._pName,n)},Pt.u[ht.INTXX]=function(e,t){e.gl.uniform1iv(t._pName,t.value)},Pt.u[ht.FLOATXX]=function(e,t){e.gl.uniform1fv(t._pName,t.value)},Pt.a[ht.FLOAT]=function(e,t){e.gl.vertexAttrib1f(t._pName,t.value)},Pt.a[ht.VEC2]=function(e,t){e.gl.vertexAttrib2fv(t._pName,t.value)},Pt.a[ht.VEC3]=function(e,t){e.gl.vertexAttrib3fv(t._pName,t.value)};const il=["BYTE","SHORT","UNSIGNED_BYTE","UNSIGNED_SHORT","FLOAT","HALF_FLOAT"];class X{constructor(e,t){this.name=e,this._programController=null,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){if(!this.gl)return!1;const i=this.gl instanceof WebGL2RenderingContext;return this.gl.shaderSource(e,function(e,t){if(!t)return e;const i=e.split("\n"),s=i.findIndex((e=>e.startsWith("#version")));return-1!==s?(i.splice(s+1,0,"#define WEBGL2"),i.join("\n")):e}(t,i)),this.gl.compileShader(e),!!this.gl.getShaderParameter(e,this.gl.COMPILE_STATUS)||(ie.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,s=t.length;i<s;i++)e.disableVertexAttribArray(t[i]),this.vertexAttribDivisor(t[i],0)}enableAttribArrays(){let e=this.gl,t=this._attribArrays,i=this._attribDivisor;for(let s=0,r=t.length;s<r;s++)e.enableVertexAttribArray(t[s]),this.vertexAttribDivisor(t[s],i[s])}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 ie.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=X.bindBuffer;let i=this._attributes[t].itemType,s=i?i.trim().toUpperCase():"FLOAT";if(-1==il.indexOf(s)?(ie.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[s],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 ie.logErr(`Shader program "${this.name}": attribute '${t}' not exists.`),void e.deleteProgram(this._p);let r=this._attributes[t].type;"string"==typeof r&&(r=Er[r.trim().toLowerCase()]);let n=this._attributes[t].divisor;if(r===ht.MAT4){let e=this._p[t];this._attribArrays.push(e,e+1,e+2,e+3),this._attribDivisor.push(n,n,n,n)}else this._attribArrays.push(this._p[t]),this._attribDivisor.push(n);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=Pt.u[Er[e.trim().toLowerCase()]]}else this._uniforms[t].func=Pt.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 ie.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 bs=class e{constructor(t){this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,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 X("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#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}attribute vec2 a_vertices;attribute vec2 a_texCoord;attribute vec3 a_positionsHigh;attribute vec3 a_positionsLow;attribute vec3 a_offset;attribute vec2 a_size;attribute float a_rotation;attribute vec4 a_rgba;varying vec2 v_texCoords;varying vec4 v_rgba;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform vec3 uScaleByDistance;uniform float opacity;uniform float planetRadius;uniform vec2 viewport;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;v_texCoords=a_texCoord;vec3 look=a_positions-cameraPos;float lookDist=length(look);v_rgba=a_rgba;if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(uScaleByDistance[0],uScaleByDistance[1],lookDist))*(1.0-step(uScaleByDistance[2],lookDist));mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 v=screenPos+rotate2d(a_rotation)*(a_vertices*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"precision highp float;uniform sampler2D u_texture;varying vec2 v_texCoords;varying vec4 v_rgba;void main(){vec4 color=texture2D(u_texture,v_texCoords);if(color.a<0.1)discard;gl_FragColor=color*v_rgba;}"})),this._renderer.handler.programs.billboardPicking||this._renderer.handler.addProgram(new X("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#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}attribute vec2 a_vertices;attribute vec3 a_positionsHigh;attribute vec3 a_positionsLow;attribute vec3 a_offset;attribute vec2 a_size;attribute float a_rotation;attribute vec4 a_rgba;varying vec3 v_rgb;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform vec3 uScaleByDistance;uniform float opacity;uniform float planetRadius;uniform vec2 viewport;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;vec3 look=a_positions-cameraPos;float lookDist=length(look);v_rgb=a_rgba.rgb;if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(uScaleByDistance[0],uScaleByDistance[1],lookDist))*(1.0-step(uScaleByDistance[2],lookDist));mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 v=screenPos+rotate2d(a_rotation)*(a_vertices*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"precision highp float;varying vec3 v_rgb;void main(){gl_FragColor=vec4(v_rgb,1.0);}"})))}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=-1}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,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection;n.disable(n.CULL_FACE),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.uniform1i(r.u_texture,0),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform3fv(r.uScaleByDistance,o.scaleByDistance),n.uniform1f(r.opacity,o._fadingOpacity),n.bindBuffer(n.ARRAY_BUFFER,this._texCoordBuffer),n.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionHighBuffer),n.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionLowBuffer),n.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._rgbaBuffer),n.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._sizeBuffer),n.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._offsetBuffer),n.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,n.FLOAT,!1,0,0),n.uniform1f(r.planetRadius,o.renderNode._planetRadius2||0),n.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),n.bindBuffer(n.ARRAY_BUFFER,this._rotationBuffer),n.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.enable(n.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.billboardPicking.activate();let i=t.programs.billboardPicking._program,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection;n.disable(n.CULL_FACE),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform3fv(r.uScaleByDistance,o.scaleByDistance),n.uniform1f(r.opacity,o._fadingOpacity),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionHighBuffer),n.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionLowBuffer),n.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._pickingColorBuffer),n.vertexAttribPointer(s.a_rgba,this._pickingColorBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._sizeBuffer),n.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._offsetBuffer),n.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,n.FLOAT,!1,0,0),n.uniform1f(r.planetRadius,o.renderNode._planetRadius2||0),n.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),n.bindBuffer(n.ARRAY_BUFFER,this._rotationBuffer),n.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.enable(n.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=ot(this._rgbaArr,i,24),i=18*t,this._positionHighArr=ot(this._positionHighArr,i,18),this._positionLowArr=ot(this._positionLowArr,i,18),this._offsetArr=ot(this._offsetArr,i,18),this._pickingColorArr=ot(this._pickingColorArr,i,18),i=12*t,this._vertexArr=ot(this._vertexArr,i,12),this._sizeArr=ot(this._sizeArr,i,12),this._texCoordArr=ot(this._texCoordArr,i,12),i=6*t,this._rotationArr=ot(this._rotationArr,i,6),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1,e._lockId=-1}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 s=18*e,r=this._positionHighArr,n=t.x,o=t.y,a=t.z;r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,r=this._positionLowArr,n=i.x,o=i.y,a=i.z,r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e,s=this._pickingColorArr,r=t.x/255,n=t.y/255,o=t.z/255;s[i]=r,s[i+1]=n,s[i+2]=o,s[i+3]=r,s[i+4]=n,s[i+5]=o,s[i+6]=r,s[i+7]=n,s[i+8]=o,s[i+9]=r,s[i+10]=n,s[i+11]=o,s[i+12]=r,s[i+13]=n,s[i+14]=o,s[i+15]=r,s[i+16]=n,s[i+17]=o,this._changedBuffers[0]=!0}setSizeArr(e,t,i){let s=12*e,r=this._sizeArr,n=t,o=i;r[s]=n,r[s+1]=o,r[s+2]=n,r[s+3]=o,r[s+4]=n,r[s+5]=o,r[s+6]=n,r[s+7]=o,r[s+8]=n,r[s+9]=o,r[s+10]=n,r[s+11]=o,this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e,s=this._offsetArr,r=t.x,n=t.y,o=t.z;s[i]=r,s[i+1]=n,s[i+2]=o,s[i+3]=r,s[i+4]=n,s[i+5]=o,s[i+6]=r,s[i+7]=n,s[i+8]=o,s[i+9]=r,s[i+10]=n,s[i+11]=o,s[i+12]=r,s[i+13]=n,s[i+14]=o,s[i+15]=r,s[i+16]=n,s[i+17]=o,this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e,s=this._rgbaArr,r=t.x,n=t.y,o=t.z,a=t.w;s[i]=r,s[i+1]=n,s[i+2]=o,s[i+3]=a,s[i+4]=r,s[i+5]=n,s[i+6]=o,s[i+7]=a,s[i+8]=r,s[i+9]=n,s[i+10]=o,s[i+11]=a,s[i+12]=r,s[i+13]=n,s[i+14]=o,s[i+15]=a,s[i+16]=r,s[i+17]=n,s[i+18]=o,s[i+19]=a,s[i+20]=r,s[i+21]=n,s[i+22]=o,s[i+23]=a,this._changedBuffers[4]=!0}setRotationArr(e,t){let i=6*e,s=this._rotationArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[5]=!0}setTexCoordArr(e,t){let i=12*e,s=this._texCoordArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[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,s=this._vertexArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[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(){}};bs.__counter__=0;let ns=bs;class sl extends ns{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=it(this._vertexArr,[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]):this._vertexArr=it(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]),this._texCoordArr=it(this._texCoordArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t,i=e._positionHigh.x,s=e._positionHigh.y,r=e._positionHigh.z;this._positionHighArr=it(this._positionHighArr,[i,s,r,i,s,r,i,s,r,i,s,r,i,s,r,i,s,r]),i=e._positionLow.x,s=e._positionLow.y,r=e._positionLow.z,this._positionLowArr=it(this._positionLowArr,[i,s,r,i,s,r,i,s,r,i,s,r,i,s,r,i,s,r]),i=e._width,s=e._height,this._sizeArr=it(this._sizeArr,[i,s,i,s,i,s,i,s,i,s,i,s]),i=e._offset.x,s=e._offset.y,r=e._offset.z,this._offsetArr=it(this._offsetArr,[i,s,r,i,s,r,i,s,r,i,s,r,i,s,r,i,s,r]),i=e._color.x,s=e._color.y,r=e._color.z,t=e._color.w,this._rgbaArr=it(this._rgbaArr,[i,s,r,t,i,s,r,t,i,s,r,t,i,s,r,t,i,s,r,t,i,s,r,t]),i=e._rotation,this._rotationArr=it(this._rotationArr,[i,i,i,i,i,i]),i=e._entity._pickingColor.x/255,s=e._entity._pickingColor.y/255,r=e._entity._pickingColor.z/255,this._pickingColorArr=it(this._pickingColorArr,[i,s,r,i,s,r,i,s,r,i,s,r,i,s,r,i,s,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],s=i.getImage();if(s){let t=e.get(s.__nodeIndex);t&&this.setTexCoordArr(i._handlerIndex,t.texCoords)}}}}}class rl{constructor(e){this.isFree=!0,this._geoObjectHandler=e,this.geoObjects=[],this.numInstances=0,this._colorTexture=null,this._colorTextureSrc=null,this._colorTextureImage=null,this._normalTexture=null,this._normalTextureSrc=null,this._normalTextureImage=null,this._metallicRoughnessTexture=null,this._metallicRoughnessTextureSrc=null,this._metallicRoughnessTextureImage=null,this._sizeArr=[],this._translateArr=[],this._vertexArr=[],this._rtcPositionHighArr=[],this._rtcPositionLowArr=[],this._qRotArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._localPositionArr=[],this._sizeBuffer=null,this._translateBuffer=null,this._vertexBuffer=null,this._rtcPositionHighBuffer=null,this._rtcPositionLowBuffer=null,this._qRotBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._localPositionBuffer=null,this._materialParams=new Float32Array(9),this._materialShininess=0,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[Jo]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[Xo]=this.createNormalsBuffer,this._buffersUpdateCallbacks[$o]=this.createRgbaBuffer,this._buffersUpdateCallbacks[Zo]=this.createIndicesBuffer,this._buffersUpdateCallbacks[Yo]=this.createVertexBuffer,this._buffersUpdateCallbacks[Qo]=this.createSizeBuffer,this._buffersUpdateCallbacks[ta]=this.createVisibleBuffer,this._buffersUpdateCallbacks[ea]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[Ko]=this.createQRotBuffer,this._buffersUpdateCallbacks[ia]=this.createTranslateBuffer,this._buffersUpdateCallbacks[Wo]=this.createRTCPositionBuffer,this._buffersUpdateCallbacks[sa]=this.createLocalPositionBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}setMaterialAmbient(e,t,i){this._materialParams[0]=e,this._materialParams[1]=t,this._materialParams[2]=i}setMaterialDiffuse(e,t,i){this._materialParams[3]=e,this._materialParams[4]=t,this._materialParams[5]=i}setMaterialSpecular(e,t,i){this._materialParams[6]=e,this._materialParams[7]=t,this._materialParams[8]=i}setMaterialShininess(e){this._materialShininess=e}setMaterialParams(e,t,i,s){this.setMaterialAmbient(e[0],e[1],e[2]),this.setMaterialDiffuse(t[0],t[1],t[2]),this.setMaterialSpecular(i[0],i[1],i[2]),this.setMaterialShininess(s)}drawOpaque(e){let t=e.gl,i=e.uniforms,s=e.attributes;t.bindBuffer(t.ARRAY_BUFFER,this._qRotBuffer),t.vertexAttribPointer(s.qRot,this._qRotBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._sizeBuffer),t.vertexAttribPointer(s.aScale,this._sizeBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._translateBuffer),t.vertexAttribPointer(s.aTranslate,this._translateBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._localPositionBuffer),t.vertexAttribPointer(s.aLocalPosition,this._localPositionBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._visibleBuffer),t.vertexAttribPointer(s.aDispose,this._visibleBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(i.uUseTexture,this._colorTexture?1:0),t.bindBuffer(t.ARRAY_BUFFER,this._rgbaBuffer),t.vertexAttribPointer(s.aColor,this._rgbaBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform3fv(i.materialParams,this._materialParams),t.uniform1f(i.materialShininess,this._materialShininess),this._drawElementsInstanced(e)}drawTransparent(e){let t=e.gl,i=e.uniforms,s=e.attributes;t.bindBuffer(t.ARRAY_BUFFER,this._qRotBuffer),t.vertexAttribPointer(s.qRot,this._qRotBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._sizeBuffer),t.vertexAttribPointer(s.aScale,this._sizeBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._translateBuffer),t.vertexAttribPointer(s.aTranslate,this._translateBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._localPositionBuffer),t.vertexAttribPointer(s.aLocalPosition,this._localPositionBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._visibleBuffer),t.vertexAttribPointer(s.aDispose,this._visibleBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(i.uUseTexture,this._colorTexture?1:0),t.uniform3fv(i.materialParams,this._materialParams),t.uniform1f(i.materialShininess,this._materialShininess),t.bindBuffer(t.ARRAY_BUFFER,this._rgbaBuffer),t.vertexAttribPointer(s.aColor,this._rgbaBuffer.itemSize,t.FLOAT,!1,0,0),this._drawElementsInstanced(e)}_drawElementsInstanced(e){let t=e.gl,i=e.uniforms,s=e.attributes,r=this._geoObjectHandler._renderer;t.bindBuffer(t.ARRAY_BUFFER,this._rtcPositionHighBuffer),t.vertexAttribPointer(s.aRTCPositionHigh,this._rtcPositionHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._rtcPositionLowBuffer),t.vertexAttribPointer(s.aRTCPositionLow,this._rtcPositionLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._normalsBuffer),t.vertexAttribPointer(s.aVertexNormal,this._normalsBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._vertexBuffer),t.vertexAttribPointer(s.aVertexPosition,this._vertexBuffer.itemSize,t.FLOAT,!1,0,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._colorTexture||r.handler.defaultTexture),t.uniform1i(i.uTexture,0),t.bindBuffer(t.ARRAY_BUFFER,this._texCoordBuffer),t.vertexAttribPointer(s.aTexCoord,this._texCoordBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indicesBuffer),e.drawElementsInstanced(t.TRIANGLES,this._indicesBuffer.numItems,t.UNSIGNED_INT,0,this.numInstances)}async loadColorTexture(){if(this._geoObjectHandler._renderer){if(!this._colorTextureSrc)return this._colorTextureImage?(await this._colorTextureImage.decode(),void this._createColorTexture(this._colorTextureImage)):void 0;{const e=await Ui(this._colorTextureSrc);this._createColorTexture(e)}}}async loadNormalTexture(){if(this._geoObjectHandler._renderer){if(!this._normalTextureSrc)return this._normalTextureImage?(await this._normalTextureImage.decode(),void this._createNormalTexture(this._normalTextureImage)):void 0;{const e=await Ui(this._normalTextureSrc);this._createNormalTexture(e)}}}async loadMetallicRoughnessTexture(){if(this._geoObjectHandler._renderer){if(!this._metallicRoughnessTextureSrc)return this._metallicRoughnessTextureImage?(await this._metallicRoughnessTextureImage.decode(),void this._createMetallicRoughnessTexture(this._metallicRoughnessTextureImage)):void 0;{const e=await Ui(this._metallicRoughnessTextureSrc);this._createMetallicRoughnessTexture(e)}}}clear(){this.numInstances=0,this.geoObjects=[],this._sizeArr=[],this._translateArr=[],this._vertexArr=[],this._rtcPositionHighArr=[],this._rtcPositionLowArr=[],this._qRotArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._localPositionArr=[],this._deleteBuffers(),this.isFree=!1}_deleteBuffers(){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let e=this._geoObjectHandler._renderer.handler;if(e){e.deleteTexture(this._colorTexture),e.deleteTexture(this._normalTexture),e.deleteTexture(this._metallicRoughnessTexture);let t=e.gl;t&&(t.deleteBuffer(this._sizeBuffer),t.deleteBuffer(this._translateBuffer),t.deleteBuffer(this._vertexBuffer),t.deleteBuffer(this._rtcPositionHighBuffer),t.deleteBuffer(this._rtcPositionLowBuffer),t.deleteBuffer(this._qRotBuffer),t.deleteBuffer(this._rgbaBuffer),t.deleteBuffer(this._normalsBuffer),t.deleteBuffer(this._indicesBuffer),t.deleteBuffer(this._pickingColorBuffer),t.deleteBuffer(this._visibleBuffer),t.deleteBuffer(this._texCoordBuffer),t.deleteBuffer(this._localPositionBuffer))}this._colorTexture=null,this._normalTexture=null,this._metallicRoughnessTexture=null}this._sizeBuffer=null,this._translateBuffer=null,this._vertexBuffer=null,this._rtcPositionHighBuffer=null,this._rtcPositionLowBuffer=null,this._qRotBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._localPositionBuffer=null}createVertexBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=st(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,3,this._vertexArr.length/3)}createVisibleBuffer(){const e=this._geoObjectHandler._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=st(this._visibleArr),e.setStreamArrayBuffer(this._visibleBuffer,this._visibleArr)}createSizeBuffer(){let e=this._geoObjectHandler._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=st(this._sizeArr),e.setStreamArrayBuffer(this._sizeBuffer,this._sizeArr)}createTranslateBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._translateArr.length/3;this._translateBuffer&&this._translateBuffer.numItems===t||(e.gl.deleteBuffer(this._translateBuffer),this._translateBuffer=e.createStreamArrayBuffer(3,t)),this._translateArr=st(this._translateArr),e.setStreamArrayBuffer(this._translateBuffer,this._translateArr)}createLocalPositionBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._localPositionArr.length/3;this._localPositionBuffer&&this._localPositionBuffer.numItems===t||(e.gl.deleteBuffer(this._localPositionBuffer),this._localPositionBuffer=e.createStreamArrayBuffer(3,t)),this._localPositionArr=st(this._localPositionArr),e.setStreamArrayBuffer(this._localPositionBuffer,this._localPositionArr)}createTexCoordBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordArr=st(this._texCoordArr),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createRTCPositionBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._rtcPositionHighArr.length/3;this._rtcPositionHighBuffer&&this._rtcPositionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._rtcPositionHighBuffer),e.gl.deleteBuffer(this._rtcPositionLowBuffer),this._rtcPositionHighBuffer=e.createStreamArrayBuffer(3,t),this._rtcPositionLowBuffer=e.createStreamArrayBuffer(3,t)),this._rtcPositionHighArr=st(this._rtcPositionHighArr),this._rtcPositionLowArr=st(this._rtcPositionLowArr),e.setStreamArrayBuffer(this._rtcPositionHighBuffer,this._rtcPositionHighArr),e.setStreamArrayBuffer(this._rtcPositionLowBuffer,this._rtcPositionLowArr)}createRgbaBuffer(){let e=this._geoObjectHandler._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=st(this._rgbaArr),e.setStreamArrayBuffer(this._rgbaBuffer,this._rgbaArr)}createQRotBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._qRotArr.length/4;this._qRotBuffer&&this._qRotBuffer.numItems===t||(e.gl.deleteBuffer(this._qRotBuffer),this._qRotBuffer=e.createStreamArrayBuffer(4,t)),this._qRotArr=st(this._qRotArr),e.setStreamArrayBuffer(this._qRotBuffer,this._qRotArr)}createNormalsBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._normalsBuffer),this._normalsArr=st(this._normalsArr),this._normalsBuffer=e.createArrayBuffer(this._normalsArr,3,this._normalsArr.length/3)}createIndicesBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._indicesBuffer),this._indicesArr=st(this._indicesArr,Uint32Array),this._indicesBuffer=e.createElementArrayBuffer(this._indicesArr,1,this._indicesArr.length)}createPickingColorBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=st(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._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1);this.isFree=!0}}_createColorTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._colorTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}_createNormalTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._normalTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}_createMetallicRoughnessTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._metallicRoughnessTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}}const Yo=0,Wo=1,$o=2,Xo=3,Zo=4,Ko=5,Qo=6,Jo=7,ta=8,ea=9,ia=10,sa=11;function Tt(e,t=0,i=0,s=1,...r){const n=t*i;for(let t=n,o=n+i;t<o;t++)e[t]=r[t%s];return e}const ws=class e{constructor(t){this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,this._renderNode=null,this._renderer=null,this._geoObjects=[],this._instanceDataMap=new Map,this._instanceDataMapValues=[],this._dataTagUpdateQueue=[],this._relativeCenter=new v,this._rtcEyePositionHigh=new Float32Array([0,0,0]),this._rtcEyePositionLow=new Float32Array([0,0,0])}initProgram(){this._renderer&&(this._renderer.handler.programs.geo_object||this._renderer.handler.addProgram(new X("geo_object",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",eyePositionHigh:"vec3",eyePositionLow:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",sunPosition:"vec3",materialParams:"vec3",materialShininess:"float",uTexture:"sampler2d",uUseTexture:"float",useLighting:"float"},attributes:{aVertexPosition:"vec3",aVertexNormal:"vec3",aTexCoord:"vec2",aLocalPosition:{type:"vec3",divisor:1},aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aColor:{type:"vec4",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1}},vertexShader:"precision highp float;vec3 qRotate(vec4 q,vec3 v){return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}attribute vec3 aVertexPosition;attribute vec3 aVertexNormal;attribute vec3 aRTCPositionHigh;attribute vec3 aRTCPositionLow;attribute vec4 aColor;attribute vec3 aScale;attribute vec3 aTranslate;attribute float aDispose;attribute float aUseTexture;attribute vec2 aTexCoord;attribute vec4 qRot;attribute vec3 aLocalPosition;uniform vec3 uScaleByDistance;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;varying vec3 cameraPosition;varying vec3 vNormal;varying vec3 v_vertex;varying vec4 vColor;varying float vDispose;varying vec2 vTexCoords;void main(void){if(aDispose==0.0){return;}vColor=aColor;vTexCoords=aTexCoord;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=aRTCPositionHigh-rtcEyePositionHigh;vec3 lowDiff=aRTCPositionLow-rtcEyePositionLow;cameraPosition=eyePositionHigh+eyePositionLow;highDiff=highDiff*step(1.0,length(highDiff));vec4 positionInViewSpace=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);float lookLength=length(positionInViewSpace.xyz);vNormal=normalize(qRotate(qRot,aVertexNormal));float scd=uScaleByDistance[2]*clamp(lookLength,uScaleByDistance[0],uScaleByDistance[1])/uScaleByDistance[0];vec3 vert=qRotate(qRot,scd*(aVertexPosition*aScale+aTranslate))+scd*aLocalPosition;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff+lowDiff+vert,1.0);v_vertex=positionInViewSpace.xyz+vert;}",fragmentShader:"precision highp float;uniform vec3 sunPosition;uniform vec3 materialParams[3];uniform float materialShininess;uniform sampler2D uTexture;uniform float uUseTexture;uniform float useLighting;varying vec3 cameraPosition;varying vec3 v_vertex;varying vec4 vColor;varying vec3 vNormal;varying vec2 vTexCoords;void main(void){vec3 lightWeighting=vec3(1.0);if(useLighting!=0.0){vec3 normal=normalize(vNormal);vec3 light_dir=normalize(sunPosition);vec3 look_dir=normalize(cameraPosition-v_vertex);float diffuse=max(dot(normal,light_dir),0.0);vec3 refl_dir=reflect(-light_dir,normal);float refl=max(dot(refl_dir,look_dir),0.0);float specular=pow(refl,materialShininess)*step(1e-4,diffuse);lightWeighting=vColor.rgb*materialParams[0]+materialParams[1]*diffuse+materialParams[2]*specular;}else{lightWeighting=vColor.rgb;}if(uUseTexture>0.0){vec4 texColor=texture2D(uTexture,vTexCoords);gl_FragColor=vec4(texColor.rgb*lightWeighting,texColor.a);}else{gl_FragColor=vec4(lightWeighting,vColor.a);}}"})),this._renderer.handler.programs.geo_object_picking||this._renderer.handler.addProgram(new X("geo_object_picking",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",pickingScale:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3"},attributes:{aVertexPosition:"vec3",aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aPickingColor:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aLocalPosition:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1}},vertexShader:"precision highp float;vec3 qRotate(vec4 q,vec3 v){return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}attribute vec3 aVertexPosition;attribute vec3 aRTCPositionHigh;attribute vec3 aRTCPositionLow;attribute vec3 aPickingColor;attribute vec3 aScale;attribute vec3 aTranslate;attribute float aDispose;attribute vec4 qRot;attribute vec3 aLocalPosition;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;uniform vec3 uScaleByDistance;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 pickingScale;varying vec3 vColor;void main(void){if(aDispose==0.0){return;}vColor=aPickingColor;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=aRTCPositionHigh-rtcEyePositionHigh;vec3 lowDiff=aRTCPositionLow-rtcEyePositionLow;highDiff=highDiff*step(1.0,length(highDiff));vec4 positionInViewSpace=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);float lookLength=length(positionInViewSpace.xyz);float scd=uScaleByDistance[2]*clamp(lookLength,uScaleByDistance[0],uScaleByDistance[1])/uScaleByDistance[0];vec3 vert=qRotate(qRot,scd*pickingScale*(aVertexPosition*aScale+aTranslate))+scd*aLocalPosition;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff+lowDiff+vert,1.0);}",fragmentShader:"precision highp float;varying vec3 vColor;void main(){gl_FragColor=vec4(vColor,1.0);}"})),this._renderer.handler.programs.geo_object_depth||this._renderer.handler.addProgram(new X("geo_object_depth",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",frustumPickingColor:"float"},attributes:{aVertexPosition:"vec3",aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1},aLocalPosition:{type:"vec3",divisor:1}},vertexShader:"#version 300 es\nprecision highp float;vec3 qRotate(vec4 q,vec3 v){return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}in vec3 aVertexPosition;in vec3 aRTCPositionHigh;in vec3 aRTCPositionLow;in vec3 aScale;in vec3 aTranslate;in float aDispose;in vec4 qRot;in vec3 aLocalPosition;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;uniform vec3 uScaleByDistance;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;void main(void){if(aDispose==0.0){return;}mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=aRTCPositionHigh-rtcEyePositionHigh;vec3 lowDiff=aRTCPositionLow-rtcEyePositionLow;highDiff=highDiff*step(1.0,length(highDiff));vec4 positionInViewSpace=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);float lookLength=length(positionInViewSpace.xyz);float scd=uScaleByDistance[2]*clamp(lookLength,uScaleByDistance[0],uScaleByDistance[1])/uScaleByDistance[0];vec3 vert=qRotate(qRot,scd*(aVertexPosition*aScale+aTranslate))+scd*aLocalPosition;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff+lowDiff+vert,1.0);}",fragmentShader:"#version 300 es\nprecision highp float;uniform float frustumPickingColor;layout(location=0)out vec4 frustumColor;layout(location=1)out vec4 depthColor;void main(){frustumColor=vec4(frustumPickingColor,frustumPickingColor,frustumPickingColor,1.0);depthColor=vec4(gl_FragCoord.z,gl_FragCoord.z,gl_FragCoord.z,1.0);}"})))}setRenderNode(e){this._renderNode=e,this._renderer=e.renderer,this.initProgram();for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].loadColorTexture(),this._instanceDataMapValues[e].loadNormalTexture(),this._instanceDataMapValues[e].loadMetallicRoughnessTexture();for(let e=0;e<this._geoObjects.length;e++)this._geoObjects[e].updateRotation();this.update()}setColorTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&("string"==typeof e&&(i._colorTextureSrc=e,i._colorTextureImage=null),e instanceof HTMLImageElement&&(i._colorTextureSrc=null,i._colorTextureImage=e),this._instanceDataMap.set(t,i),i.loadColorTexture())}setNormalTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&("string"==typeof e&&(i._normalTextureSrc=e,i._normalTextureImage=null),e instanceof HTMLImageElement&&(i._normalTextureSrc=null,i._normalTextureImage=e),this._instanceDataMap.set(t,i),i.loadNormalTexture())}setMetallicRoughnessTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&("string"==typeof e&&(i._metallicRoughnessTextureSrc=e,i._metallicRoughnessTextureImage=null),e instanceof HTMLImageElement&&(i._metallicRoughnessTextureSrc=null,i._metallicRoughnessTextureImage=e),this._instanceDataMap.set(t,i),i.loadMetallicRoughnessTexture())}setObjectSrc(e,t){const i=this._instanceDataMap.get(t);e&&i&&i._objectSrc!==e&&(i._objectSrc=e,$.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[Yo]=!0),e.normals.length!==i._normalsArr.length&&(i._normalsArr=e.normals,i._changedBuffers[Xo]=!0),e.indices.length!==i._indicesArr.length&&(i._indicesArr=e.indices,i._changedBuffers[Zo]=!0),e.texCoords.length!==i._texCoordArr.length&&(i._texCoordArr=e.texCoords,i._changedBuffers[ea]=!0),i._colorTextureSrc=e.colorTextureSrc,i._normalTextureSrc=e.normalTextureSrc,i._metallicRoughnessTexture=e.metallicRoughnessTextureSrc,i._colorTextureImage=e.colorTextureImage,i._normalTextureImage=e.normalTextureImage,i._metallicRoughnessTextureImage=e.metallicRoughnessTextureImage,i.loadColorTexture(),i.loadNormalTexture(),i.loadMetallicRoughnessTexture(),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 rl(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._colorTextureSrc=e.object3d.colorTextureSrc,i._normalTextureSrc=e.object3d.normalTextureSrc,i._metallicRoughnessTextureSrc=e.object3d.metallicRoughnessTextureSrc,i._colorTextureImage=e.object3d.colorTextureImage,i._normalTextureImage=e.object3d.normalTextureImage,i._metallicRoughnessTextureImage=e.object3d.metallicRoughnessTextureImage,i.setMaterialParams(e.object3d.ambient,e.object3d.diffuse,e.object3d.specular,e.object3d.shininess),i.loadColorTexture(),i.loadNormalTexture(),i.loadMetallicRoughnessTexture()),e._tagDataIndex=i.numInstances++,e._tagData=i,i.geoObjects.push(e);let s=3;i._visibleArr=bt(i._visibleArr,Tt([],0,1,1,e.getVisibility()?1:0)),this.getRTCPosition(e.getPosition(),e._rtcPositionHigh,e._rtcPositionLow);let r,n=e._rtcPositionHigh.x,o=e._rtcPositionHigh.y,a=e._rtcPositionHigh.z;i._rtcPositionHighArr=bt(i._rtcPositionHighArr,Tt([],0,s,s,n,o,a)),n=e._rtcPositionLow.x,o=e._rtcPositionLow.y,a=e._rtcPositionLow.z,i._rtcPositionLowArr=bt(i._rtcPositionLowArr,Tt([],0,s,s,n,o,a)),n=e._entity._pickingColor.x/255,o=e._entity._pickingColor.y/255,a=e._entity._pickingColor.z/255,i._pickingColorArr=bt(i._pickingColorArr,Tt([],0,s,s,n,o,a)),s=4,n=e._qRot.x,o=e._qRot.y,a=e._qRot.z,r=e._qRot.w,i._qRotArr=bt(i._qRotArr,Tt([],0,s,s,n,o,a,r)),n=e._color.x,o=e._color.y,a=e._color.z,r=e._color.w,i._rgbaArr=bt(i._rgbaArr,Tt([],0,s,s,n,o,a,r)),s=3;let l=e.getScale();n=l.x,o=l.y,a=l.z,i._sizeArr=bt(i._sizeArr,Tt([],0,s,s,n,o,a));let h=e.getTranslate();n=h.x,o=h.y,a=h.z,i._translateArr=bt(i._translateArr,Tt([],0,s,s,n,o,a));let c=e.getLocalPosition();n=c.x,o=c.y,a=c.z,i._localPositionArr=bt(i._localPositionArr,Tt([],0,s,s,n,o,a))}_bindCommon(){let e=this._renderer,t=e.handler.programs.geo_object._program.uniforms,i=e.handler.gl,s=this._entityCollection;i.uniform3fv(t.uScaleByDistance,s.scaleByDistance),i.uniform1f(t.useLighting,s._useLighting),i.uniform3fv(t.eyePositionHigh,e.activeCamera.eyeHigh),i.uniform3fv(t.eyePositionLow,e.activeCamera.eyeLow),i.uniform3fv(t.rtcEyePositionHigh,this._rtcEyePositionHigh),i.uniform3fv(t.rtcEyePositionLow,this._rtcEyePositionLow),i.uniformMatrix4fv(t.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),i.uniformMatrix4fv(t.viewMatrix,!1,e.activeCamera.getViewMatrix()),i.uniform3fv(t.sunPosition,this._renderNode._lightPosition)}_displayOpaquePASS(){let e=this._renderer.handler.programs.geo_object,t=e._program;e.activate(),this._bindCommon();for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].drawOpaque(t)}_displayTransparentPASS(){let e=this._renderer.handler.programs.geo_object,t=e._program;e.activate(),this._bindCommon();for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].drawTransparent(t)}_depthPASS(){let e=this._renderer,t=e.handler.programs.geo_object_depth,i=t._program,s=i.uniforms,r=i.attributes,n=e.handler.gl,o=this._entityCollection,a=e.activeCamera;t.activate(),n.uniform3fv(s.uScaleByDistance,o.scaleByDistance),n.uniform3fv(s.rtcEyePositionHigh,this._rtcEyePositionHigh),n.uniform3fv(s.rtcEyePositionLow,this._rtcEyePositionLow),n.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniform1f(s.frustumPickingColor,a.frustumColorIndex);for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];n.bindBuffer(n.ARRAY_BUFFER,t._qRotBuffer),n.vertexAttribPointer(r.qRot,t._qRotBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._sizeBuffer),n.vertexAttribPointer(r.aScale,t._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._translateBuffer),n.vertexAttribPointer(r.aTranslate,t._translateBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._localPositionBuffer),n.vertexAttribPointer(r.aLocalPosition,t._localPositionBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._rtcPositionHighBuffer),n.vertexAttribPointer(r.aRTCPositionHigh,t._rtcPositionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._rtcPositionLowBuffer),n.vertexAttribPointer(r.aRTCPositionLow,t._rtcPositionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._visibleBuffer),n.vertexAttribPointer(r.aDispose,t._visibleBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._vertexBuffer),n.vertexAttribPointer(r.aVertexPosition,t._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(n.TRIANGLES,t._indicesBuffer.numItems,n.UNSIGNED_INT,0,t.numInstances)}}drawDepth(){this._geoObjects.length&&this._depthPASS()}drawPicking(){this._geoObjects.length&&this.pickingEnabled&&this._pickingPASS()}_pickingPASS(){let e=this._renderer,t=e.handler.programs.geo_object_picking,i=t._program,s=i.uniforms,r=i.attributes,n=e.handler.gl,o=this._entityCollection;t.activate(),n.uniform3fv(s.uScaleByDistance,o.scaleByDistance),n.uniform3fv(s.pickingScale,o.pickingScale),n.uniform3fv(s.rtcEyePositionHigh,this._rtcEyePositionHigh),n.uniform3fv(s.rtcEyePositionLow,this._rtcEyePositionLow),n.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix());for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];n.bindBuffer(n.ARRAY_BUFFER,t._qRotBuffer),n.vertexAttribPointer(r.qRot,t._qRotBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._sizeBuffer),n.vertexAttribPointer(r.aScale,t._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._translateBuffer),n.vertexAttribPointer(r.aTranslate,t._translateBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._localPositionBuffer),n.vertexAttribPointer(r.aLocalPosition,t._localPositionBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._pickingColorBuffer),n.vertexAttribPointer(r.aPickingColor,t._pickingColorBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._rtcPositionHighBuffer),n.vertexAttribPointer(r.aRTCPositionHigh,t._rtcPositionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._rtcPositionLowBuffer),n.vertexAttribPointer(r.aRTCPositionLow,t._rtcPositionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._visibleBuffer),n.vertexAttribPointer(r.aDispose,t._visibleBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,t._vertexBuffer),n.vertexAttribPointer(r.aVertexPosition,t._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(n.TRIANGLES,t._indicesBuffer.numItems,n.UNSIGNED_INT,0,t.numInstances)}}setQRotArr(e,t,i){Tt(e._qRotArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[Ko]=!0,this._updateTag(e)}setVisibility(e,t,i){Tt(e._visibleArr,t,1,1,i?1:0),e._changedBuffers[ta]=!0,this._updateTag(e)}setRTCPositionArr(e,t,i,s){Tt(e._rtcPositionHighArr,t,3,3,i.x,i.y,i.z),Tt(e._rtcPositionLowArr,t,3,3,s.x,s.y,s.z),e._changedBuffers[Wo]=!0,this._updateTag(e)}setRgbaArr(e,t,i){Tt(e._rgbaArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[$o]=!0,this._updateTag(e)}setPickingColorArr(e,t,i){Tt(e._pickingColorArr,t,3,3,i.x/255,i.y/255,i.z/255),e._changedBuffers[Jo]=!0,this._updateTag(e)}setScaleArr(e,t,i){Tt(e._sizeArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[Qo]=!0,this._updateTag(e)}setTranslateArr(e,t,i){Tt(e._translateArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[ia]=!0,this._updateTag(e)}setLocalPositionArr(e,t,i){Tt(e._localPositionArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[sa]=!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()}getRTCPosition(e,t,i){let s=e.sub(this._relativeCenter);v.doubleToTwoFloats(s,t,i)}setRelativeCenter(e){this._relativeCenter.copy(e);for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e].geoObjects;for(let e=0;e<t.length;e++)t[e].updateRTCPosition()}}_updateRTCEyePosition(){let e=this._renderer;if(e.activeCamera.isFirstPass){let t=e.activeCamera.eye.sub(this._relativeCenter);v.doubleToTwoFloat32Array(t,this._rtcEyePositionHigh,this._rtcEyePositionLow)}}draw(){this._geoObjects.length&&(this._updateRTCEyePosition(),this.update(),this._displayOpaquePASS())}drawTransparent(){this._geoObjects.length&&this._displayTransparentPASS()}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._geoObjects.length,this._geoObjects.push(e),this._addGeoObjectToArray(e),e.updateRotation(),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 s=!1;if(0===t.numInstances){t.clear(),this._instanceDataMap.delete(i);for(let e=0;this._instanceDataMapValues.length;e++)if(0===this._instanceDataMapValues[e].numInstances){this._instanceDataMapValues.splice(e,1);break}this._clearDataTagQueue(),s=!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,s=t.geoObjects.length;i<s;i++){let e=t.geoObjects[i];e._tagDataIndex=e._tagDataIndex-1}t._rgbaArr=Et(t._rgbaArr,4*r,4),t._rtcPositionHighArr=Et(t._rtcPositionHighArr,3*r,3),t._rtcPositionLowArr=Et(t._rtcPositionLowArr,3*r,3),t._qRotArr=Et(t._qRotArr,4*r,4),t._pickingColorArr=Et(t._pickingColorArr,3*r,3),t._sizeArr=Et(t._sizeArr,3*r,3),t._translateArr=Et(t._translateArr,3*r,3),t._localPositionArr=Et(t._localPositionArr,3*r,3),t._visibleArr=Et(t._visibleArr,r,1),e._handlerIndex=-1,e._handler=null,e._tagDataIndex=-1,e._tagData=null,s||(t.refresh(),this._updateTag(t))}};ws.__counter__=0;let Ar=ws;const ze=-1;class nl extends ns{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 X("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#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}in float a_outline;in vec4 a_gliphParam;in vec2 a_vertices;in vec4 a_texCoord;in vec3 a_positionsHigh;in vec3 a_positionsLow;in vec3 a_offset;in float a_size;in float a_rotation;in vec4 a_rgba;in float a_fontIndex;out vec2 v_uv;out vec4 v_rgba;flat out int v_fontIndex;out vec4 v_outlineColor;flat out float v_outline;uniform vec2 viewport;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float planetRadius;uniform vec3 scaleByDistance;uniform float opacity;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){if(a_texCoord.w==EMPTY){gl_Position=vec4(0.0);v_fontIndex=-1;return;}vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;v_outline=a_outline;v_fontIndex=int(a_fontIndex);v_uv=a_texCoord.xy;vec3 look=a_positions-cameraPos;float lookDist=length(look);v_rgba=a_rgba;if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(scaleByDistance[0],scaleByDistance[1],lookDist))*(1.0-step(scaleByDistance[2],lookDist));v_rgba.a*=opacity;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 vert=a_vertices;vec4 gp=a_gliphParam;if(a_texCoord.w==RTL){vert.x=step(vert.x*0.5+1.0,1.0);gp.x=-a_gliphParam.x;gp.z=-(a_gliphParam.z+a_texCoord.z);}else{gp.z=a_gliphParam.z+a_texCoord.z;}vec2 v=screenPos+rotate2d(a_rotation)*((vert*gp.xy+gp.zw)*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"#version 300 es\nuniform int isOutlinePass;precision highp float;const int MAX_SIZE=11;uniform sampler2D fontTextureArr[MAX_SIZE];uniform vec4 sdfParamsArr[MAX_SIZE];flat in int v_fontIndex;in vec2 v_uv;in vec4 v_rgba;flat in float v_outline;in vec3 v_pickingColor;layout(location=0)out vec4 outScreen;float median(float r,float g,float b){return max(min(r,g),min(max(r,g),b));}float getDistance(){vec3 msdf;if(v_fontIndex==0){msdf=texture(fontTextureArr[0],v_uv).rgb;}else if(v_fontIndex==1){msdf=texture(fontTextureArr[1],v_uv).rgb;}else if(v_fontIndex==2){msdf=texture(fontTextureArr[2],v_uv).rgb;}else if(v_fontIndex==3){msdf=texture(fontTextureArr[3],v_uv).rgb;}else if(v_fontIndex==4){msdf=texture(fontTextureArr[4],v_uv).rgb;}else if(v_fontIndex==5){msdf=texture(fontTextureArr[5],v_uv).rgb;}else if(v_fontIndex==6){msdf=texture(fontTextureArr[6],v_uv).rgb;}else if(v_fontIndex==7){msdf=texture(fontTextureArr[7],v_uv).rgb;}else if(v_fontIndex==8){msdf=texture(fontTextureArr[8],v_uv).rgb;}else if(v_fontIndex==9){msdf=texture(fontTextureArr[9],v_uv).rgb;}else if(v_fontIndex==10){msdf=texture(fontTextureArr[10],v_uv).rgb;}return median(msdf.r,msdf.g,msdf.b);}void main(){if(v_fontIndex==-1){return;}vec4 sdfParams=sdfParamsArr[v_fontIndex];float sd=getDistance();vec2 dxdy=fwidth(v_uv)*sdfParams.xy;if(isOutlinePass==0){float dist=sd+min(0.001,0.5-1.0/sdfParams.w)-0.5;float opacity=clamp(dist*sdfParams.w/length(dxdy)+0.5,0.0,1.0);if(opacity<=0.1){discard;}outScreen=vec4(v_rgba.rgb,opacity*v_rgba.a);}else{float dist=sd+min(v_outline,0.5-1.0/sdfParams.w)-0.5;float opacity=clamp(dist*sdfParams.w/length(dxdy)+0.5,0.0,1.0);if(opacity<=0.1){discard;}outScreen=vec4(v_rgba.rgb,opacity*v_rgba.a);}}"})):this._renderer.handler.addProgram(new X("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:"#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}attribute float a_outline;attribute vec4 a_gliphParam;attribute vec2 a_vertices;attribute vec4 a_texCoord;attribute vec3 a_positionsHigh;attribute vec3 a_positionsLow;attribute vec3 a_offset;attribute float a_size;attribute float a_rotation;attribute vec4 a_rgba;attribute float a_fontIndex;varying float v_outline;varying vec2 v_uv;varying vec4 v_rgba;varying float v_fontIndex;uniform vec2 viewport;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float planetRadius;uniform vec3 scaleByDistance;uniform float opacity;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){if(a_texCoord.w==EMPTY){gl_Position=vec4(0.0);v_fontIndex=-1.0;return;}vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;v_outline=a_outline;v_uv=vec2(a_texCoord.xy);v_rgba=a_rgba;v_fontIndex=a_fontIndex;vec3 look=a_positions-cameraPos;float lookDist=length(look);if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(scaleByDistance[0],scaleByDistance[1],lookDist))*(1.0-step(scaleByDistance[2],lookDist));v_rgba.a*=opacity;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 vert=a_vertices;vec4 gp=a_gliphParam;if(a_texCoord.w==RTL){vert.x=step(vert.x*0.5+1.0,1.0);gp.x=-a_gliphParam.x;gp.z=-(a_gliphParam.z+a_texCoord.z);}else{gp.z=a_gliphParam.z+a_texCoord.z;}vec2 v=screenPos+rotate2d(a_rotation)*((vert*gp.xy+gp.zw)*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"#extension GL_OES_standard_derivatives: enable\nprecision highp float;precision highp int;const int MAX_SIZE=11;uniform sampler2D fontTextureArr[MAX_SIZE];uniform vec4 sdfParamsArr[MAX_SIZE];uniform int isOutlinePass;varying float v_outline;varying vec2 v_uv;varying vec4 v_rgba;varying float v_fontIndex;float fontIndex;float median(float r,float g,float b){return max(min(r,g),min(max(r,g),b));}float getDistance(){vec3 msdf;if(fontIndex>=0.0&&fontIndex<1.0){msdf=texture2D(fontTextureArr[0],v_uv).rgb;}else if(fontIndex>=1.0&&fontIndex<2.0){msdf=texture2D(fontTextureArr[1],v_uv).rgb;}else if(fontIndex>=2.0&&fontIndex<3.0){msdf=texture2D(fontTextureArr[2],v_uv).rgb;}else if(fontIndex>=3.0&&fontIndex<4.0){msdf=texture2D(fontTextureArr[3],v_uv).rgb;}else if(fontIndex>=4.0&&fontIndex<5.0){msdf=texture2D(fontTextureArr[4],v_uv).rgb;}else if(fontIndex>=5.0&&fontIndex<6.0){msdf=texture2D(fontTextureArr[5],v_uv).rgb;}else if(fontIndex>=6.0&&fontIndex<7.0){msdf=texture2D(fontTextureArr[6],v_uv).rgb;}else if(fontIndex>=7.0&&fontIndex<8.0){msdf=texture2D(fontTextureArr[7],v_uv).rgb;}else if(fontIndex>=8.0&&fontIndex<9.0){msdf=texture2D(fontTextureArr[8],v_uv).rgb;}else if(fontIndex>=9.0&&fontIndex<10.0){msdf=texture2D(fontTextureArr[9],v_uv).rgb;}else if(fontIndex>=10.0&&fontIndex<11.0){msdf=texture2D(fontTextureArr[10],v_uv).rgb;}return median(msdf.r,msdf.g,msdf.b);}vec4 getSDFParams(){if(fontIndex>=0.0&&fontIndex<1.0){return sdfParamsArr[0];}else if(fontIndex>=1.0&&fontIndex<2.0){return sdfParamsArr[1];}else if(fontIndex>=2.0&&fontIndex<3.0){return sdfParamsArr[2];}else if(fontIndex>=3.0&&fontIndex<4.0){return sdfParamsArr[3];}else if(fontIndex>=4.0&&fontIndex<5.0){return sdfParamsArr[4];}else if(fontIndex>=5.0&&fontIndex<6.0){return sdfParamsArr[5];}else if(fontIndex>=6.0&&fontIndex<7.0){return sdfParamsArr[6];}else if(fontIndex>=7.0&&fontIndex<8.0){return sdfParamsArr[7];}else if(fontIndex>=8.0&&fontIndex<9.0){return sdfParamsArr[8];}else if(fontIndex>=9.0&&fontIndex<10.0){return sdfParamsArr[9];}else if(fontIndex>=10.0&&fontIndex<11.0){return sdfParamsArr[10];}}void main(){fontIndex=v_fontIndex+0.1;if(v_fontIndex<0.0){return;}vec4 sdfParams=getSDFParams();float sd=getDistance();vec2 dxdy=fwidth(v_uv)*sdfParams.xy;float dist=sd+min(0.001,0.5-1.0/sdfParams.w)-0.5;float opacity=clamp(dist*sdfParams.w/length(dxdy)+0.5,0.0,1.0);if(isOutlinePass==0){}else{float strokeDist=sd+min(v_outline,0.5-1.0/sdfParams.w)-0.5;float strokeAlpha=v_rgba.a*clamp(strokeDist*sdfParams.w/length(dxdy)+0.5,0.0,1.0);if(strokeAlpha<0.1){discard;}}}"}))),this._renderer.handler.programs.labelPicking||this._renderer.handler.addProgram(new X("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:"#define EMPTY - 1.0\n#define RTL 1.0\nvec2 project(vec4 p,vec2 viewport){return(0.5*p.xyz/p.w+0.5).xy*viewport;}mat2 rotate2d(float angle){return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));}attribute vec4 a_gliphParam;attribute vec2 a_vertices;attribute vec4 a_texCoord;attribute vec3 a_positionsHigh;attribute vec3 a_positionsLow;attribute vec3 a_offset;attribute float a_size;attribute float a_rotation;attribute vec4 a_rgba;varying vec4 v_rgba;uniform vec2 viewport;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float planetRadius;uniform vec3 scaleByDistance;uniform float opacity;uniform float depthOffset;const vec3 ZERO3=vec3(0.0);void main(){vec3 a_positions=a_positionsHigh+a_positionsLow;vec3 cameraPos=eyePositionHigh+eyePositionLow;v_rgba=a_rgba;if(a_texCoord.w==EMPTY){v_rgba.a=0.0;gl_Position=vec4(0.0);return;}vec3 look=a_positions-cameraPos;float lookDist=length(look);if(opacity*step(lookDist,sqrt(dot(cameraPos,cameraPos)-planetRadius)+sqrt(dot(a_positions,a_positions)-planetRadius))==0.0){return;}float scd=(1.0-smoothstep(scaleByDistance[0],scaleByDistance[1],lookDist))*(1.0-step(scaleByDistance[2],lookDist));v_rgba.a*=opacity;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff=a_positionsHigh-eyePositionHigh;vec3 lowDiff=a_positionsLow-eyePositionLow;vec4 posRTE=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec4 projPos=projectionMatrix*posRTE;float camSlope=dot(vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2]),normalize(cameraPos));if(camSlope>0.5){float dist=dot(look,normalize(cameraPos));projPos.z+=dist*0.02;}else{projPos.z+=-(abs(projPos.z))*0.002;}projPos.z+=depthOffset+a_offset.z;vec2 screenPos=project(projPos,viewport);vec2 vert=a_vertices;vec4 gp=a_gliphParam;if(a_texCoord.w==RTL){vert.x=step(vert.x*0.5+1.0,1.0);gp.x=-a_gliphParam.x;gp.z=-(a_gliphParam.z+a_texCoord.z);}else{gp.z=a_gliphParam.z+a_texCoord.z;}vec2 v=screenPos+rotate2d(a_rotation)*((vert*gp.xy+gp.zw)*a_size*scd+a_offset.xy);gl_Position=vec4((2.0*v/viewport-1.0)*projPos.w,projPos.z,projPos.w);}",fragmentShader:"precision highp float;varying vec4 v_rgba;varying vec3 v_pickingColor;void main(){vec4 color=v_rgba;if(color.a<0.05){return;}gl_FragColor=vec4(v_rgba.rgb,v_rgba.a);}"})))}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){-1!==t._lockId&&t._handler&&this.isEqual(t._handler)&&(t._isReady=!0,t._lockId=-1,t._handlerIndex=this._billboards.length,this._billboards.push(t),this._vertexArr=it(this._vertexArr,e.vertexArr),this._texCoordArr=it(this._texCoordArr,e.texCoordArr),this._gliphParamArr=it(this._gliphParamArr,e.gliphParamArr),this._positionHighArr=it(this._positionHighArr,e.positionHighArr),this._positionLowArr=it(this._positionLowArr,e.positionLowArr),this._sizeArr=it(this._sizeArr,e.sizeArr),this._offsetArr=it(this._offsetArr,e.offsetArr),this._rgbaArr=it(this._rgbaArr,e.rgbaArr),this._rotationArr=it(this._rotationArr,e.rotationArr),this._fontIndexArr=it(this._fontIndexArr,e.fontIndexArr),this._outlineArr=it(this._outlineArr,e.outlineArr),this._outlineColorArr=it(this._outlineColorArr,e.outlineColorArr),this._pickingColorArr=it(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,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection;n.disable(n.CULL_FACE),n.uniform1iv(r.fontTextureArr,e.fontAtlas.samplerArr),n.uniform4fv(r.sdfParamsArr,e.fontAtlas.sdfParamsArr),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform3fv(r.scaleByDistance,o.scaleByDistance),n.uniform1f(r.opacity,o._fadingOpacity),n.uniform1f(r.planetRadius,o.renderNode._planetRadius2||0),n.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),n.bindBuffer(n.ARRAY_BUFFER,this._texCoordBuffer),n.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._gliphParamBuffer),n.vertexAttribPointer(s.a_gliphParam,this._gliphParamBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionHighBuffer),n.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionLowBuffer),n.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._sizeBuffer),n.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._rotationBuffer),n.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._offsetBuffer),n.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._fontIndexBuffer),n.vertexAttribPointer(s.a_fontIndex,this._fontIndexBuffer.itemSize,n.FLOAT,!1,0,0),n.uniform1i(r.isOutlinePass,1),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.bindBuffer(n.ARRAY_BUFFER,this._outlineColorBuffer),n.vertexAttribPointer(s.a_rgba,this._outlineColorBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._outlineBuffer),n.vertexAttribPointer(s.a_outline,this._outlineBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.depthFunc(n.EQUAL),n.uniform1i(r.isOutlinePass,0),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.bindBuffer(n.ARRAY_BUFFER,this._rgbaBuffer),n.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.depthFunc(n.LESS),n.enable(n.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.labelPicking.activate();let i=t.programs.labelPicking._program,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection,a=o.renderNode;n.disable(n.CULL_FACE),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform3fv(r.scaleByDistance,o.scaleByDistance),n.uniform1f(r.opacity,o._fadingOpacity),n.uniform1f(r.planetRadius,a._planetRadius2||0),n.uniform2fv(r.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),n.bindBuffer(n.ARRAY_BUFFER,this._texCoordBuffer),n.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._gliphParamBuffer),n.vertexAttribPointer(s.a_gliphParam,this._gliphParamBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionHighBuffer),n.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._positionLowBuffer),n.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._sizeBuffer),n.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._rotationBuffer),n.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._offsetBuffer),n.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._pickingColorBuffer),n.vertexAttribPointer(s.a_rgba,this._pickingColorBuffer.itemSize,n.FLOAT,!1,0,0),n.uniform1f(r.depthOffset,o.polygonOffsetUnits),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.enable(n.CULL_FACE)}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*this._maxLetters,s=t*i;this._rgbaArr=ot(this._rgbaArr,s,i),this._outlineColorArr=ot(this._outlineColorArr,s,i),this._texCoordArr=ot(this._texCoordArr,s,i),this._gliphParamArr=ot(this._gliphParamArr,s,i),i=18*this._maxLetters,s=t*i,this._positionHighArr=ot(this._positionHighArr,s,i),this._positionLowArr=ot(this._positionLowArr,s,i),this._offsetArr=ot(this._offsetArr,s,i),this._pickingColorArr=ot(this._pickingColorArr,s,i),i=12*this._maxLetters,s=t*i,this._vertexArr=ot(this._vertexArr,s,i),i=6*this._maxLetters,s=t*i,this._sizeArr=ot(this._sizeArr,s,i),this._rotationArr=ot(this._rotationArr,s,i),this._fontIndexArr=ot(this._fontIndexArr,s,i),this._outlineArr=ot(this._outlineArr,s,i),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1}setText(e,t,i,s,r=0,n=!1){t=t.normalize("NFKC");let o=this._renderer.fontAtlas.atlasesArr[i];if(!o)return;let a=24*e*this._maxLetters,l=this._texCoordArr,h=this._gliphParamArr,c=0,d=Math.min(this._maxLetters,t.length),_=0;n&&(_=1);let u=0,f=o.kernings;for(c=0;c<d;c++){let e=a+24*c,i=t[c],s=o.get(i.charCodeAt(0))||o.get(32);if(!s)continue;let n=s.texCoords,d=s.metrics;l[e]=n[0],l[e+1]=n[1],l[e+2]=u,l[e+3]=_,l[e+4]=n[2],l[e+5]=n[3],l[e+6]=u,l[e+7]=_,l[e+8]=n[4],l[e+9]=n[5],l[e+10]=u,l[e+11]=_,l[e+12]=n[6],l[e+13]=n[7],l[e+14]=u,l[e+15]=_,l[e+16]=n[8],l[e+17]=n[9],l[e+18]=u,l[e+19]=_,l[e+20]=n[10],l[e+21]=n[11],l[e+22]=u,l[e+23]=_,h[e]=d.nWidth,h[e+1]=d.nHeight,h[e+2]=d.nXOffset,h[e+3]=d.nYOffset,h[e+4]=d.nWidth,h[e+5]=d.nHeight,h[e+6]=d.nXOffset,h[e+7]=d.nYOffset,h[e+8]=d.nWidth,h[e+9]=d.nHeight,h[e+10]=d.nXOffset,h[e+11]=d.nYOffset,h[e+12]=d.nWidth,h[e+13]=d.nHeight,h[e+14]=d.nXOffset,h[e+15]=d.nYOffset,h[e+16]=d.nWidth,h[e+17]=d.nHeight,h[e+18]=d.nXOffset,h[e+19]=d.nYOffset,h[e+20]=d.nWidth,h[e+21]=d.nHeight,h[e+22]=d.nXOffset,h[e+23]=d.nYOffset;let g=f[i.charCodeAt(0)];if(g&&t[c+1]){let e=g[t[c+1].charCodeAt(0)];u+=e?d.nAdvance+e+r:d.nAdvance+r}else u+=d.nAdvance+r}if(s===_i.CENTER)for(u*=-.5,c=0;c<d;c++){let e=a+24*c;l[e+2]+=u,l[e+6]+=u,l[e+10]+=u,l[e+14]+=u,l[e+18]+=u,l[e+22]+=u}for(;c<this._maxLetters;c++){let e=a+24*c;l[e+3]=-1,l[e+7]=-1,l[e+11]=-1,l[e+15]=-1,l[e+19]=-1,l[e+23]=-1}this._changedBuffers[6]=!0}setPositionArr(e,t,i){let s=18*e*this._maxLetters,r=this._positionHighArr,n=t.x,o=t.y,a=t.z,l=this._positionLowArr,h=i.x,c=i.y,d=i.z;for(let e=0;e<this._maxLetters;e++){let t=s+18*e;r[t]=n,r[t+1]=o,r[t+2]=a,r[t+3]=n,r[t+4]=o,r[t+5]=a,r[t+6]=n,r[t+7]=o,r[t+8]=a,r[t+9]=n,r[t+10]=o,r[t+11]=a,r[t+12]=n,r[t+13]=o,r[t+14]=a,r[t+15]=n,r[t+16]=o,r[t+17]=a,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,s=this._pickingColorArr,r=t.x/255,n=t.y/255,o=t.z/255;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;s[t]=r,s[t+1]=n,s[t+2]=o,s[t+3]=r,s[t+4]=n,s[t+5]=o,s[t+6]=r,s[t+7]=n,s[t+8]=o,s[t+9]=r,s[t+10]=n,s[t+11]=o,s[t+12]=r,s[t+13]=n,s[t+14]=o,s[t+15]=r,s[t+16]=n,s[t+17]=o}this._changedBuffers[0]=!0}setSizeArr(e,t){let i=6*e*this._maxLetters,s=this._sizeArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;s[r]=t,s[r+1]=t,s[r+2]=t,s[r+3]=t,s[r+4]=t,s[r+5]=t}this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e*this._maxLetters,s=this._offsetArr,r=t.x,n=t.y,o=t.z;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;s[t]=r,s[t+1]=n,s[t+2]=o,s[t+3]=r,s[t+4]=n,s[t+5]=o,s[t+6]=r,s[t+7]=n,s[t+8]=o,s[t+9]=r,s[t+10]=n,s[t+11]=o,s[t+12]=r,s[t+13]=n,s[t+14]=o,s[t+15]=r,s[t+16]=n,s[t+17]=o}this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e*this._maxLetters,s=this._rgbaArr,r=t.x,n=t.y,o=t.z,a=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;s[t]=r,s[t+1]=n,s[t+2]=o,s[t+3]=a,s[t+4]=r,s[t+5]=n,s[t+6]=o,s[t+7]=a,s[t+8]=r,s[t+9]=n,s[t+10]=o,s[t+11]=a,s[t+12]=r,s[t+13]=n,s[t+14]=o,s[t+15]=a,s[t+16]=r,s[t+17]=n,s[t+18]=o,s[t+19]=a,s[t+20]=r,s[t+21]=n,s[t+22]=o,s[t+23]=a}this._changedBuffers[4]=!0}setOutlineColorArr(e,t){let i=24*e*this._maxLetters,s=this._outlineColorArr,r=t.x,n=t.y,o=t.z,a=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;s[t]=r,s[t+1]=n,s[t+2]=o,s[t+3]=a,s[t+4]=r,s[t+5]=n,s[t+6]=o,s[t+7]=a,s[t+8]=r,s[t+9]=n,s[t+10]=o,s[t+11]=a,s[t+12]=r,s[t+13]=n,s[t+14]=o,s[t+15]=a,s[t+16]=r,s[t+17]=n,s[t+18]=o,s[t+19]=a,s[t+20]=r,s[t+21]=n,s[t+22]=o,s[t+23]=a}this._changedBuffers[10]=!0}setOutlineArr(e,t){let i=6*e*this._maxLetters,s=this._outlineArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;s[r]=t,s[r+1]=t,s[r+2]=t,s[r+3]=t,s[r+4]=t,s[r+5]=t}this._changedBuffers[9]=!0}setRotationArr(e,t){let i=6*e*this._maxLetters,s=this._rotationArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;s[r]=t,s[r+1]=t,s[r+2]=t,s[r+3]=t,s[r+4]=t,s[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,s=this._vertexArr;for(let e=0;e<this._maxLetters;e++){let r=i+12*e;s[r]=t[0],s[r+1]=t[1],s[r+2]=t[2],s[r+3]=t[3],s[r+4]=t[4],s[r+5]=t[5],s[r+6]=t[6],s[r+7]=t[7],s[r+8]=t[8],s[r+9]=t[9],s[r+10]=t[10],s[r+11]=t[11]}this._changedBuffers[7]=!0}setFontIndexArr(e,t){let i=6*e*this._maxLetters,s=this._fontIndexArr;for(let e=0;e<this._maxLetters;e++){let r=i+6*e;s[r]=t,s[r+1]=t,s[r+2]=t,s[r+3]=t,s[r+4]=t,s[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}}const Ts=class e{constructor(t){this.pickingEnabled=!0,this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,this._renderer=null,this._pointClouds=[]}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.pointCloud||this._renderer.handler.addProgram(new X("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=[]}};Ts.__counter__=0;let Lr=Ts;const Cs=class e{constructor(t){this.__id=e.__counter__++,this._entityCollection=t,this._renderer=null,this._polylines=[],this.pickingEnabled=!0,this._relativeCenter=new v,this._rtcEyePositionHigh=new Float32Array([0,0,0]),this._rtcEyePositionLow=new Float32Array([0,0,0])}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.polyline_screen||this._renderer.handler.addProgram(new X("polyline_screen",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",thickness:"float",opacity:"float",depthOffset:"float",visibleSphere:"vec4",texAtlas:"sampler2d",strokeSize:"float",texOffset:"float"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float",color:"vec4",texCoord:"vec4"},vertexShader:"#version 300 es\nprecision highp float;in vec3 prevHigh;in vec3 currentHigh;in vec3 nextHigh;in vec3 prevLow;in vec3 currentLow;in vec3 nextLow;in vec4 texCoord;in float order;in vec4 color;uniform float thickness;uniform mat4 proj;uniform mat4 view;uniform vec2 viewport;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;uniform float opacity;uniform float depthOffset;uniform float strokeSize;uniform float texOffset;out vec4 v_rgba;out vec3 vPos;out vec3 uCamPos;out vec4 vTexCoord;flat out float repeat;flat out float v_texOffset;const float NEAR=-1.0;vec2 getIntersection(vec2 start1,vec2 end1,vec2 start2,vec2 end2){vec2 dir=end2-start2;vec2 perp=vec2(-dir.y,dir.x);float d2=dot(perp,start2);float seg=dot(perp,start1)-d2;float prl=seg-dot(perp,end1)+d2;if(prl>-1.0&&prl<1.0){return start1;}float u=seg/prl;return start1+u*(end1-start1);}vec2 project(vec4 p){return(0.5*p.xyz/p.w+0.5).xy*viewport;}void main(){uCamPos=rtcEyePositionHigh+rtcEyePositionLow;vPos=currentHigh+currentLow;v_rgba=vec4(color.rgb,color.a*opacity);mat4 viewMatrixRTE=view;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);vec3 highDiff,lowDiff;highDiff=currentHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=currentLow-rtcEyePositionLow;vec4 vCurrent=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=prevHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=prevLow-rtcEyePositionLow;vec4 vPrev=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=nextHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=nextLow-rtcEyePositionLow;vec4 vNext=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);if(vCurrent.z>NEAR){if(vPrev.z<NEAR&&abs(order)==1.0){vCurrent=vPrev+(vCurrent-vPrev)*(NEAR-vPrev.z)/(vCurrent.z-vPrev.z);}else if(vNext.z<NEAR&&abs(order)==2.0){vCurrent=vNext+(vCurrent-vNext)*(NEAR-vNext.z)/(vCurrent.z-vNext.z);}}vec4 dCurrent=proj*vCurrent;vec2 _next=project(proj*vNext);vec2 _prev=project(proj*vPrev);vec2 _current=project(dCurrent);if(_prev==_current){if(_next==_current){_next=_current+vec2(1.0,0.0);_prev=_current-_next;}else{_prev=_current+normalize(_current-_next);}}if(_next==_current){_next=_current+normalize(_current-_prev);}vec2 sNext=_next,sCurrent=_current,sPrev=_prev;vec2 dirNext=normalize(sNext-sCurrent);vec2 dirPrev=normalize(sPrev-sCurrent);float dotNP=dot(dirNext,dirPrev);vec2 normalNext=normalize(vec2(-dirNext.y,dirNext.x));vec2 normalPrev=normalize(vec2(dirPrev.y,-dirPrev.x));float d=thickness*sign(order);vTexCoord=texCoord;vec2 m;if(dotNP>=0.99991){m=sCurrent-normalPrev*d;}else{m=getIntersection(sCurrent+normalPrev*d,sPrev+normalPrev*d,sCurrent+normalNext*d,sNext+normalNext*d);if(dotNP>0.5&&dot(dirNext+dirPrev,m-sCurrent)<0.0){float occw=order*sign(dirNext.x*dirPrev.y-dirNext.y*dirPrev.x);if(occw==-1.0){m=sCurrent+normalPrev*d;}else if(occw==1.0){m=sCurrent+normalNext*d;}else if(occw==-2.0){m=sCurrent+normalNext*d;}else if(occw==2.0){m=sCurrent+normalPrev*d;}}else if(distance(sCurrent,m)>min(distance(sCurrent,sNext),distance(sCurrent,sPrev))){m=sCurrent+normalNext*d;}}repeat=min(distance(sCurrent,sPrev),viewport.y)/strokeSize;v_texOffset=texOffset;gl_Position=vec4((2.0*m/viewport-1.0)*dCurrent.w,dCurrent.z+depthOffset,dCurrent.w);}",fragmentShader:"#version 300 es\nprecision highp float;uniform sampler2D texAtlas;uniform vec4 visibleSphere;in vec3 uCamPos;in vec4 v_rgba;in vec3 vPos;in vec4 vTexCoord;flat in float repeat;flat in float v_texOffset;out vec4 fragColor;void main(){if(visibleSphere.w!=0.0){vec3 cam_dir=normalize(vPos-uCamPos);vec3 sph_dir=normalize(vPos-visibleSphere.xyz);if(dot(cam_dir,sph_dir)>0.11){discard;}}float height=vTexCoord.w;if(height==0.0){fragColor=vec4(v_rgba.rgb,v_rgba.a);}else{vec2 uv=vTexCoord.xy;float min=vTexCoord.z;float EPS=0.5/1024.0;float localY=fract((uv.y+v_texOffset-min)/height*repeat);uv.y=clamp(min+localY*height,min+EPS,min+height-EPS);vec4 color=texture(texAtlas,uv);color.a*=v_rgba.a;fragColor=color;}}"})),this._renderer.handler.programs.polyline_picking||this._renderer.handler.addProgram(new X("polyline_picking",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",color:"vec4",thickness:"float",depthOffset:"float",visibleSphere:"vec4"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float"},vertexShader:"precision highp float;attribute vec3 prevHigh;attribute vec3 currentHigh;attribute vec3 nextHigh;attribute vec3 prevLow;attribute vec3 currentLow;attribute vec3 nextLow;attribute float order;uniform float thickness;uniform vec4 color;uniform mat4 proj;uniform mat4 view;uniform vec2 viewport;uniform vec3 rtcEyePositionHigh;uniform vec3 rtcEyePositionLow;uniform float depthOffset;varying vec4 vColor;varying vec3 vPos;varying vec3 uCamPos;const float NEAR=-1.0;vec2 getIntersection(vec2 start1,vec2 end1,vec2 start2,vec2 end2){vec2 dir=end2-start2;vec2 perp=vec2(-dir.y,dir.x);float d2=dot(perp,start2);float seg=dot(perp,start1)-d2;float prl=seg-dot(perp,end1)+d2;if(prl>-1.0&&prl<1.0){return start1;}float u=seg/prl;return start1+u*(end1-start1);}vec2 project(vec4 p){return(0.5*p.xyz/p.w+0.5).xy*viewport;}void main(){uCamPos=rtcEyePositionHigh+rtcEyePositionLow;vPos=currentHigh+currentLow;vColor=color;vec3 highDiff,lowDiff;mat4 viewMatrixRTE=view;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);highDiff=currentHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=currentLow-rtcEyePositionLow;vec4 vCurrent=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=prevHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=prevLow-rtcEyePositionLow;vec4 vPrev=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=nextHigh-rtcEyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=nextLow-rtcEyePositionLow;vec4 vNext=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);if(vCurrent.z>NEAR){if(vPrev.z<NEAR&&abs(order)==1.0){vCurrent=vPrev+(vCurrent-vPrev)*(NEAR-vPrev.z)/(vCurrent.z-vPrev.z);}else if(vNext.z<NEAR&&abs(order)==2.0){vCurrent=vNext+(vCurrent-vNext)*(NEAR-vNext.z)/(vCurrent.z-vNext.z);}}vec4 dCurrent=proj*vCurrent;vec2 _next=project(proj*vNext);vec2 _prev=project(proj*vPrev);vec2 _current=project(dCurrent);if(_prev==_current){if(_next==_current){_next=_current+vec2(1.0,0.0);_prev=_current-_next;}else{_prev=_current+normalize(_current-_next);}}if(_next==_current){_next=_current+normalize(_current-_prev);}vec2 sNext=_next,sCurrent=_current,sPrev=_prev;vec2 dirNext=normalize(sNext-sCurrent);vec2 dirPrev=normalize(sPrev-sCurrent);float dotNP=dot(dirNext,dirPrev);vec2 normalNext=normalize(vec2(-dirNext.y,dirNext.x));vec2 normalPrev=normalize(vec2(dirPrev.y,-dirPrev.x));float d=thickness*sign(order);vec2 m;if(dotNP>=0.99991){m=sCurrent-normalPrev*d;}else{m=getIntersection(sCurrent+normalPrev*d,sPrev+normalPrev*d,sCurrent+normalNext*d,sNext+normalNext*d);if(dotNP>0.5&&dot(dirNext+dirPrev,m-sCurrent)<0.0){float occw=order*sign(dirNext.x*dirPrev.y-dirNext.y*dirPrev.x);if(occw==-1.0){m=sCurrent+normalPrev*d;}else if(occw==1.0){m=sCurrent+normalNext*d;}else if(occw==-2.0){m=sCurrent+normalNext*d;}else if(occw==2.0){m=sCurrent+normalPrev*d;}}else if(distance(sCurrent,m)>min(distance(sCurrent,sNext),distance(sCurrent,sPrev))){m=sCurrent+normalNext*d;}}gl_Position=vec4((2.0*m/viewport-1.0)*dCurrent.w,dCurrent.z+depthOffset,dCurrent.w);}",fragmentShader:"precision highp float;uniform vec4 visibleSphere;varying vec3 uCamPos;varying vec4 vColor;varying vec3 vPos;void main(){if(visibleSphere.w!=0.0){vec3 cam_dir=normalize(vPos-uCamPos);vec3 sph_dir=normalize(vPos-visibleSphere.xyz);if(dot(cam_dir,sph_dir)>0.11){discard;}}gl_FragColor=vec4(vColor.rgb,vColor.a);}"})))}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,e.__doubleToTwoFloats=this.getRTCPosition.bind(this),this._polylines.push(e),this._entityCollection&&this._entityCollection.renderNode&&(e.setRenderNode(this._entityCollection.renderNode),e.updateRTCPosition()))}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(){this._updateRTCEyePosition();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=[]}getRTCPosition(e,t,i){let s=e.sub(this._relativeCenter);v.doubleToTwoFloats(s,t,i)}setRelativeCenter(e){this._relativeCenter.copy(e);for(let e=0;e<this._polylines.length;e++)this._polylines[e].updateRTCPosition()}_updateRTCEyePosition(){let e=this._renderer;if(e.activeCamera.isFirstPass){let t=e.activeCamera.eye.sub(this._relativeCenter);v.doubleToTwoFloat32Array(t,this._rtcEyePositionHigh,this._rtcEyePositionLow)}}reloadTextures(){for(let e=0;e<this._polylines.length;e++){let t=this._polylines[e];t.setSrc(t.getSrc())}}get polylines(){return[...this._polylines]}refreshTexCoordsArr(){if(this._entityCollection&&this._renderer){let e=this._renderer.strokeTextureAtlas;for(let t=0;t<this._polylines.length;t++){let i=this._polylines[t],s=i.getImage();if(s){let t=e.get(s.__nodeIndex);t&&i._setTexCoordArr(t.texCoords)}}}}};Cs.__counter__=0;let Pr=Cs;const Es=class e{constructor(t){this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,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._texCoordBuffer=null,this._texOffsetBuffer=null,this._strokeSizeBuffer=null,this._vertexArr=[],this._startPositionHighArr=[],this._startPositionLowArr=[],this._endPositionHighArr=[],this._endPositionLowArr=[],this._thicknessArr=[],this._rgbaArr=[],this._pickingColorArr=[],this._texCoordArr=new Float32Array([]),this._texOffsetArr=new Float32Array([]),this._strokeSizeArr=new Float32Array([]),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._buffersUpdateCallbacks[6]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[7]=this.createTexOffsetBuffer,this._buffersUpdateCallbacks[8]=this.createStrokeSizeBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}reloadTextures(){for(let e=0;e<this._rays.length;e++){let t=this._rays[e];t.setSrc(t.getSrc())}}get rays(){return[...this._rays]}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.rayScreen||this._renderer.handler.addProgram(new X("rayScreen",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",resolution:"float",uOpacity:"float",texAtlas:"sampler2d",viewport:"vec2"},attributes:{a_vertices:"vec2",a_texCoord:"vec4",a_startPosHigh:"vec3",a_startPosLow:"vec3",a_endPosHigh:"vec3",a_endPosLow:"vec3",a_thickness:"float",a_rgba:"vec4",a_texOffset:"float",a_strokeSize:"float"},vertexShader:"#version 300 es\nprecision highp float;in vec4 a_rgba;in vec3 a_startPosHigh;in vec3 a_startPosLow;in vec3 a_endPosHigh;in vec3 a_endPosLow;in vec2 a_vertices;in float a_thickness;in vec4 a_texCoord;in float a_texOffset;in float a_strokeSize;out vec4 v_rgba;out vec4 v_texCoord;out float v_texOffset;flat out float repeat;uniform mat4 viewMatrix;uniform mat4 projectionMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float resolution;uniform float uOpacity;uniform vec2 viewport;vec2 project(vec4 p){return(0.5*p.xyz/p.w+0.5).xy*viewport;}void main(){v_texOffset=a_texOffset;v_rgba=vec4(a_rgba.rgb,a_rgba.a*uOpacity);v_texCoord=a_texCoord;vec3 v=(a_endPosHigh-a_startPosHigh)+(a_endPosLow-a_startPosLow);vec3 look=(a_startPosHigh-eyePositionHigh)+(a_startPosLow-eyePositionLow)+v*a_vertices.y;vec3 up=normalize(v);vec3 right=normalize(cross(look,up));float dist=abs(dot(look,vec3(viewMatrix[0][2],viewMatrix[1][2],viewMatrix[2][2])));float focalSize=2.0*dist*resolution;vec3 vert=right*a_thickness*focalSize*a_vertices.x;vec3 highDiff;if(a_vertices.y==0.0){highDiff=a_startPosHigh-eyePositionHigh;vert+=a_startPosLow-eyePositionLow;}else{highDiff=a_endPosHigh-eyePositionHigh;vert+=a_endPosLow-eyePositionLow;}mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff*step(1.0,length(highDiff))+vert,1.0);highDiff=a_startPosHigh-eyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));vec3 lowDiff=a_startPosLow-eyePositionLow;vec4 vStart=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);highDiff=a_endPosHigh-eyePositionHigh;highDiff=highDiff*step(1.0,length(highDiff));lowDiff=a_endPosLow-eyePositionLow;vec4 vEnd=viewMatrixRTE*vec4(highDiff+lowDiff,1.0);vec2 nStart=project(projectionMatrix*vStart);vec2 nEnd=project(projectionMatrix*vEnd);repeat=min(distance(nStart,nEnd),viewport.y)/a_strokeSize;}",fragmentShader:"#version 300 es\nprecision highp float;uniform sampler2D texAtlas;in vec4 v_rgba;in vec4 v_texCoord;in float v_texOffset;flat in float repeat;out vec4 fragColor;void main(){float height=v_texCoord.w;if(height==0.0){fragColor=v_rgba;}else{vec2 uv=v_texCoord.xy;float min=v_texCoord.z;float EPS=0.5/1024.0;float localY=fract((uv.y+v_texOffset-min)/height*repeat);uv.y=clamp(min+localY*height,min+EPS,min+height-EPS);vec4 color=texture(texAtlas,uv);fragColor=v_rgba*color;}}"})))}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._texCoordArr=null,this._texOffsetArr=null,this._strokeSizeArr=null,this._vertexArr=new Float32Array([]),this._texCoordArr=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._texOffsetArr=new Float32Array([]),this._strokeSizeArr=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),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._texOffsetBuffer),e.deleteBuffer(this._strokeSizeBuffer)),this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._texOffsetBuffer=null,this._strokeSizeBuffer=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=bt(this._vertexArr,[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]):this._vertexArr=bt(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t=e.texOffset;this._texOffsetArr=it(this._texOffsetArr,[t,t,t,t,t,t]),t=e.strokeSize,this._strokeSizeArr=it(this._strokeSizeArr,[t,t,t,t,t,t]),this._texCoordArr=it(this._texCoordArr,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),t=e._startPositionHigh.x;let i=e._startPositionHigh.y,s=e._startPositionHigh.z;this._startPositionHighArr=bt(this._startPositionHighArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._startPositionLow.x,i=e._startPositionLow.y,s=e._startPositionLow.z,this._startPositionLowArr=bt(this._startPositionLowArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._endPositionHigh.x,i=e._endPositionHigh.y,s=e._endPositionHigh.z,this._endPositionHighArr=bt(this._endPositionHighArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._endPositionLow.x,i=e._endPositionLow.y,s=e._endPositionLow.z,this._endPositionLowArr=bt(this._endPositionLowArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._thickness,this._thicknessArr=bt(this._thicknessArr,[t,t,t,t,t,t]);let r=e._startColor.x,n=e._startColor.y,o=e._startColor.z,a=e._startColor.w,l=e._endColor.x,h=e._endColor.y,c=e._endColor.z,d=e._endColor.w;this._rgbaArr=bt(this._rgbaArr,[l,h,c,d,r,n,o,a,r,n,o,a,r,n,o,a,l,h,c,d,l,h,c,d]),t=e._entity._pickingColor.x/255,i=e._entity._pickingColor.y/255,s=e._entity._pickingColor.z/255,this._pickingColorArr=bt(this._pickingColorArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s])}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.rayScreen.activate();let i=t.programs.rayScreen._program,s=i.attributes,r=i.uniforms,n=t.gl,o=this._entityCollection;n.disable(n.CULL_FACE),n.uniform1f(r.uOpacity,o._fadingOpacity),n.uniform1i(r.u_texAtlas,0),n.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),n.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),n.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),n.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),n.uniform1f(r.resolution,e.activeCamera._tanViewAngle_hradOneByHeight),n.uniform2fv(r.viewport,[e.handler.canvas.width,e.handler.canvas.height]),n.bindBuffer(n.ARRAY_BUFFER,this._startPositionHighBuffer),n.vertexAttribPointer(s.a_startPosHigh,this._startPositionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._startPositionLowBuffer),n.vertexAttribPointer(s.a_startPosLow,this._startPositionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._endPositionHighBuffer),n.vertexAttribPointer(s.a_endPosHigh,this._endPositionHighBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._endPositionLowBuffer),n.vertexAttribPointer(s.a_endPosLow,this._endPositionLowBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._rgbaBuffer),n.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._thicknessBuffer),n.vertexAttribPointer(s.a_thickness,this._thicknessBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._vertexBuffer),n.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._texCoordBuffer),n.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._texOffsetBuffer),n.vertexAttribPointer(s.a_texOffset,this._texOffsetBuffer.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this._strokeSizeBuffer),n.vertexAttribPointer(s.a_strokeSize,this._strokeSizeBuffer.itemSize,n.FLOAT,!1,0,0),n.drawArrays(n.TRIANGLES,0,this._vertexBuffer.numItems),n.enable(n.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=Et(this._rgbaArr,i,24),this._texCoordArr=ot(this._texCoordArr,i,24),i=18*t,this._startPositionHighArr=Et(this._startPositionHighArr,i,18),this._startPositionLowArr=Et(this._startPositionLowArr,i,18),this._endPositionHighArr=Et(this._endPositionHighArr,i,18),this._endPositionLowArr=Et(this._endPositionLowArr,i,18),this._pickingColorArr=Et(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Et(this._vertexArr,i,12),i=6*t,this._thicknessArr=Et(this._thicknessArr,i,6),this._texOffsetArr=ot(this._texOffsetArr,i,6),this._strokeSizeArr=ot(this._strokeSizeArr,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 s=18*e,r=this._startPositionHighArr,n=t.x,o=t.y,a=t.z;r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,r=this._startPositionLowArr,n=i.x,o=i.y,a=i.z,r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,this._changedBuffers[1]=!0}setEndPositionArr(e,t,i){let s=18*e,r=this._endPositionHighArr,n=t.x,o=t.y,a=t.z;r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,r=this._endPositionLowArr,n=i.x,o=i.y,a=i.z,r[s]=n,r[s+1]=o,r[s+2]=a,r[s+3]=n,r[s+4]=o,r[s+5]=a,r[s+6]=n,r[s+7]=o,r[s+8]=a,r[s+9]=n,r[s+10]=o,r[s+11]=a,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=n,r[s+16]=o,r[s+17]=a,this._changedBuffers[2]=!0}setPickingColorArr(e,t){let i=18*e,s=this._pickingColorArr,r=t.x/255,n=t.y/255,o=t.z/255;s[i]=r,s[i+1]=n,s[i+2]=o,s[i+3]=r,s[i+4]=n,s[i+5]=o,s[i+6]=r,s[i+7]=n,s[i+8]=o,s[i+9]=r,s[i+10]=n,s[i+11]=o,s[i+12]=r,s[i+13]=n,s[i+14]=o,s[i+15]=r,s[i+16]=n,s[i+17]=o,this._changedBuffers[0]=!0}setRgbaArr(e,t,i){let s=24*e,r=this._rgbaArr,n=t.x,o=t.y,a=t.z,l=t.w,h=i.x,c=i.y,d=i.z,_=i.w;r[s]=h,r[s+1]=c,r[s+2]=d,r[s+3]=_,r[s+4]=n,r[s+5]=o,r[s+6]=a,r[s+7]=l,r[s+8]=n,r[s+9]=o,r[s+10]=a,r[s+11]=l,r[s+12]=n,r[s+13]=o,r[s+14]=a,r[s+15]=l,r[s+16]=h,r[s+17]=c,r[s+18]=d,r[s+19]=_,r[s+20]=h,r[s+21]=c,r[s+22]=d,r[s+23]=_,this._changedBuffers[3]=!0}setThicknessArr(e,t){let i=6*e,s=this._thicknessArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[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,s=this._vertexArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[i+11]=t[11],this._changedBuffers[5]=!0}createStartPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._startPositionHighBuffer),this._startPositionHighArr=st(this._startPositionHighArr),this._startPositionHighBuffer=e.createArrayBuffer(this._startPositionHighArr,3,this._startPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._startPositionLowBuffer),this._startPositionLowArr=st(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=st(this._endPositionHighArr),this._endPositionHighBuffer=e.createArrayBuffer(this._endPositionHighArr,3,this._endPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._endPositionLowBuffer),this._endPositionLowArr=st(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=st(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=st(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=st(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2,e.gl.DYNAMIC_DRAW)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,4,this._texCoordArr.length/4)}createTexOffsetBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texOffsetBuffer),this._texOffsetBuffer=e.createArrayBuffer(this._texOffsetArr,1,this._texOffsetArr.length)}createStrokeSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._strokeSizeBuffer),this._strokeSizeBuffer=e.createArrayBuffer(this._strokeSizeArr,1,this._strokeSizeArr.length)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=st(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}setTexCoordArr(e,t){let i=t[1],s=t[3]-i,r=24*e,n=this._texCoordArr;n[r]=t[0],n[r+1]=t[1],n[r+2]=i,n[r+3]=s,n[r+4]=t[2],n[r+5]=t[3],n[r+6]=i,n[r+7]=s,n[r+8]=t[4],n[r+9]=t[5],n[r+10]=i,n[r+11]=s,n[r+12]=t[6],n[r+13]=t[7],n[r+14]=i,n[r+15]=s,n[r+16]=t[8],n[r+17]=t[9],n[r+18]=i,n[r+19]=s,n[r+20]=t[10],n[r+21]=t[11],n[r+22]=i,n[r+23]=s,this._changedBuffers[6]=!0}setTextureDisabled(e){let t=24*e,i=this._texCoordArr;i[t+3]=0,i[t+7]=0,i[t+11]=0,i[t+15]=0,i[t+19]=0,i[t+23]=0,this._changedBuffers[6]=!0}setTexOffsetArr(e,t){let i=6*e,s=this._texOffsetArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[7]=!0}setStrokeSizeArr(e,t){let i=6*e,s=this._strokeSizeArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[8]=!0}refreshTexCoordsArr(){if(this._entityCollection&&this._renderer){let e=this._renderer.strokeTextureAtlas;for(let t=0;t<this._rays.length;t++){let i=this._rays[t],s=i.getImage();if(s){let t=e.get(s.__nodeIndex);t&&this.setTexCoordArr(i._handlerIndex,t.texCoords)}}}}};Es.__counter__=0;let Sr=Es;const As=class e{constructor(t){this.__id=e.__counter__++,this.pickingEnabled=!0,this._entityCollection=t,this._renderer=null,this._strips=[]}_initProgram(){this._renderer&&this._renderer.handler&&!this._renderer.handler.programs.strip&&this._renderer.handler.addProgram(new X("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=[]}};As.__counter__=0;let Rr=As;const Ls=class e{constructor(t={}){this._onChangeRelativeCenter=e=>{this.geoObjectHandler.setRelativeCenter(e),this.polylineHandler.setRelativeCenter(e)},this.__id=e.__counter__++,this.renderNode=null,this._visibility=null==t.visibility||t.visibility,this.polygonOffsetUnits=null!=t.polygonOffsetUnits?t.polygonOffsetUnits:0,this.billboardHandler=new sl(this),this.labelHandler=new nl(this,t.labelMaxLetters),this.polylineHandler=new Pr(this),this.rayHandler=new Sr(this),this.pointCloudHandler=new Lr(this),this.stripHandler=new Rr(this),this.geoObjectHandler=new Ar(this),null!=t.pickingEnabled&&this.setPickingEnabled(t.pickingEnabled),this._entities=[],this.scaleByDistance=t.scaleByDistance||[1,1,1];let i=new Float32Array([1,1,1]);void 0!==t.pickingScale&&(t.pickingScale instanceof Array?(i[0]=t.pickingScale[0]||i[0],i[1]=t.pickingScale[1]||i[1],i[2]=t.pickingScale[2]||i[2]):"number"==typeof t.pickingScale&&(i[0]=t.pickingScale,i[1]=t.pickingScale,i[2]=t.pickingScale)),this._depthOrder=t.depthOrder||0,this.pickingScale=i,this._opacity=null==t.opacity?1:t.opacity,this._fadingOpacity=this._opacity,this.events=this.rendererEvents=lt(ol,this),this._useLighting=null!=t.useLighting?t.useLighting?1:0:1,t.entities&&this.addEntities(t.entities)}get depthOrder(){return this._depthOrder}set depthOrder(e){this._depthOrder=e,this.renderNode&&this.renderNode.updateEntityCollectionsDepthOrder()}isEmpty(){return 0==this._entities.length}get id(){return this.__id}get useLighting(){return!!this._useLighting}set useLighting(e){this._useLighting=Number(e)}isEqual(e){return null!==e&&this.__id===e.__id}setVisibility(e){var t;this._visibility=e,this._fadingOpacity=this._opacity*(e?1:0),null==(t=this.renderNode)||t.updateEntityCollectionsDepthOrder(),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||Ae}appendChildEntity(e){this._addRecursively(e)}_addRecursively(e){let t=this.renderNode;t&&t.ellipsoid&&e._cartesian.isZero()&&!e.relativePosition&&e.setCartesian3v(t.ellipsoid.lonLatToCartesian(e._lonLat)),this._setPickingColor(e),e._updateAbsolutePosition(),e.setScale3v(e.getScale()),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.childEntities.length;t++)e.childEntities[t]._entityCollection=this,this._addRecursively(e.childEntities[t])}add(e){return e._entityCollection||(e._entityCollection=this,e._entityCollectionIndex=this._entities.length,this._entities.push(e),this._addRecursively(e)),this}addEntities(e){for(let t=0,i=e.length;t<i;t++)this.add(e[t]);return this}belongs(e){return this.isEqual(e._entityCollection)}_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.childEntities.length;t++)this._removeRecursively(e.childEntities[t])}_removeEntity(e){if(e.parent){let t=e.parent.childEntities;for(let i=0,s=t.length;i<s;i++)if(t[i].isEqual(e)){t.splice(i,1);break}e.parent=null}else this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex);this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this._removeRecursively(e)}removeEntity(e){this.belongs(e)&&(this._removeEntity(e),this.events.dispatch(this.events.entityremove,e))}_removeEntitySilent(e){this.belongs(e)&&this._removeEntity(e)}createPickingColors(e=this._entities){if(this.renderNode&&this.renderNode.renderer)for(let t=0;t<e.length;t++){let i=e[t];this._setPickingColor(i),this.createPickingColors(i.childEntities)}}_setPickingColor(e){this.renderNode&&this.renderNode.renderer&&(e._independentPicking||!e.parent?this.renderNode.renderer.assignPickingColor(e):e._pickingColor=e.parent._pickingColor,this.renderNode.renderer.assignPickingColor(e),e.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||e.addEntityCollection(this,t),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),e.renderer.events.on("changerelativecenter",this._onChangeRelativeCenter),this.updateBillboardsTextureAtlas(),this.updateLabelsFontAtlas(),this.updateStrokeTextureAtlas(),this.createPickingColors())}_updateGeodeticCoordinates(e){let t=this._entities,i=t.length;for(;i--;){let s=t[i];s._lonLat&&s.setCartesian3v(e.lonLatToCartesian(s._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()}updateStrokeTextureAtlas(){this.rayHandler.reloadTextures(),this.polylineHandler.reloadTextures()}remove(){var e;this.renderNode&&(this.renderNode.removeEntityCollection(this),null==(e=this.renderNode.renderer)||e.events.off("changerelativecenter",this._onChangeRelativeCenter),this.renderNode=null,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.childEntities.length;t++)this._clearEntity(e.childEntities[t])}};Ls.__counter__=0;let se=Ls;const ol=["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"];function ae(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 An(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 Ln(e,t,i){i=i||2;var s,r,n,o,a,l,h,c=t&&t.length,d=c?t[0]*i:e.length,_=Pn(e,0,d,i,!0),u=[];if(!_)return u;if(c&&(_=function(e,t,i,s){var r,n,o,a=[];for(r=0,n=t.length;r<n;r++)(o=Pn(e,t[r]*s,r<n-1?t[r+1]*s:e.length,s,!1))===o.next&&(o.steiner=!0),a.push(_l(o));for(a.sort(dl),r=0;r<a.length;r++)ul(a[r],i),i=wi(i,i.next);return i}(e,t,_,i)),e.length>80*i){s=n=e[0],r=o=e[1];for(let t=i;t<d;t+=i)(a=e[t])<s&&(s=a),(l=e[t+1])<r&&(r=l),a>n&&(n=a),l>o&&(o=l);h=Math.max(n-s,o-r)}return Ti(_,u,i,s,r,h),u}function Pn(e,t,i,s,r){var n,o;if(r===function(e,t,i,s){var r=0;for(let n=t,o=i-s;n<i;n+=s)r+=(e[o]-e[n])*(e[n+1]+e[o+1]),o=n;return r}(e,t,i,s)>0)for(n=t;n<i;n+=s)o=Sn(n,e[n],e[n+1],o);else for(n=i-s;n>=t;n-=s)o=Sn(n,e[n],e[n+1],o);return o&&Te(o,o.next)&&(Ei(o),o=o.next),o}function wi(e,t){if(!e)return e;t||(t=e);var i,s=e;do{if(i=!1,s.steiner||!Te(s,s.next)&&0!==It(s.prev,s,s.next))s=s.next;else{if(Ei(s),(s=t=s.prev)===s.next)return null;i=!0}}while(i||s!==t);return t}function Ti(e,t,i,s,r,n,o){if(e){!o&&n&&function(e,t,i,s){var r=e;do{null===r.z&&(r.z=Mr(r.x,r.y,t,i,s)),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,s,r,n,o,a,l,h=1;do{for(i=e,e=null,n=null,o=0;i;){for(o++,s=i,a=0,t=0;t<h&&(a++,s=s.nextZ);t++);for(l=h;a>0||l>0&&s;)0!==a&&(0===l||!s||i.z<=s.z)?(r=i,i=i.nextZ,a--):(r=s,s=s.nextZ,l--),n?n.nextZ=r:e=r,r.prevZ=n,n=r;i=s}n.nextZ=null,h*=2}while(o>1)}(r)}(e,s,r,n);for(var a,l,h=e;e.prev!==e.next;)if(a=e.prev,l=e.next,n?ll(e,s,r,n):al(e))t.push(a.i/i),t.push(e.i/i),t.push(l.i/i),Ei(e),e=l.next,h=l.next;else if((e=l)===h){o?1===o?Ti(e=hl(e,t,i),t,i,s,r,n,2):2===o&&cl(e,t,i,s,r,n):Ti(wi(e),t,i,s,r,n,1);break}}}function al(e){var t=e.prev,i=e,s=e.next;if(It(t,i,s)>=0)return!1;for(var r=e.next.next;r!==e.prev;){if(os(t.x,t.y,i.x,i.y,s.x,s.y,r.x,r.y)&&It(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function ll(e,t,i,s){var r=e.prev,n=e,o=e.next;if(It(r,n,o)>=0)return!1;for(var a=r.x<n.x?r.x<o.x?r.x:o.x:n.x<o.x?n.x:o.x,l=r.y<n.y?r.y<o.y?r.y:o.y:n.y<o.y?n.y:o.y,h=r.x>n.x?r.x>o.x?r.x:o.x:n.x>o.x?n.x:o.x,c=r.y>n.y?r.y>o.y?r.y:o.y:n.y>o.y?n.y:o.y,d=Mr(a,l,t,i,s),_=Mr(h,c,t,i,s),u=e.nextZ;u&&u.z<=_;){if(u!==e.prev&&u!==e.next&&os(r.x,r.y,n.x,n.y,o.x,o.y,u.x,u.y)&&It(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&&os(r.x,r.y,n.x,n.y,o.x,o.y,u.x,u.y)&&It(u.prev,u,u.next)>=0)return!1;u=u.prevZ}return!0}function hl(e,t,i){var s=e;do{var r=s.prev,n=s.next.next;!Te(r,n)&&ra(r,s,s.next,n)&&Ci(r,n)&&Ci(n,r)&&(t.push(r.i/i),t.push(s.i/i),t.push(n.i/i),Ei(s),Ei(s.next),s=e=n),s=s.next}while(s!==e);return s}function cl(e,t,i,s,r,n){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&fl(o,a)){var l=na(o,a);return o=wi(o,o.next),l=wi(l,l.next),Ti(o,t,i,s,r,n),void Ti(l,t,i,s,r,n)}a=a.next}o=o.next}while(o!==e)}function dl(e,t){return e.x-t.x}function ul(e,t){if(t=function(e,t){var i,s=t,r=e.x,n=e.y,o=-1/0;do{if(n<=s.y&&n>=s.next.y&&s.next.y!==s.y){var a=s.x+(n-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=r&&a>o){if(o=a,a===r){if(n===s.y)return s;if(n===s.next.y)return s.next}i=s.x<s.next.x?s:s.next}}s=s.next}while(s!==t);if(!i)return null;if(r===o)return i.prev;var l,h=i,c=i.x,d=i.y,_=1/0;for(s=i.next;s!==h;)r>=s.x&&s.x>=c&&r!==s.x&&os(n<d?r:o,n,c,d,n<d?o:r,n,s.x,s.y)&&((l=Math.abs(n-s.y)/(r-s.x))<_||l===_&&s.x>i.x)&&Ci(s,e)&&(i=s,_=l),s=s.next;return i}(e,t)){var i=na(t,e);wi(i,i.next)}}function Mr(e,t,i,s,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-s)/r)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function _l(e){var t=e,i=e;do{t.x<i.x&&(i=t),t=t.next}while(t!==e);return i}function os(e,t,i,s,r,n,o,a){return(r-o)*(t-a)-(e-o)*(n-a)>=0&&(e-o)*(s-a)-(i-o)*(t-a)>=0&&(i-o)*(n-a)-(r-o)*(s-a)>=0}function fl(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&&ra(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&Ci(e,t)&&Ci(t,e)&&function(e,t){var i=e,s=!1,r=(e.x+t.x)/2,n=(e.y+t.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&r<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)}function It(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function Te(e,t){return e.x===t.x&&e.y===t.y}function ra(e,t,i,s){return!!(Te(e,t)&&Te(i,s)||Te(e,s)&&Te(i,t))||It(e,t,i)>0!=It(e,t,s)>0&&It(i,s,e)>0!=It(i,s,t)>0}function Ci(e,t){return It(e.prev,e,e.next)<0?It(e,t,e.next)>=0&&It(e,e.prev,t)>=0:It(e,t,e.prev)<0||It(e,e.next,t)<0}function na(e,t){var i=new Br(e.i,e.x,e.y),s=new Br(t.i,t.x,t.y),r=e.next,n=t.prev;return e.next=t,t.prev=e,i.next=r,r.prev=i,s.next=i,i.prev=s,n.next=s,s.prev=n,s}function Sn(e,t,i,s){var r=new Br(e,t,i);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function Ei(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 Br(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 Rn(e){var t=e[0][0].length,i={vertices:[],holes:[],dimensions:t},s=0;for(let r=0;r<e.length;r++){for(let s=0;s<e[r].length;s++)for(let n=0;n<t;n++)i.vertices.push(e[r][s][n]);r>0&&(s+=e[r-1].length,i.holes.push(s))}return i}function qs(e,t,i){let s=e[0],r=e[1];if(s>=0){let e=65536*Math.floor(s/65536);t.x=Math.fround(e),i.x=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.x=Math.fround(-e),i.x=Math.fround(s+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 q=new H,Y=new H,De=new H;const ge=class e{constructor(t){this.__id=e.__counter__++,this._layer=t,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,s,r,n,o,a,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=o,w=[n.x,n.y,n.z,n.w],T=[s.x,s.y,s.z,1];for(let i=0;i<e.length;i++){var C=e[i];if(0===C.length)continue;let s,r,n=v;if(t)s=C[C.length-1];else{let e=C[0],t=C[1];t||(t=e),s=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]]}qs(s,q,Y),a.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),l.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.y),p.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),m.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.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++)qs(C[e],q,Y),a.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),l.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.y),p.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),m.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.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(n,n+1,n+1,n+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)}qs(r,q,Y),a.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),l.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.y),p.push(q.x,q.y,q.x,q.y,q.x,q.y,q.x,q.y),m.push(Y.x,Y.y,Y.x,Y.y,Y.x,Y.y,Y.x,Y.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(t){if(-1===t._handlerIndex){t._handler=this,t._handlerIndex=this._geometries.length,this._geometries.push(t);let i=t._entity._pickingColor.scaleTo(1/255);if(t._polyVerticesHighMerc=[],t._polyVerticesLowMerc=[],t._lineVerticesHighMerc=[],t._lineVerticesLowMerc=[],t._coordinates[0].length)if(t.type===ai.POLYGON){let s=t._coordinates,r=[];for(let e=0;e<s.length;e++){r[e]=[];for(let t=0;t<s[e].length;t++)r[e][t]=[ni(s[e][t][0]),oi(s[e][t][1])]}let n=Rn(r),o=Ln(n.vertices,n.holes,2);t._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,t._polyIndexesHandlerIndex=this._polyIndexes.length;for(let e=0;e<o.length;e++)this._polyIndexes.push(o[e]+.5*t._polyVerticesHandlerIndex);let a=t._style.fillColor,l=[],h=[];for(let e=0;e<.5*n.vertices.length;e++)this._polyColors.push(a.x,a.y,a.z,a.w),this._polyPickingColors.push(i.x,i.y,i.z,1);for(let e=0;e<n.vertices.length;e++)An(n.vertices[e],De),l[e]=De.x,h[e]=De.y;t._polyVerticesHighMerc=l,t._polyVerticesLowMerc=h,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,l),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,h),t._polyVerticesLength=n.vertices.length,t._polyIndexesLength=o.length,t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,e.appendLineData(r,!0,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===ai.MULTIPOLYGON){let s=t._coordinates,r=[],n=[];t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length;for(let o=0;o<s.length;o++){let a=s[o],l=[];for(let e=0;e<a.length;e++){l[e]=[];for(let t=0;t<s[o][e].length;t++)l[e][t]=[ni(a[e][t][0]),oi(a[e][t][1])]}let h=Rn(l),c=Ln(h.vertices,h.holes,2);for(let e=0;e<c.length;e++)n.push(c[e]+.5*r.length);r.push.apply(r,h.vertices),e.appendLineData(l,!0,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc)}t._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,t._polyIndexesHandlerIndex=this._polyIndexes.length;for(let e=0;e<n.length;e++)this._polyIndexes.push(n[e]+.5*t._polyVerticesHandlerIndex);let o=t._style.fillColor,a=[],l=[];for(let e=0;e<.5*r.length;e++)this._polyColors.push(o.x,o.y,o.z,o.w),this._polyPickingColors.push(i.x,i.y,i.z,1);for(let e=0;e<r.length;e++)An(r[e],De),a[e]=De.x,l[e]=De.y;t._polyVerticesHighMerc=a,t._polyVerticesLowMerc=l,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,a),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,l),t._polyVerticesLength=r.length,t._polyIndexesLength=n.length,t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===ai.LINESTRING){let s=t._coordinates,r=new Array(s.length);for(let e=0;e<s.length;e++)r[e]=[ni(s[e][0]),oi(s[e][1])];t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,e.appendLineData([r],!1,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===ai.MULTILINESTRING){let s=t._coordinates,r=[];for(let e=0;e<s.length;e++){r[e]=[];for(let t=0;t<s[e].length;t++)r[e][t]=[ni(s[e][t][0]),oi(s[e][t][1])]}t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,e.appendLineData(r,!1,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}this.setGeometryVisibility(t),!this._updatedGeometry[t.__id]&&this._updatedGeometryArr.push(t),this._updatedGeometry[t.__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 s=this._geometries;for(let i=t;i<s.length;i++){let t=s[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 s=0;s<t.nodes.length;s++){let r=t.nodes[s];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 s=0;s<t.nodes.length;s++){let r=t.nodes[s];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 s=this._updatedGeometryArr;for(t=0;t<s.length;t++)this._refreshRecursevely(s[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,s=this._polyVerticesLowMerc,r=e._polyVerticesLength,n=e._polyVerticesHandlerIndex;for(let o=0;o<r;o++)i[n+o]=e._polyVerticesHighMerc[o]*t,s[n+o]=e._polyVerticesLowMerc[o]*t;i=this._lineVerticesHighMerc,s=this._lineVerticesLowMerc,r=e._lineVerticesLength,n=e._lineVerticesHandlerIndex;for(let o=0;o<r;o++)i[n+o]=e._lineVerticesHighMerc[o]*t,s[n+o]=e._lineVerticesLowMerc[o]*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,s=i+2*e._polyVerticesLength,r=this._polyColors;for(let e=i;e<s;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,s=i+e._lineColorsLength,r=this._lineStrokeColors;for(let e=i;e<s;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,s=i+e._lineColorsLength,r=this._lineColors;for(let e=i;e<s;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,s=i+e._lineThicknessLength,r=this._lineThickness;for(let e=i;e<s;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 s=this._geometries;for(let t=e._handlerIndex;t<s.length;t++){let i=s[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)}clear(){this._geometries=[],this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyIndexes=[],this._polyColors=[],this._polyPickingColors=[],this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineOrders=[],this._lineIndexes=[],this._lineColors=[],this._linePickingColors=[],this._lineThickness=[],this._lineStrokeColors=[],this._lineStrokes=[],this._deleteBuffers(),this._polyVerticesHighBufferMerc=null,this._polyVerticesLowBufferMerc=null,this._polyIndexesBuffer=null,this._polyColorsBuffer=null,this._polyPickingColorsBuffer=null,this._lineVerticesHighBufferMerc=null,this._lineVerticesLowBufferMerc=null,this._lineIndexesBuffer=null,this._lineOrdersBuffer=null,this._lineColorsBuffer=null,this._linePickingColorsBuffer=null,this._lineThicknessBuffer=null,this._lineStrokeColorsBuffer=null,this._lineStrokesBuffer=null,this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr=[],this._removeGeometryExtents={},this.refresh()}_deleteBuffers(){if(this._layer._planet&&this._layer._planet.renderer){let e=this._layer._planet.renderer.handler.gl;e&&(e.deleteBuffer(this._polyVerticesHighBufferMerc),e.deleteBuffer(this._polyVerticesLowBufferMerc),e.deleteBuffer(this._polyIndexesBuffer),e.deleteBuffer(this._polyColorsBuffer),e.deleteBuffer(this._polyPickingColorsBuffer),e.deleteBuffer(this._lineVerticesHighBufferMerc),e.deleteBuffer(this._lineVerticesLowBufferMerc),e.deleteBuffer(this._lineIndexesBuffer),e.deleteBuffer(this._lineOrdersBuffer),e.deleteBuffer(this._lineColorsBuffer),e.deleteBuffer(this._linePickingColorsBuffer),e.deleteBuffer(this._lineThicknessBuffer),e.deleteBuffer(this._lineStrokeColorsBuffer),e.deleteBuffer(this._lineStrokesBuffer))}}};ge.__counter__=0;let kr=ge;class _t extends zt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(gl),this.isVector=!0,this._hasImageryTiles=!1,this.scaleByDistance=t.scaleByDistance||[Ae,Ae,Ae],this._useLighting=void 0===t.useLighting||t.useLighting;let i=new Float32Array([1,1,1]);void 0!==t.pickingScale&&(t.pickingScale instanceof Array?(i[0]=t.pickingScale[0]||i[0],i[1]=t.pickingScale[1]||i[1],i[2]=t.pickingScale[2]||i[2]):"number"==typeof t.pickingScale&&(i[0]=t.pickingScale,i[1]=t.pickingScale,i[2]=t.pickingScale)),this.pickingScale=i,this.async=void 0===t.async||t.async,this.clampToGround=t.clampToGround||!1,this.relativeToGround=t.relativeToGround||!1,this._entities=function(e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];"Entity"===s.instanceName?t.push(s):t.push(new G(s))}return t}(t.entities||[]),this._labelMaxLetters=t.labelMaxLetters||24,this._stripEntityCollection=new se({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._stripEntityCollection),this._polylineEntityCollection=new se({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._polylineEntityCollection),this._geoObjectEntityCollection=new se({pickingEnabled:this.pickingEnabled,useLighting:this._useLighting}),this._bindEventsDefault(this._geoObjectEntityCollection),this._geometryHandler=new kr(this),this._nodeCapacity=t.nodeCapacity||60,this._entityCollectionsTreeStrategy=null,this.setEntities(this._entities),this.polygonOffsetUnits=null!=t.polygonOffsetUnits?t.polygonOffsetUnits:0,this.pickingEnabled=this._pickingEnabled,this._depthOrder=t.depthOrder||0}get depthOrder(){return this._depthOrder}set depthOrder(e){e!==this._depthOrder&&(this._depthOrder=e,this._planet&&this._planet.updateVisibleLayers())}get useLighting(){return this._useLighting}set useLighting(e){e!==this._useLighting&&(this._geoObjectEntityCollection.useLighting=e,this._useLighting=e)}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._polylineEntityCollection._layer=this,this._stripEntityCollection._layer=this,this._geoObjectEntityCollection._layer=this,this.setEntities(this._entities))}remove(){return super.remove(),this._polylineEntityCollection.remove(),this._stripEntityCollection.remove(),this._geoObjectEntityCollection.remove(),this._polylineEntityCollection._layer=void 0,this._stripEntityCollection._layer=void 0,this._geoObjectEntityCollection._layer=void 0,this}getEntities(){return[].concat(this._entities)}add(e){return e._layer||e._entityCollection||(e._layer=this,e._layerIndex=this._entities.length,this._entities.push(e),this._proceedEntity(e)),this}insert(e,t){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)}return this}_proceedEntity(e){var t;let i=this._hasImageryTiles;e.strip&&this._stripEntityCollection.add(e),(e.polyline||e.ray)&&this._polylineEntityCollection.add(e),(e.geoObject||e.isEmpty)&&this._geoObjectEntityCollection.add(e),e.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(e),this._geometryHandler.add(e.geometry))),this._planet&&((e.billboard||e.label||e.geoObject||e.isEmpty)&&(e._cartesian.isZero()&&!e._lonLat.isZero()?e._setCartesian3vSilent(this._planet.ellipsoid.lonLatToCartesian(e._lonLat)):(e._lonLat=this._planet.ellipsoid.cartesianToLonLat(e._cartesian),Math.abs(e._lonLat.lat)<ct?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc.lon=e._lonLatMerc.lat=e._lonLatMerc.height=0)),(e.billboard||e.label)&&(null==(t=this._entityCollectionsTreeStrategy)||t.insertEntity(e))),this._planet&&this._hasImageryTiles!==i&&this._planet.updateVisibleLayers(),this.events.dispatch(this.events.entityadd,e)}addEntities(e){let t=e.length;for(;t--;)this.add(e[t]);return this}removeEntity(e){if(e._layer&&this.isEqual(e._layer)){if(e.parent||(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 s=e._nodePtr;for(;s;)s.count--,s=s.parentNode;break}}this._planet&&e.geometry&&(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){var t;this._pickingEnabled=e,this._stripEntityCollection.setPickingEnabled(e),this._polylineEntityCollection.setPickingEnabled(e),this._geoObjectEntityCollection.setPickingEnabled(e),null==(t=this._entityCollectionsTreeStrategy)||t.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(){var e;super.clear();let t=new Array(this._entities.length);for(let e=0;e<t.length;e++)t[e]=this._entities[e];let i=this._entities.length;for(;i--;)this._entities[i].remove();this._entities.length=0,this._entities=[];for(let e=0;e<t.length;e++)this._entities[e]=t[e];null==(e=this._entityCollectionsTreeStrategy)||e.dispose(),this._entityCollectionsTreeStrategy=null,this._geometryHandler.clear()}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,s=e.length;i<s;i++)t[i]=e[i];this.clear(),this._entities=new Array(t.length);let i=[];for(let e=0;e<t.length;e++){let s=t[e];s._layer=this,s._layerIndex=e;let r=!(s.strip||s.polyline||s.ray||s.geoObject||s.billboard||s.label);s.strip?this._stripEntityCollection.add(s):s.polyline||s.ray?this._polylineEntityCollection.add(s):s.geoObject||r?this._geoObjectEntityCollection.add(s):(s.billboard||s.label)&&i.push(s),s.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(s),this._geometryHandler.add(s.geometry))),this._entities[e]=s}return this._createEntityCollectionsTree(i),this}_createEntityCollectionsTree(e){this._planet&&(this._entityCollectionsTreeStrategy=this._planet.quadTreeStrategy.createEntityCollectionsTreeStrategy(this,this._nodeCapacity),this._entityCollectionsTreeStrategy.insertEntities(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.quadTreeStrategy._renderedNodes,s=this._planet.getViewExtent();let r=t._entities,n=r.length,o=new v;for(;n--;){let t=r[n]._altitude||0,a=r[n].polyline;if(a&&s.overlaps(a._extent)){let s=a._pathLonLatMerc,r=s.length;for(;r--;){let n=s[r].length;for(;n--;){let l=s[r][n],h=i.length;for(;h--;){let s=i[h].segment;if(s._extent.isInside(l)){let i=a._path3v[r][n];s.getTerrainPoint(i,l,o);let h=e&&a.altitude||t;if(h){let e=this._planet.ellipsoid.getSurfaceNormal3v(o);a.setPoint3v(o.addA(e.scale(h)),n,r,!0)}else a.setPoint3v(o,n,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;(this._fading&&this._fadingOpacity>0||this.minZoom<=t.quadTreeStrategy.maxCurrZoom&&this.maxZoom>=t.quadTreeStrategy.maxCurrZoom)&&(this._collectStripCollectionPASS(e),this._collectPolylineCollectionPASS(e),this._collectGeoObjectCollectionPASS(e),this._entityCollectionsTreeStrategy&&this._entityCollectionsTreeStrategy.collectVisibleEntityCollections(e))}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){if(e.isReady)return[0,0,1,1];{!e.isLoading&&this.loadMaterial(e);const t=e.segment;let i=t.node,s=!1,r=this.__id,n=e;for(;i.parentNode;){if(n&&n.isReady){s=!0;break}i=i.parentNode,n=i.segment.materials[r]}if(s){e.appliedNodeId=i.nodeId,e.texture=n.texture,e.pickingMask=n.pickingMask;const s=1/(2<<t.tileZoom-i.segment.tileZoom-1);return[t.tileX*s-i.segment.tileX,t.tileY*s-i.segment.tileY,s,s]}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 gl=["draw","entityadd","entityremove"],pl=["change","startpoint"],Mn=$.createCylinder(1,1,2,20,1,!0,!1,0,-.5,0),kt=200,gi=.3;class oa extends de{constructor(e){super(e.name),this._cornerDblClick=!1,this._onChange=e=>{if("POLYGON"===e.geometryType){let t=this.getCoordinates(),i=new G({geometry:{type:e.geometryType,coordinates:[t],style:this._fillStyle}});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=lt(pl),this._planet=null,this._initCoordinates=e.coordinates||[],this._pickedCorner=null,this._pickedCenter=null,this._startPos=null,this._startClick=new H,this._geometryLayer=new _t,this._cornerStyle={scale:.5,tag:"corners",color:"rgb(350, 350, 0)",object3d:Mn,...e.cornerStyle||{}},this._centerStyle={scale:.4,tag:"centers",color:"rgb(0, 350, 50)",object3d:Mn,...e.centerStyle||{}},this._outlineStyle={thickness:3.5,color:"rgb(0, 350, 50)",...e.outlineStyle||{}},this._fillStyle={fillColor:"rgba(0,146,247,0.2)",...e.fillStyle||{}},this._cornerLayer=new _t("corners",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._centerLayer=new _t("centers",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._outlineLayer=new _t("outline",{entities:[new G({polyline:{path3v:[],isClosed:!1,...this._outlineStyle}})],pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0}),this._outlineLayer.getEntities()[0].polyline.altitude=gi,this._ghostCorner=new G({geoObject:this._cornerStyle}),this._ghostOutlineLayer=new _t("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._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 s=this._outlineLayer.getEntities();for(t=s.length;t--;)s[t].polyline.clear(),t>0&&s[t].remove();this._clearGhostPointer()}setCoordinates(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],s=this._planet.ellipsoid.lonLatToCartesian(new L(i[0],i[1],i[2]));this._appendCart(s)}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 v,i=this._planet.quadTreeStrategy._renderedNodes;for(let s=0;s<i.length;s++){let r=i[s].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(),s=[i.lon,i.lat,i.height];e.splice(t,0,s),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,s=this._planet.ellipsoid.cartesianToLonLat(e),r=[s.lon,s.lat,s.height];t.splice(i,0,r),this.clear(),this.setCoordinates(t)}}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],s=new G({geoObject:this._cornerStyle});if(s.setCartesian3v(e),s.addTo(this._cornerLayer),this._checkTerrainCollision(s),i){let e=t[0].getCartesian(),r=i.getCartesian(),n=s.getCartesian().sub(r),o=s.getCartesian().sub(e),a=n.length(),l=o.length();n.normalize(),o.normalize();let h=[],c=[];for(let t=0;t<=kt;t++){let i=n.scaleTo(t*a/kt).addA(r);h.push(i);let s=o.scaleTo(t*l/kt).addA(e);c.push(s)}this._outlineLayer.getEntities()[0].polyline.setPath3v([c]);let d=new G({polyline:{path3v:[h],isClosed:!1,...this._outlineStyle}});d.polyline.altitude=gi,this._outlineLayer.add(d);let _=this._centerLayer.getEntities(),u=_[_.length-1],f=n.scaleTo(.5*a).addA(r),g=o.scaleTo(.5*l).addA(e),p=new G({geoObject:this._centerStyle});p.setCartesian3v(f),p.addTo(this._centerLayer),this._checkTerrainCollision(p),u.remove(),u.addTo(this._centerLayer),u.setCartesian3v(g)}else new G({geoObject:this._centerStyle}).addTo(this._centerLayer)}_clearGhostPointer(){const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.clear(),e.getEntities()[1].polyline.clear()}_moveCornerPoint(e){let t=new H(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);if(s){this._pickedCorner.setCartesian3v(s);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex,i=e.length,s=e[0===t?i-1:t-1].getCartesian(),r=e[(t+1)%i].getCartesian(),n=this._pickedCorner.getCartesian().sub(s),o=this._pickedCorner.getCartesian().sub(r),a=n.length(),l=o.length();n.normalize(),o.normalize();let h=[],c=[];for(let e=0;e<=kt;e++){let t=n.scaleTo(e*a/kt).addA(s);h.push(t);let i=o.scaleTo(e*l/kt).addA(r);c.push(i)}let d=this._outlineLayer.getEntities(),_=d[t].polyline,u=d[(t+1)%i].polyline;null==_||_.setPath3v([h]),null==u||u.setPath3v([c]);let f=this._centerLayer.getEntities(),g=f[0===t?i-1:t-1],p=f[t],m=n.scaleTo(.5*a).addA(s),v=o.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 s=0,r=xt;for(let n=0;n<i;n++){let i=t[n].getCartesian().distance(e);i<r&&(r=i,s=n)}let n=t[s].getCartesian(),o=t[(s+1)%i].getCartesian(),a=t[0===s?i-1:s-1].getCartesian().sub(n).normalize(),l=o.sub(n).normalize(),h=e.sub(n).normalize(),c=a.add(l).normalize(),d=h.cross(c),_=a.cross(l);d.dot(_)>0&&(s--,s<0&&(s=i-1));let u=new v;for(let n=0;n<i;n++)if(new Jt(t[n].getCartesian(),t[(n+1)%i].getCartesian()).getNearestDistancePoint(e,u)){let t=u.distance(e);t<r&&(r=t,s=n)}this._insertCornerIndex=(s+1)%i;let f=t[s%i].getCartesian(),g=t[(s+1)%i].getCartesian(),p=this._ghostCorner.getCartesian().sub(f),m=this._ghostCorner.getCartesian().sub(g),y=p.length(),x=m.length();p.normalize(),m.normalize();let b=[],w=[];for(let e=0;e<=kt;e++){let t=p.scaleTo(e*y/kt).addA(f);b.push(t);let i=m.scaleTo(e*x/kt).addA(g);w.push(i)}let T=this._ghostOutlineLayer.getEntities(),C=T[0].polyline,E=T[1].polyline;null==C||C.setPath3v([b]),null==E||E.setPath3v([w])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new G({polyline:{path3v:[],isClosed:!1,...this._outlineStyle}}),new G({polyline:{path3v:[],isClosed:!1,...this._outlineStyle}}),this._ghostCorner]);const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.altitude=e.getEntities()[1].polyline.altitude=gi}}class Bn extends oa{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],s=new G({geoObject:this._cornerStyle});if(s.setCartesian3v(e),s.addTo(this._cornerLayer),this._checkTerrainCollision(s),i){let e=i.getCartesian(),t=s.getCartesian().sub(e),r=t.length();t.normalize();let n=[];for(let i=0;i<=kt;i++){let s=t.scaleTo(i*r/kt).addA(e);n.push(s)}let o=new G({polyline:{path3v:[n],isClosed:!1,...this._outlineStyle}});o.polyline.altitude=gi,this._outlineLayer.add(o);let a=t.scaleTo(.5*r).addA(e),l=new G({geoObject:this._centerStyle});l.setCartesian3v(a),l.addTo(this._centerLayer),this._checkTerrainCollision(l)}}_clearGhostPointer(){this._ghostOutlineLayer.getEntities()[0].polyline.clear()}_moveCorner(e,t,i){let s=this._cornerLayer.getEntities();if(0==s.length)return;1==s.length&&(e=t=i=0);let r=s[e].getCartesian(),n=this._pickedCorner.getCartesian().sub(r),o=n.length();n.normalize();let a=[];for(let e=0;e<=kt;e++){let t=n.scaleTo(e*o/kt).addA(r);a.push(t)}let l=this._outlineLayer.getEntities()[t].polyline;null==l||l.setPath3v([a]);let h=this._centerLayer.getEntities()[i];if(h){let e=n.scaleTo(.5*o).addA(r);h.setCartesian3v(e),this._checkTerrainCollision(h)}}_moveCornerPoint(e){let t=new H(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);if(s){this._pickedCorner.setCartesian3v(s);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 s=t[e].getCartesian(),r=this._ghostCorner.getCartesian().sub(s),n=r.length();r.normalize();let o=[];for(let e=0;e<=kt;e++){let t=r.scaleTo(e*n/kt).addA(s);o.push(t)}this._ghostOutlineLayer.getEntities()[0].polyline.setPath3v([o])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new G({polyline:{path3v:[],isClosed:!1,...this._outlineStyle}}),this._ghostCorner]),this._ghostOutlineLayer.getEntities()[0].polyline.altitude=gi}}class kn extends Q{constructor(e={}){super(e),this._drawingScene=new Bn({name:`drawingScene:${this.__id}`,cornerStyle:e.cornerStyle||{},centerStyle:e.centerStyle||{},outlineStyle:e.outlineStyle||{},fillStyle:e.fillStyle||{}})}activatePolygonDrawing(){this.deactivate(),this._drawingScene=new oa({name:`polygonDrawingScene:${this.__id}`,cornerStyle:this._drawingScene._cornerStyle,centerStyle:this._drawingScene._centerStyle,outlineStyle:this._drawingScene._outlineStyle,fillStyle:this._drawingScene._fillStyle}),this.activate()}activateLineStringDrawing(){this.deactivate(),this._drawingScene=new Bn({name:`linestringDrawingScene:${this.__id}`,cornerStyle:this._drawingScene._cornerStyle,centerStyle:this._drawingScene._centerStyle,outlineStyle:this._drawingScene._outlineStyle,fillStyle:this._drawingScene._fillStyle}),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 li={ell:0,msl:1,gnd:2},sn=.3048,ml=1/sn,vl=1/3.6,aa=.001*sn,yl=1/aa,xl=["m","km","ft","s","h","m/s","km/h","ft/s"],la=[0,2,0,0,0,0,0,0];let pt=[];function ha(e,t,i){return pt[e][t](i)}function Ir(e,t,i,s,r){return e?ha(t,i,s).toFixed(r||la[i]):"--"}function ca(e){return xl[e]}pt[0]=[],pt[0][0]=e=>e,pt[0][1]=e=>.001*e,pt[0][2]=e=>e*ml,pt[2]=[],pt[2][0]=e=>e*sn,pt[2][1]=e=>e*aa,pt[2][2]=e=>e,pt[1]=[],pt[1][0]=e=>1e3*e,pt[1][1]=e=>e,pt[1][2]=e=>e*yl,pt[5]=[],pt[5][5]=e=>e,pt[5][6]=e=>3.6*e,pt[5][7]=e=>3.28084*e,pt[6]=[],pt[6][5]=e=>e*vl,pt[6][6]=e=>e;const In=Object.freeze(Object.defineProperty({__proto__:null,ELL:0,GND:2,MSL:1,_tenth:la,convert:ha,convertExt:Ir,ft:2,fts:7,h:4,heightMode:li,km:1,kmh:6,m:0,ms:5,s:3,toString:ca},Symbol.toStringTag,{value:"Module"})),bl=['<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 da extends Q{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=In[this._altUnitVal],this._heightMode=li[this._heightModeVal],this._lonLat=null,this._centerMode=!1}_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 s=0,r=t<0?Math.ceil(t):Math.floor(t),n=Math.floor(s=60*Math.abs(t-r)),o=Math.floor(6e3*(s-n))/100;this._latValEl.innerHTML=Math.abs(r)+"°"+n+"'"+o.toFixed(0)+'"',r=i<0?Math.ceil(i):Math.floor(i),n=Math.floor(s=60*Math.abs(i-r)),o=Math.floor(6e3*(s-n))/100,this._lonValEl.innerHTML=Math.abs(r)+"°"+n+"'"+o.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=li[this._heightModeVal],this._altUnit=In[this._altUnitVal],this._el.querySelector(".og-units-height").innerHTML=ca(this._altUnit),this._showHeight()}_refreshCoordinates(){this._type>=this._TYPE_FUNC.length&&(this._type=0);let e=this._el;e.innerHTML=bl[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",yi((()=>this._showHeight()),400,!0),this)):(this.renderer.events.on("mousemove",this._grabCoordinates,this),this.renderer.events.on("mousestop",yi((()=>this._showHeight()),400,!0),this)),this._refreshCoordinates(),this._updateUnits()}_grabCoordinates(e){let t,i=e.pos,s=this.renderer;t=this._centerMode?s.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===li.ell?(e=await this.planet.getHeightAboveELL(this._lonLat),e=Number(Ir(!0,0,this._altUnit,e))):this._heightMode===li.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()}}}const wl=["loadend"];class Ai extends zt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(wl),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 U,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 L(e[0].lon,e[0].lat),new L(e[1].lon,e[1].lat),new L(e[2].lon,e[2].lat),new L(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(L.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>ct||t.northEast.lat<Ot?(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 U(this._extentWgs84.southWest.forwardMercatorEPS01(),this._extentWgs84.northEast.forwardMercatorEPS01());let e=new Float32Array(2);if(0===this._projType?(ae(this._extentWgs84.southWest.lon,e),this._extentWgs84ParamsHigh[0]=e[0],this._extentWgs84ParamsLow[0]=e[1],ae(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()):(ae(this._extentMerc.southWest.lon,e),this._extentMercParamsHigh[0]=e[0],this._extentMercParamsLow[0]=e[1],ae(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,s=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=s._extent):(t=this._extentMerc,i=s.getExtentMerc());let r=t.northEast.lon-t.southWest.lon,n=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/r,(t.northEast.lat-i.northEast.lat)/n,(i.northEast.lon-i.southWest.lon)/r,(i.northEast.lat-i.southWest.lat)/n]}get getFrameWidth(){return this._frameWidth}get getFrameHeight(){return this._frameHeight}_createSourceTexture(){}_renderingProjType1(){let e=this._planet,t=e.renderer.handler,i=t.gl,s=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let r=s._framebuffer;r.setSize(this._frameWidth,this._frameHeight),r.activate(),t.programs.geoImageTransform.activate();let n=t.programs.geoImageTransform._program,o=n.attributes,a=n.uniforms;i.disable(i.CULL_FACE),r.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.uniform1i(a.isFullExtent,this._isFullExtent),i.bindBuffer(i.ARRAY_BUFFER,s._texCoordsBuffer),i.vertexAttribPointer(o.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(o.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(o.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(a.extentParamsHigh,this._extentMercParamsHigh),i.uniform4fv(a.extentParamsLow,this._extentMercParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(a.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,s._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,s=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let r=s._framebuffer;r.setSize(this._frameWidth,this._frameHeight),r.activate(),t.programs.geoImageTransform.activate();let n=t.programs.geoImageTransform._program,o=n.attributes,a=n.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,s._texCoordsBuffer),i.vertexAttribPointer(o.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(o.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(o.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(a.extentParamsHigh,this._extentWgs84ParamsHigh),i.uniform4fv(a.extentParamsLow,this._extentWgs84ParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(a.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,s._indexBuffer.numItems,i.UNSIGNED_INT,0),r.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}}const W={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},Tl=["change","idle","play","pause","stop"];class Cl extends ut{constructor(e){super({template:Dt('<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 El=["change"];class Z extends ut{constructor(e={}){super({template:Dt('<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=Zi(e.clientX,t.left,t.right),s=this._startPosX-i;this._startPosX=i,this.value=this._value-s*(this._max-this._min)/this.$panel.clientWidth},this._onMouseUp=()=>{document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(El),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=Zi(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()}set max(t){this._max=t,this.events.stopPropagation(),this.value=this._value+Math.sign(e.wheelDelta)*(this._max-this._min)/100}get max(){return this._max}}const Al=["input"];let Ll=0;class zn extends ut{constructor(e={}){super({template:Dt('<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-"+Ll++,label:e.label||"",value:e.value||"#000000"})}),this._onInput=e=>{this.value=e.target.value},this.events=this.events.registerNames(Al),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 zr{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}}const Ps=class e{constructor(){this.__id=e.__counter__++}get id(){return this.__id}};Ps.__counter__=0;let Me=Ps;class rn extends Q{constructor(e={}){super(e),this._deactivate=!1,this._shiftBusy=!1,this._name="mouseNavigation",this.grabbedPoint=new v,this._eye0=new v,this.pointOnEarth=new v,this.earthUp=new v,this.inertia=.007,this.grabbedSpheroid=new Ft,this.qRot=new F,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 Me}static getMovePointsFromPixelTerrain(e,t,i,s,r,n,o){const a=[];let l=e.eye.clone(),h=e.getBackward(),c=e.getRight(),d=e.getUp(),_=t.getCartesianFromPixelTerrain(r);if(_||(_=t.getCartesianFromPixelTerrain(t.renderer.handler.getCenter())),_){o||(o=v.sub(_,e.eye).normalize());let t=s*e.eye.distance(_)/i;t*=n?-1.25:2;const r=h.scaleTo(t);if(o.dot(e.eye.normal().negate())>=.1){const t=new Ft;t.radius=_.length();let s=[],n=[],u=!1;for(let e=0;e<i;e++){l.addA(r);const i=new V(l,o).hitSphere(t);if(n[e]=l.clone(),!i){u=!0;break}s[e]=(new tt).rotateBetweenVectors(_.normal(),i.normal())}if(u){l=e.eye.clone();for(let e=0;e<i;e++)a[e]={eye:l.addA(r).clone(),v:d,u:c,n:h}}else for(let e=0;e<i;e++){let t=s[e];a[e]={eye:t.mulVec3(n[e]),v:t.mulVec3(d),u:t.mulVec3(c),n:t.mulVec3(h)}}}else for(let e=0;e<i;e++)a[e]={eye:l.addA(o.scaleTo(-t)).clone(),v:d,u:c,n:h};return a}}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(W.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=rn.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",W.KEY_ALT,this.onShiftFree,this),this.renderer.events.on("keyfree",W.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,s=e.minAltitude+this.planet.ellipsoid.polarSize;const r=e.eye.length(),n=this.planet.ellipsoid.cartesianToLonLat(t);if(r>i||r<s)return void this.planet.flyLonLat(new L(n.lon,n.lat));this.renderer.events.isKeyPressed(W.KEY_ALT)?this.planet.flyLonLat(new L(n.lon,n.lat,2*e.eye.distance(t))):this.planet.flyLonLat(new L(n.lon,n.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 V(t.eye,e.direction).hitSphere(this.grabbedSpheroid);if(i){this.scaleRot=1,this.qRot=F.getRotationBetweenVectors(i.normal(),this.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t.rotate(e)}}else{let i=this.grabbedPoint,s=v.add(i,t.getRight()),r=v.add(i,i.normal()),n=new v;new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,s,r),n)===V.INSIDE&&(t.eye=this._eye0.addA(n.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*j;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(W.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,t._f.set(-t._b.x,-t._b.y,-t._b.z)}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(F.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.rotate(i)}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 Pl=["drag","zoom","rotate"],zi=.96;class Yi extends Q{constructor(e={}){super({name:"navigation",autoActivate:!0,...e}),this._freeMode=!1,this._shiftBusy=!1,this._hold=!1,this._onShiftFree=()=>{this._shiftBusy=!1},this._onCameraFly=()=>{this.stop()},this._onMouseMove=e=>{this._active&&this.renderer.events.isKeyPressed(W.KEY_ALT)&&(this._shiftBusy||(this._shiftBusy=!0,this._onRHold(e)),this._onRDown(e))},this._onMouseEnter=e=>{const t=this.renderer.events;t.isKeyPressed(W.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")},this._onMouseLeave=()=>{this.renderer.events.mouseState.leftButtonDown&&this.vel.scale(0),this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this._onRHold=e=>{if((!this.disableRotation||!this.disableTilt)&&this._targetRotationPoint){this._velInertia=.6,this.disableRotation||(this.force_h=.5*(e.x-e.prev_x)),this.disableTilt||(this.force_v=.5*(e.y-e.prev_y));let t=this.planet.camera.getHeading();this._freeMode=!1,!isNaN(t)&&t>45&&t<340&&(this._freeMode=!0)}},this._onRDown=e=>{if((!this.disableRotation||!this.disableTilt)&&this.planet){this.planet.stopFlying();const t=this._getTargetPoint(e.pos);this._targetRotationPoint=t||null,t&&(this._targetZoomPoint=null,this._targetDragPoint=null,this.vel.set(0,0,0),this._tUp=t.getNormal(),this._tRad=this.planet.camera.eye.distance(t))}},this._onMouseWheel=e=>{if(this.planet){this._targetRotationPoint=null,this._targetDragPoint=null;let t=e.x,i=e.y,s=this.planet.camera;if(s.isOrthographic){t=.5*this.renderer.handler.getWidth(),i=.5*this.renderer.handler.getHeight();let e=this._getTargetPoint(new H(t,i));if(!e)return;this._targetZoomPoint=e,this._grabbedSphere.radius=this._targetZoomPoint.length();let r=s.eye.distance(e),n=new v,o=s.unproject(t,i,r,n);const a=n.sub(o.scaleTo(r));if(e=new V(a,o).hitSphere(this._grabbedSphere),!e)return;this._targetZoomPoint=e}else{let e=this._getTargetPoint(new H(t,i));if(!e)return;this._targetZoomPoint=e,this._grabbedSphere.radius=this._targetZoomPoint.length()}if(this._curPitch=s.getPitch(),this._curYaw=s.getYaw(),this._curRoll=s.getRoll(),Math.sign(e.wheelDelta)!==this._wheelDirection)return this.vel.scale(.3),this._currScreenPos.set(t,i),void(this._wheelDirection=Math.sign(e.wheelDelta));this._currScreenPos.set(t,i),this._wheelDirection=Math.sign(e.wheelDelta);let r=20;this._velInertia=.83,this._isTouchPad=e.isTouchPad,e.isTouchPad&&(this._velInertia=.63,r=17);let n=this._targetZoomPoint.sub(s.eye);n.length()>6e3&&this._wheelDirection>0&&s.eye.getNormal().negate().dot(n.normalize())<.3&&(r=4.3);let o=this.planet.camera.eye.distance(this._targetZoomPoint)*r;this.force=e.direction.scale(this._wheelDirection).normalize().scale(this._wheelDirection<0?1.3*o:o).scale(this.zoomSpeed),this.vel.set(0,0,0),this.force_roll=this._curRoll}},this._onLDown=e=>{this.stop(),this._targetRotationPoint=null,this._targetZoomPoint=null,this.planet&&(this.planet.stopFlying(),this._grabbedPoint=this._getTargetPoint(e.pos),this._grabbedPoint&&(this._targetDragPoint=this._grabbedPoint,this.planet.camera.isOrthographic?this._grabbedDist=this.renderer.getDistanceFromPixel(e.pos):this._grabbedDist=this.renderer.activeCamera.eye.distance(this._grabbedPoint),this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this._grabbedSphere.radius=this._grabbedPoint.length(),this._eye0=this.planet.camera.eye.clone(),this._grabbedCameraHeight=this._eye0.length(),this._curPitch=this.planet.camera.getPitch(),this._curYaw=this.planet.camera.getYaw(),this._curRoll=this.planet.camera.getRoll(),this._currScreenPos.copy(e.pos)))},this._onLHold=e=>{if(this._grabbedPoint&&this.planet){let t=this.planet.camera;if(t.isOrthographic){const i=this._grabbedDist,s=new v,r=t.unproject(e.x,e.y,i,s),n=s.sub(r.scaleTo(i)),o=new V(n,r).hitSphere(this._grabbedSphere);if(!o)return;this._targetDragPoint=o;let a=F.getRotationBetweenVectors(this._targetDragPoint.getNormal(),this._grabbedPoint.getNormal()).mulVec3(t.eye);this.force=a.sub(t.eye).scale(this.dragInertia)}else if(t.slope>this.minSlope){this._grabbedDist=t.eye.distance(this._grabbedPoint);let i,s=t.unproject(e.x,e.y,this._grabbedDist),r=new V(t.eye,s).hitSphere(this._grabbedSphere);if(!r)return;if(this._targetDragPoint=r,this.freeMode)i=F.getRotationBetweenVectors(this._targetDragPoint.getNormal(),this._grabbedPoint.getNormal());else{let e=v.NORTH,s=Math.acos(r.dot(e)/this._grabbedSphere.radius)-Math.acos(this._grabbedPoint.dot(e)/this._grabbedSphere.radius),n=t.eyeNorm.dot(v.NORTH);(s>0&&n>=this.poleThreshold||s<0&&n<=-this.poleThreshold)&&(s=0);let o=F.axisAngleToQuat(e.cross(t.eyeNorm).normalize(),-s),a=v.proj_b_to_plane(r,e),l=v.proj_b_to_plane(this._grabbedPoint,e);i=F.getRotationBetweenVectors(a.getNormal(),l.getNormal()).mul(o)}let n=i.mulVec3(t.eye);this.force=n.sub(t.eye).scale(this.dragInertia)}else{let i=this._grabbedPoint,s=v.add(i,t.getRight()),r=v.add(i,i.getNormal()),n=new v;new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,s,r),n);let o=t.eye.add(n.subA(i).negate());this.force=o.sub(t.eye).scale(this.dragInertia),this._targetDragPoint=n}this.vel.set(0,0,0),this._currScreenPos.equal(e.pos)||this._currScreenPos.copy(e.pos),this._hold=!0}},this._onLUp=e=>{this._hold=!1,this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this.events=lt(Pl,this),this.force=new v,this.force_h=0,this.force_v=0,this.vel=new v,this.vel_h=0,this.vel_v=0,this.vel_roll=0,this.force_roll=0,this.mass=null!=e.mass?e.mass:1,this.inertia=null!=e.inertia?e.inertia:1,this._velInertia=zi,this.minSlope=null!=e.minSlope?e.minSlope:.35,this.dragInertia=null!=e.dragInertia?e.dragInertia:170,this.zoomSpeed=null!=e.zoomSpeed?e.zoomSpeed:1,this.poleThreshold=null!=e.poleThreshold?e.poleThreshold:.999,this.disableRotation=null!=e.disableRotation&&e.disableRotation,this.disableTilt=null!=e.disableTilt&&e.disableTilt,this._lookPos=void 0,this._grabbedPoint=null,this._grabbedDist=0,this._targetZoomPoint=null,this._targetDragPoint=null,this._targetRotationPoint=null,this._tUp=new v,this._tRad=0,this._rotHDir=0,this._rotVDir=0,this._wheelDirection=1,this._currScreenPos=new H,this._grabbedSphere=new Ft,this._rot=new F,this._curPitch=0,this._curYaw=0,this._curRoll=0,this._eye0=new v,this._newEye=new v,this._grabbedCameraHeight=0,this._isTouchPad=!1,this._freeMode=!1,this.mode=this._modeToNumber(e.mode||"adaptive")}oninit(){this.renderer&&(this.renderer.events.on("keyfree",W.KEY_ALT,this._onShiftFree),this.renderer.events.on("keyfree",W.KEY_PRINTSCREEN,this._onShiftFree))}onadd(){var e;null!=(e=this.planet)&&e.camera&&this.planet.camera.events.on("flystart",this._onCameraFly)}onremove(){var e;null!=(e=this.planet)&&e.camera&&this.planet.camera.events.off("flystart",this._onCameraFly)}onactivate(){super.onactivate();let e=this.renderer;e.events.on("mousewheel",this._onMouseWheel),e.events.on("rhold",this._onRHold),e.events.on("rdown",this._onRDown),e.events.on("lhold",this._onLHold),e.events.on("ldown",this._onLDown),e.events.on("lup",this._onLUp),e.events.on("draw",this.onDraw,this,-1e3),e.events.on("mousemove",this._onMouseMove),e.events.on("mouseleave",this._onMouseLeave),e.events.on("mouseenter",this._onMouseEnter)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("mousewheel",this._onMouseWheel),e.events.off("rhold",this._onRHold),e.events.off("rdown",this._onRDown),e.events.off("lhold",this._onLHold),e.events.off("ldown",this._onLDown),e.events.off("lup",this._onLUp),e.events.off("draw",this.onDraw),e.events.off("mousemove",this._onMouseMove),e.events.off("mouseleave",this._onMouseLeave),e.events.off("mouseenter",this._onMouseEnter)}onDraw(){this._updateVel(),this._handleZoom(),this._handleDrag(),this._handleRotation()}_handleRotation(){if((!this.disableRotation||!this.disableTilt)&&this.planet&&this._targetRotationPoint){let e=this.planet.camera;if((this.disableRotation||0===this.vel_h)&&(this.disableTilt||0===this.vel_v))return;if(!this.disableRotation){let t=this.vel_h*this.dt;e.rotateHorizontal(t,!1,this._targetRotationPoint,this._tUp)}if(!this.disableTilt){let t=this.vel_v*this.dt;e.rotateVertical(t,this._targetRotationPoint,.1)}this.events.dispatch(this.events.rotate,this),this._curPitch=e.getPitch(),this._curYaw=e.getYaw(),this._curRoll=e.getRoll(),this._velInertia=zi}}_getTargetPoint(e){return this.planet?this.planet.camera.isOrthographic?this.renderer.getCartesianFromPixel(e)||null:this.planet.camera.getAltitude()>8e4?this.planet.getCartesianFromPixelEllipsoid(e)||null:this.planet.getCartesianFromPixelTerrain(e)||null:null}get freeMode(){return 1!==this.mode&&(0===this.mode||this._freeMode)}setMode(e){this.mode=this._modeToNumber(e)}_modeToNumber(e){switch(e){case"lockNorth":return 1;case"free":return 0;default:return 2}}_handleDrag(){if(this.planet&&this._targetDragPoint&&this._grabbedPoint&&this.vel.length()>.1){this._velInertia=zi;let e=this.planet.camera;if(e.slope>this.minSlope){let t=this.vel.scaleTo(this.dt),i=v.proj_b_to_plane(t,e.eyeNorm),s=e.eye.add(i).normalize().scale(this._grabbedCameraHeight);if(this.freeMode){let t=F.getRotationBetweenVectors(e.eye.getNormal(),s.getNormal());e.rotate(t),e.eye.copy(s)}else{let t=s.getNormal().dot(v.NORTH),i=e.eyeNorm.dot(v.NORTH);(t>i&&t>=this.poleThreshold||t<i&&t<=-this.poleThreshold)&&this.vel.scale(.8),e.eye.copy(s),this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll)}}else{let t=this.vel.scaleTo(this.dt),i=e.eye.add(t);e.eye.copy(i),e.checkTerrainCollision(),this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll)}this.events.dispatch(this.events.drag,this)}}_corrRoll(){this.planet.camera.slope<.5&&(this._curRoll-=this.vel_roll*this.dt,this._curRoll<.01*Math.PI/180&&(this._curRoll=.01*Math.PI/180))}_handleZoom(){if(this._targetZoomPoint&&this.vel.length()>.1){let e=this.planet.camera,t=this._targetZoomPoint,i=e.eye.clone(),s=t.sub(e.eye).normalize(),r=this.vel.getNormal(),n=Math.sign(r.dot(e.getForward())),o=this.vel.scaleTo(this.dt);this._grabbedSphere.radius>i.length()&&(n*=-1);let a=e.getForward().scaleTo(n*o.length());i.addA(a),this.events.dispatch(this.events.zoom,this);let l=e.maxAltitude+this.planet.ellipsoid.getEquatorialSize();if(i.length()>l)return void i.copy(i.getNormal().scale(l));let h=new V(i,s).hitSphere(this._grabbedSphere);if(!h)return void this.vel.set(0,0,0);let c=F.getRotationBetweenVectors(h.getNormal(),t.getNormal());if(e.eye=c.mulVec3(i),e.rotate(c),!this.freeMode){this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll),e.update();let i=e.unproject2v(this._currScreenPos,e.eye.distance(this._targetZoomPoint)),s=t.sub(e.eye).normalize(),r=new v,n=new v,o=vt.fromPoints(t,t.add(e.getUp()),t.add(e.getRight()));new V(e.eye,i).hitPlaneRes(o,r),new V(e.eye,s).hitPlaneRes(o,n);let a=n.sub(r);e.eye=e.eye.add(a),this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll)}if(e.checkTerrainCollision(),e.isOrthographic){let t=e.getAltitude();t&&(e.focusDistance=Math.abs(t))}}}_updateVel(){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(this.velocityInertia),this.vel.length()<.001&&this.vel.set(0,0,0),this.force.set(0,0,0),this._updateVel_h(),this._updateVel_v(),this._updateVel_roll()}_updateVel_h(){let e=this.force_h/this.mass;this.vel_h+=e,this.vel_h*=this.velocityInertia,Math.abs(this.vel_h)<.001&&(this.vel_h=0),this.force_h=0}_updateVel_v(){let e=this.force_v/this.mass;this.vel_v+=e,this.vel_v*=this.velocityInertia,Math.abs(this.vel_v)<.001&&(this.vel_v=0),this.force_v=0}_updateVel_roll(){let e=this.force_roll/this.mass;this.vel_roll+=e,this.vel_roll*=this.velocityInertia,this.force_roll=0}get dt(){return.001*this.renderer.handler.deltaTime}get velocityInertia(){return this._velInertia*this.inertia}stop(){this.vel.set(0,0,0),this.vel_h=0,this.vel_v=0,this._velInertia=zi,this._targetZoomPoint=null,this._grabbedPoint=null,this._targetRotationPoint=null,this._targetDragPoint=null}}const Dn=e=>e>1e3?`${(e/1e3).toFixed(1)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`;let Sl=$.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);const Rl={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]},Fn={scale:1,instanced:!0,tag:"ruler",color:"rgb(0,305,0)",object3d:Sl};class ua extends de{constructor(e={}){super(e.name),this._onCornerLdown=e=>{var t,i;if(!this._startLonLat){null==(i=null==(t=this.renderer)?void 0:t.controls.navigation)||i.deactivate(),this._startClick.set(e.x,e.y);let s=e.pickingObject.getCartesian();this._startPos=this._planet.getPixelFromCartesian(s),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=()=>{var e;this._pickedCorner&&(null==(e=this.renderer.controls.navigation)||e.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=lt(Ml),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 H,this._anchorLonLat=null,this._heading=0,this._trackLayer=new _t("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._labelLayer=new _t("ruler-label",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-100,relativeToGround:!0,hideInLayerSwitcher:!0}),this._cornersLayer=new _t("corners",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[100,4e6,1],pickingScale:2}),this._propsLabel=new G({name:"propsLabel",label:Rl}),this._trackEntity=new G({polyline:{path3v:[],thickness:4.8,color:"rgb(255,131,0)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01,this._cornerEntity=[new G({geoObject:Fn,properties:{name:"start"}}),new G({geoObject:Fn,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 s=this._planet.ellipsoid.lonLatToCartesian(t),r=this._planet.ellipsoid.inverse(e,t),n=r.distance;this._heading=r.initialAzimuth;let o=[],a=s.sub(i),l=a.length();a.normalize();for(let e=0;e<120;e++){let t=a.scaleTo(e*l/120).addA(i);o.push(t)}o.push(s),this._trackEntity.polyline.setPath3v([o]),this._ignoreTerrain&&(this._propsLabel.setCartesian3v(o[Math.floor(o.length/2)]),this._propsLabel.label.setText(`${Dn(n)}, ${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,s=e.length-1;i<s;i++)t+=e[i+1].distance(e[i]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label.setText(`${Dn(t)}, ${Math.round(this._heading)} deg`)}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Ml=["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 _a extends Q{constructor(e={}){super(e),this._rulerScene=new ua({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 Bl=$.createCylinder(1.1,0,2,6,1,!0,!0,0,0,0);const On={startColor:"rgb(255,131,0)",endColor:"rgb(255,131,0)",thickness:5},Ys={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]},Nn={scale:1,instanced:!0,tag:"height-ruler",color:"rgb(255,131,0)",object3d:Bl};class kl extends ua{constructor(e={}){super(e),this._geoRulerLayer=new _t("rayHeightRuler",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-2,relativeToGround:!1,hideInLayerSwitcher:!0}),this._rayV=new G({name:"verticalRay",ray:On}),this._rayH=new G({name:"heightRay",ray:On}),this._heightLabels=[new G({name:"startCornerLabel",label:{...Ys}}),new G({name:"endCornerLabel",label:{...Ys}}),new G({name:"deltaLabel",label:{...Ys}})]}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 G({geoObject:Nn,properties:{name:"start"}}),new G({geoObject:Nn,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 Hn extends _a{constructor(e={}){super(e),this._rulerScene=new kl({name:`heightRulerScene:${this.__id}`,ignoreTerrain:!1})}}const Ws=[.001,.005,.01,.05,.1,.2,.5,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 fa extends Q{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 Wr(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,s=this.planet.getDistanceFromPixel(i)||0;0===s&&(i=t.project3v(v.ZERO),s=this.planet.getDistanceFromPixel(i)||0);let r=t.getForward().scaleTo(s).addA(t.eye),n=s*Math.tan(t.viewAngle*j),o=r.add(t.getRight().scaleTo(n)),a=t.project3v(o);this._mPx=n/a.distance(i);let l=this._mPx*this._minWidth,h=Re(Ws,l,((e,t)=>e-t));h<0&&(h=~h);let c=Ws[h],d=(c-l)/(Ws[h+1]-c);this.currWidth=this._minWidth+d*(this._maxWidth-this._minWidth),this._scaleLabelEl.innerText=c>=1e3?c/1e3+" km":c>=1?`${c} m`:c>=.01?100*c+" cm":1e3*c+" mm",this._metersInMinSize=l,this.el.style.width=this.currWidth+"px"}}class ga extends Q{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 cr([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}get colorTwo(){let e=this._colorTwo;return cr([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}set colorOne(e){let t=ts(e);this._colorOne[0]=t.x,this._colorOne[1]=t.y,this._colorOne[2]=t.z}set colorTwo(e){let t=ts(e);this._colorTwo[0]=t.x,this._colorTwo[1]=t.y,this._colorTwo[2]=t.z}oninit(){this.renderer.handler.addProgram(new X("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,s=i.uniforms,r=e.gl,n=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(s.camPos,[n.eye.x,n.eye.y,n.eye.z]),r.uniform2fv(s.iResolution,[e.getWidth(),e.getHeight()]),r.uniform1f(s.fov,n.getViewAngle()),r.uniform1f(s.earthRadius,this.planet.ellipsoid.getPolarSize()+1),r.uniform3fv(s.colorOne,this._colorOne),r.uniform3fv(s.colorTwo,this._colorTwo),r.uniformMatrix4fv(s.viewMatrix,!1,n.getViewMatrix()),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}}const $s=14959787e4;function Xs(e){var t=e-es,i=282.9404+470935e-10*t,s=.016709-1.151e-9*t,r=hr(356.047+.9856002585*t),n=23.4392911-3.563e-7*t,o=r+J*s*Math.sin(r*j)*(1+s*Math.cos(r*j)),a=Math.cos(o*j)-s,l=Math.sin(o*j)*Math.sqrt(1-s*s),h=Math.sqrt(a*a+l*l),c=hr(Math.atan2(l,a)*J+i),d=a=h*Math.cos(c*j),_=(l=h*Math.sin(c*j))*Math.cos(n*j),u=l*Math.sin(n*j),f=Xi*(24*t/23.9344694-259.853/360);return F.zRotation(-f).mulVec3(new v(-d*$s,-_*$s,u*$s))}class Il{constructor(e){this._renderNode=null,this._position=e.position||new v,this._ambient=e.ambient||new v,this._diffuse=e.diffuse||new v(.8,.8,.8),this._specular=e.specular||new v(.18,.18,.18),this._shininess=null!=e.shininess?e.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}isActive(){return this._active}setPosition3v(e){this.setPosition(e.x,e.y,e.z)}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,this._renderNode&&(this._renderNode._lightPosition[0]=e,this._renderNode._lightPosition[1]=t,this._renderNode._lightPosition[2]=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 s=this._renderNode;s&&(s._lightParams[0]=e,s._lightParams[1]=t,s._lightParams[2]=i)}setDiffuse(e,t,i){this._diffuse.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[3]=e,s._lightParams[4]=t,s._lightParams[5]=i)}setSpecular(e,t,i){this._specular.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[6]=e,s._lightParams[7]=t,s._lightParams[8]=i)}setShininess(e){this._shininess=e;const t=this._renderNode;t&&(t._lightShininess=e)}addTo(e){this._renderNode=e,this.setShininess(this._shininess),this.setAmbient3v(this._ambient),this.setDiffuse3v(this._diffuse),this.setSpecular3v(this._specular)}}class Dr extends Q{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 Il({ambient:new v(.15,.15,.25),diffuse:new v(.9,.9,.8),specular:new v(.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(Xs(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.getUp().dot(t))),e.slope>.99&&(i=e.getUp());let s=v.proj_b_to_plane(i,t,i).normalize().scale(this.offsetVertical),r=v.proj_b_to_plane(e.getRight(),t,e.getRight()).normalize().scale(this.offsetHorizontal),n=s.add(r),o=e.eye.add(n);if(this._k>0){this._k-=.001;let e=F.getRotationBetweenVectors(this.sunlight._position.normal(),o.normal()).slerp(F.IDENTITY,this._k).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else this.sunlight.setPosition3v(o)}else if(this._k=1,this._f>0){this._f-=.001;let e=F.getRotationBetweenVectors(this.sunlight._position.normal(),Xs(this._currDate).normal()).slerp(F.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(Xs(this._currDate)),this._f=0)}}}const zl=["inertiamove","drag","doubletapzoom"];class Vn{constructor(){this.x=0,this.y=0,this.prev_x=0,this.prev_y=0,this.grabbedPoint=null,this.grabbedSpheroid=new Ft,this._vec=new H,this._vecPrev=new H}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 pa extends Q{constructor(e={}){super(e),this._onCameraFly=()=>{this.stopRotation()},this._name="touchNavigation",this.events=lt(zl,this),this.grabbedPoint=new v,this.inertia=null!=e.inertia?e.inertia:.007,this.minSlope=null!=e.minSlope?e.minSlope:.1,this.jerkLimit=null!=e.jerkLimit?e.jerkLimit:.3,this.grabbedSpheroid=new Ft,this.planet=null,this.qRot=new F,this.scaleRot=0,this.rot=1,this._eye0=new v,this.pointOnEarth=null,this.earthUp=null,this.touches=[new Vn,new Vn],this._keyLock=new Me,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))}onadd(){var e;null!=(e=this.planet)&&e.camera&&this.planet.camera.events.on("flystart",this._onCameraFly)}onremove(){var e;null!=(e=this.planet)&&e.camera&&this.planet.camera.events.off("flystart",this._onCameraFly)}onTouchStart(e){const t=this.renderer.handler;if(this._touching=!0,2===e.sys.touches.length){const i=this.touches[0],s=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 H(i.x,i.y))||null,s.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*t.pixelRatio,s.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*t.pixelRatio,s.prev_x=s.x,s.prev_y=s.y,s.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new H(s.x,s.y))||null,this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter())||null,this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal()),i.grabbedPoint&&s.grabbedPoint&&(i.grabbedSpheroid.radius=i.grabbedPoint.length(),s.grabbedSpheroid.radius=s.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 L(e.lon,e.lat,.57*this.planet.camera.eye.distance(t))),this.events.dispatch(this.events.doubletapzoom,this)}}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],n=this.touches[1];if(!r.grabbedPoint||!n.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,n.prev_x=n.x,n.prev_y=n.y,n.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*i.pixelRatio,n.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*i.pixelRatio;const o=r.vec.add(n.vec).scale(.5),a=this.planet.getCartesianFromPixelEllipsoid(o);if(a){this.pointOnEarth=a;const e=Math.atan2(r.prev_y-n.prev_y,r.prev_x-n.prev_x),i=Math.atan2(r.y-n.y,r.x-n.x)-e,o=t.eye.distance(this.pointOnEarth),l=r.vec.sub(n.vec),h=r.vecPrev.sub(n.vecPrev);let c=l.length()/h.length();const d=1+this.jerkLimit,_=1-this.jerkLimit;c=c>d?d:c<_?_:c;let u=o*-(1-c);t.eye.addA(t.getForward().scale(u)),t.rotateAround(-i,!1,this.pointOnEarth,this.earthUp);const f=r.vec.add(n.vec).scale(.5),g=r.vecPrev.add(n.vecPrev).scale(.5),p=f.sub(g).scale(-1);var s=.5/o*t._lonLat.height*j;s>.003&&(s=.003),t.rotateHorizontal(s*-p.x,!1,this.pointOnEarth,this.earthUp),t.rotateVertical(s*-p.y,this.pointOnEarth,this.minSlope),t.checkTerrainCollision(),t.update(),this.events.dispatch(this.events.drag,this)}this.scaleRot=0}else if(1===e.sys.touches.length){let s=this.touches[0];if(s.prev_x=s.x,s.prev_y=s.y,s.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,s.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,!s.grabbedPoint)return;this.planet.stopFlying();let r=e.direction,n=new V(t.eye,r).hitSphere(s.grabbedSpheroid);if(n)if(t.slope>.2){this.qRot=F.getRotationBetweenVectors(n.normal(),s.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t.rotate(e),t.checkTerrainCollision(),t.update(),this.events.dispatch(this.events.drag,this),this.scaleRot=1}else{let e=s.grabbedPoint,i=v.add(e,t.getUp()),r=v.add(e,e.getNormal()),n=t.unproject(s.x,s.y),o=new v;new V(t.eye,n).hitPlaneRes(vt.fromPoints(e,i,r),o)===V.INSIDE&&(t.eye=this._eye0.addA(o.subA(e).negate()),t.checkTerrainCollision(),t.update(),this.events.dispatch(this.events.drag,this),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(F.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.rotate(i),t.checkTerrainCollision(),t.update(),this.events.dispatch(this.events.inertiamove,this)}this.setLock(t.eye.distance(i)/t.getAltitude()>.01)}}setLock(e){e?(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 ma extends Q{constructor(e={}){super(e),this._keyLock=new Me,this._move=0,this._targetPoint=null}oninit(){let e=new ce({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 ce({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 Dl extends de{constructor(e={}){var t,i;super(e.name),this._ignoreTerrain=!1,this.events=new bi(Fl),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 G({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]}}),null==(i=null==(t=this._propsLabel)?void 0:t.label)||i.setVisibility(!1),this._trackEntity=new G({polyline:{path3v:[],thickness:3.8,color:"rgb(455,455,455)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01;let s=$.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);this._cornerEntity=[new G({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(0,305,0)",object3d:s},properties:{name:"start"}}),new G({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(455,0,0)",object3d:s},properties:{name:"end"}})],this._trackLayer=new _t("track",{entities:[this._trackEntity,this._propsLabel],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!1}),this._cornersLayer=new _t("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(){var e,t,i,s,r;null==(t=null==(e=this._propsLabel)?void 0:e.label)||t.setVisibility(!1),this._onMouseMove_=this._onMouseMove.bind(this),null==(i=this.renderer)||i.events.on("mousemove",this._onMouseMove_,this),this._onMouseLdown_=this._onMouseLdown.bind(this),null==(s=this.renderer)||s.events.on("ldown",this._onMouseLdown_,this),this._onMouseLup_=this._onMouseLup.bind(this),null==(r=this.renderer)||r.events.on("lup",this._onMouseLup_,this),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer)}_deactivate(){var e,t,i;this._startLonLat=null,this._trackLayer.remove(),this._cornersLayer.remove(),null==(e=this.renderer)||e.events.off("mousemove",this._onMouseMove_),null==(t=this.renderer)||t.events.off("ldown",this._onMouseLdown_),null==(i=this.renderer)||i.events.off("lup",this._onMouseLup_),this.clear(),this._onMouseMove_=null,this._onMouseLdown_=null,this._onMouseLup_=null}_onMouseLdown(e){var t,i,s,r,n,o;if(e.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.renderer.handler.canvas.style.cursor="pointer",!this._startLonLat){null==(t=this._propsLabel.label)||t.setVisibility(!1),null==(i=this._trackEntity.polyline)||i.setPath3v([]),null==(s=this._cornerEntity[0].geoObject)||s.setVisibility(!0),null==(r=this._cornerEntity[1].geoObject)||r.setVisibility(!0),null==(o=null==(n=this.renderer)?void 0:n.controls.navigation)||o.deactivate(),this._startLonLat=this._planet.getLonLatFromPixelTerrain(e);let a=this._planet.ellipsoid.lonLatToCartesian(this._startLonLat);this._cornerEntity[0].setCartesian3v(a),this._cornerEntity[1].setCartesian3v(a)}}_onMouseLup(e){var t,i,s;if(this._startLonLat){if(this._pickedCorner=null,this._anchorLonLat=null,null==(t=this._propsLabel.label)||t.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",null==(s=null==(i=this.renderer)?void 0:i.controls.navigation)||s.activate()}_drawLine(e,t,i){var s;i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let r=this._planet.ellipsoid.lonLatToCartesian(t),n=this._planet.ellipsoid.direct(e,t);this._heading=n.initialAzimuth;let o=[];this._cornerEntity[0].setCartesian3v(i),this._cornerEntity[1].setCartesian3v(r);let a=[i,this._planet.ellipsoid.lonLatToCartesian(new L(t.lon,e.lat,e.height)),r,this._planet.ellipsoid.lonLatToCartesian(new L(e.lon,t.lat,e.height)),i];o.push(i);let l=(e,t)=>{let i=t.sub(e),s=i.length();i.normalize();for(let t=0;t<120;t++){let r=i.scaleTo(t*s/120).addA(e);o.push(r)}};for(let e=0;e<a.length-1;e++)l(a[e],a[e+1]);null==(s=this._trackEntity.polyline)||s.setPath3v([o]),this._ignoreTerrain}_onMouseMove(e){var t;if(this._startLonLat){null==(t=this._propsLabel.label)||t.setVisibility(!0);let i=this._planet.getLonLatFromPixelTerrain(e);if(!i)return;this._drawLine(this._startLonLat,i)}}clear(){var e,t,i;null==(e=this._trackEntity.polyline)||e.clear(),null==(t=this._cornerEntity[0].geoObject)||t.setVisibility(!1),null==(i=this._cornerEntity[1].geoObject)||i.setVisibility(!1)}frame(){var e,t;let i=null==(e=this._trackEntity.polyline)?void 0:e.getPath3v()[0];if(i&&!this._ignoreTerrain){let e=0;for(let t=0,s=i.length-1;t<s;t++)e+=i[t+1].distance(i[t]);this._propsLabel.setCartesian3v(i[Math.floor(i.length/2)]),null==(t=this._propsLabel.label)||t.setText(`${s=e,s>1e3?`${(s/1e3).toFixed(1)} km`:s>9?`${Math.round(s)} m`:`${s.toFixed(1)} m`}, ${Math.round(this._heading)} deg`)}var s}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Fl=["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 te(e,t){return new Date(+e+1e3*t)}function Ol(e,t=!0,i=!1){let s=Hl[e.getMonth()],r=e.getUTCDate(),n=e.getUTCFullYear();if(t){let t=e.getUTCHours().toString().padStart(2,"0"),o=e.getUTCMinutes().toString().padStart(2,"0"),a=e.getUTCSeconds().toString().padStart(2,"0");return i?`${s} ${r} ${n} ${t}:${o}:${a}.${e.getUTCMilliseconds().toString().padStart(3,"0")}`:`${s} ${r} ${n} ${t}:${o}:${a}`}return`${s} ${r} ${n}`}function Un(e,t=0,i=10,s=2,r="white"){e.lineWidth=s,e.strokeStyle=r,e.beginPath(),e.moveTo(t,0),e.lineTo(t,i),e.stroke()}function Nl(e,t,i,s,r="12px Arial",n="black",o="left",a="bottom",l=0){e.save(),e.translate(i,s),e.rotate(l*j),e.fillStyle=n,e.textBaseline=a,e.font=r,e.textAlign=o,e.fillText(t,0,0),e.restore()}const Zs=[[.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]],Hl=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Vl=["change","current"];class Ul{constructor(e={}){this.events=lt(Vl),this._current=e.current||new Date,this._rangeStart=e.rangeStart||new Date,this._rangeEnd=e.rangeEnd||te(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 Fe=.001,Gl=["startdrag","stopdrag","startdragcurrent","stopdragcurrent","setcurrent","reset","play","playback","pause","visibility"],Gn="#bfbfbf";class jl extends ut{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 Ul({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,s=-(i-.5*this.clientWidth),r=this.model.rangeStartTime+this._millisecondsInPixel*i;this._zoom(r,s,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*Fe;this.model.set(te(this._clickRangeStart,t),te(this._clickRangeEnd,t))}else if(this._isCurrentDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*Fe,i=te(this._clickCurrentDate,-t);i>=this.model.rangeStart&&i<=this.model.rangeEnd&&(this.model.current=te(this._clickCurrentDate,-t))}},this.events=this.events.registerNames(Gl),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 dt({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 dt({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 jo({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 s=(e-(this.model.rangeStartTime+.5*this.model.range))*Fe,r=te(this.model.rangeStart,s),n=te(this.model.rangeEnd,s),o=(n.getTime()-r.getTime())/20*Fe,a=te(r,o*i),l=te(n,-o*i),h=(l.getTime()-a.getTime())/this.clientWidth;if(h<31536e6&&h>.1){let e=h*t*Fe;this.model.set(te(a,e),te(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=Zs.length;t<i;t++)if(Zs[t][0]>e)return Zs[t-1]}(this._minWidth*this._millisecondsInPixel*Fe);if(e){this._clearCanvas();let i=1e3*e[0],s=i/this._millisecondsInPixel,r=e[1],n=(t=this.model.rangeStartTime)-t%i,o=e[0]<1,a=e[0]<86400;for(let e=n,t=this.model.rangeEndTime+i;e<t;e+=i){let t=this.getOffsetByTime(e);t>=0&&t<=this.clientWidth*this._canvasScale&&Un(this._ctx,t*this._canvasScale,10*this._canvasScale,2*this._canvasScale,Gn);for(let e=1;e<r;e++){let i=t+e*(s/r);i>=0&&i<=this.clientWidth*this._canvasScale&&Un(this._ctx,i*this._canvasScale,5*this._canvasScale,1*this._canvasScale,Gn)}Nl(this._ctx,Ol(new Date(e),a,o),t*this._canvasScale,26*this._canvasScale,"24px monospace","#bfbfbf","center")}this._drawCurrent()}var t}}function jn(e,t){const i=new Date(e);return i.setHours(i.getHours()+t),i}class pi{constructor(){this.resolve=()=>{},this.reject=()=>{},this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t})),Object.freeze(this)}}const ql=["startcollecting","profilecollected","clear"];class Yl{constructor(e={}){this.events=lt(ql),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,s){this._minX=e,this._maxX=t,i&&(this._minY=i),s&&(this._maxY=s)}_getHeightAsync(e,t,i){let s=new pi;if(this.planet){let r=this.planet.terrain.geoid.getHeightLonLat(e);this.planet.terrain.getHeightAsync(e,(n=>{this.planet&&i===this._promiseCounter?(n+=r,this._pGroundCoords[t][1]=n,this._pGroundCoords[t][2]=0,this._pGroundCoords[t][3]=e.height,n>this._pMaxY&&(this._pMaxY=n),n<this._pMinY&&(this._pMinY=n),this._updatePointType(t),s.resolve(n)):s.reject()}))}else s.reject();return s.promise}_collectCoordsBetweenTwoTrackPoints(e,t,i,s,r,n){if(this.planet)for(let o=1;o<=t;o++){this._pDist+=1,this._pIndex++;let t=o*i,a=s.add(r.scaleTo(t)),l=this.planet.ellipsoid.cartesianToLonLat(a);this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,e],((e,t)=>{this._promiseArr.push(this._getHeightAsync(e,t,n))})(l,this._pIndex)}}_collectAllPoints(e,t){if(!this.planet||t!==this._promiseCounter)return;let i=new v,s=new v;for(let r=1,n=e.length;r<n;r++){let n=e[r-1],o=e[r];this.planet.ellipsoid.lonLatToCartesianRes(n,i),this.planet.ellipsoid.lonLatToCartesianRes(o,s);let a=s.sub(i),l=a.length(),h=this.planet.ellipsoid.getSurfaceNormal3v(i),c=v.proj_b_to_plane(a,h),d=c.length(),_=Math.floor(d/1),u=1*l/d;this._getGroundElevation(n,r-1,t),c.normalize(),a.normalize(),this._collectCoordsBetweenTwoTrackPoints(r-1,_,u,i,a,t),this._pDist+=d-1*_,this._pIndex++;let f=o.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,s)=>{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 pi;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 va="rgb(198, 198, 198)",qn=[va,"rgb(255, 255, 0)","rgb(255, 0, 0)"],Wl=["startdrag","stopdrag","pointer","mouseenter","mouseleave","dblclick","tracklength","groundlength","warninglength","collisionlength"];class $l extends ut{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 Yl}),this._onMouseDblClick=e=>{let t,i=this.$canvas.getBoundingClientRect(),s=e.clientX-i.left,r=this._leftDistance+(this._rightDistance-this._leftDistance)*s/this.clientWidth,n=this.model.drawData[1],o=this.model.drawData[0];r<0?(t=1,r=0,s=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):r>this.model.planeDistance?(t=n.length-1,r=this.model.planeDistance,s=(r-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-Re(n,r,((e,t)=>e-t[0]));let a=n[t-1],l=n[t],h=(r-a[0])/(l[0]-a[0]),c=a[1]+h*(l[1]-a[1]),d=a[4],_=o[d],u=o[d+1];h=(r-_[0])/(u[0]-_[0]);let f=_[1]+h*(u[1]-_[1]);this.events.dispatch(this.events.dblclick,r,_,u,a,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(),s=e.clientX-i.left,r=s-.5*this.$canvas.clientWidth,n=r*this._canvasScale/this._pixelsInMeter_x,o=n+this._leftDistance+t,a=n+this._rightDistance-t;n=-r*(a-o)/this.clientWidth,this.setFrame(o+n,a+n),this.redrawPointerCanvas(s)}},this.events=this.events.registerNames(Wl),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,s=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=s.length-1,i=this.model.planeDistance,e=(i-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-Re(s,i,((e,t)=>e-t[0]));let n=s[t-1],o=s[t],a=(i-n[0])/(o[0]-n[0]),l=n[1]+a*(o[1]-n[1]),h=n[4],c=r[h],d=r[h+1];a=(i-c[0])/(d[0]-c[0]);let _=c[1]+a*(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,n,o,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=Ge(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 s=e[0];const r=this.model.maxY;let n=(-this._leftDistance+s[0])*this._pixelsInMeter_x,o=(r-s[1])*this._pixelsInMeter_y;t[s[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(n-4,o-4,8,8),i.stroke(),i.fillStyle="white",i.font=26/devicePixelRatio+"px Arial",i.textBaseline="bottom",i.textAlign="left",i.fillText(`${Math.round(s[1]-t[s[2]][1]).toString()} m`,n+1,o-10),i.stroke();for(let s=1,a=e.length;s<a;s++){let a=e[s];n=(-this._leftDistance+a[0])*this._pixelsInMeter_x,o=(r-a[1])*this._pixelsInMeter_y,t[a[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(n-4,o-4,8,8),i.stroke(),i.fillStyle="white",i.fillText(`${Math.round(a[1]-t[a[2]][1]).toString()} m`,n+1,o-10),i.stroke()}}}_drawTrack(e,t){let i=e[0],s=this._ctx;if(s){const r=this.model.maxY;s.lineWidth=5,s.strokeStyle="rgb(0, 255, 50)",s.beginPath(),s.moveTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(r-i[1])*this._pixelsInMeter_y);let n=0;for(let t=1,i=e.length;t<i;t++){let i=e[t];s.lineTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(r-i[1])*this._pixelsInMeter_y);let o=e[t-1],a=i[0]-o[0],l=i[1]-o[1],h=a*a,c=l*l;n+=Math.sqrt(h+c)}s.stroke(),s.lineWidth=2,s.strokeStyle="rgba(255,255,255,0.7)",s.beginPath();let o=(-this._leftDistance+i[0])*this._pixelsInMeter_x,a=(r-i[1])*this._pixelsInMeter_y,l=(r-t[i[2]][1])*this._pixelsInMeter_y;s.moveTo(o,a),s.lineTo(o,l);for(let i=1,n=e.length;i<n;i++){let n=e[i];o=(-this._leftDistance+n[0])*this._pixelsInMeter_x,a=(r-n[1])*this._pixelsInMeter_y,l=(r-t[n[2]][1])*this._pixelsInMeter_y,s.strokeStyle="rgba(255,255,255,0.7)",s.moveTo(o,a),s.lineTo(o,l)}s.stroke(),this.events.dispatch(this.events.tracklength,n)}}_drawTerrain(e){let t=e[0],i=this._ctx;if(i){const s=this.model.maxY;i.lineWidth=5,i.strokeStyle=va,i.beginPath(),i.moveTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,this.$canvas.height),i.lineTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,(s-t[1])*this._pixelsInMeter_y);let r=0;for(let t=1,n=e.length;t<n;t++){let n=e[t];i.lineTo((-this._leftDistance+n[0])*this._pixelsInMeter_x,(s-n[1])*this._pixelsInMeter_y);let o=e[t-1],a=n[0]-o[0],l=n[1]-o[1],h=a*a,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 s=0,r=0;for(let n=0,o=e.length-1;n<o;n++){let o=e[n],a=e[n+1];if(0!==o[2]&&0!==a[2]){let e=a[0]-o[0],n=a[1]-o[1],l=e*e,h=n*n;2===o[2]?(t.stroke(),t.beginPath(),t.strokeStyle=qn[2],r+=Math.sqrt(l+h)):1===o[2]&&(t.stroke(),t.beginPath(),t.strokeStyle=qn[1],s+=Math.sqrt(l+h)),t.moveTo((-this._leftDistance+o[0])*this._pixelsInMeter_x,(i-o[1])*this._pixelsInMeter_y),t.lineTo((-this._leftDistance+a[0])*this._pixelsInMeter_x,(i-a[1])*this._pixelsInMeter_y)}}t.stroke(),this.events.dispatch(this.events.warninglength,s),this.events.dispatch(this.events.collisionlength,r)}}}let Xl=$.createCylinder(.33,0,1,20,1,!0,!1,0,0,0),Zl=$.createCylinder(.33,.33,1.1,20,1,!0,!0,0,-.55,0);const Kl={startPosition:new v,endPosition:new v,startColor:"rgba(255,131,0,0.2)",endColor:"rgba(255,131,0,1.0)",thickness:2.7},Ql={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]},Jl={text:"",face:"arial",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]},Yn={face:"arial",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]},th={instanced:!0,tag:"ground-pointer",color:"rgb(0,305,0)",object3d:Xl},eh={instanced:!0,tag:"head-pointer",color:"rgb(305,305,0)",object3d:Zl};class ih extends de{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 H(e.x,e.y).sub(this._startClickPos),i=this._startEntityPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);s&&this.setGroundPointCartesian3v(this._pickedGroundEntity.properties.index,s)}else if(this._pickedHeadEntity){let t=this._planet.camera,i=this._pickedHeadEntity.properties.groundEntity.getCartesian(),s=this._planet.ellipsoid.getSurfaceNormal3v(i),r=i.add(s),n=i.add(t.getRight()),o=new v;if(new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,r,n),o)===V.INSIDE){let e=v.proj_b_to_a(o,i),t=e.sub(i).dot(i),r=i.add(s.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.navigation.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.navigation.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.navigation.deactivate(),this._pickedHeadEntity=e.pickingObject},this._onHeadPointerLUp=e=>{this.renderer.controls.navigation.activate(),this._pickedHeadEntity=null},this.events=lt(sh),this._planet=e.planet||null,this._pickedGroundEntity=null,this._pickedHeadEntity=null,this._startClickPos=new H,this._startEntityPos=new H,this._clampToGround=!0,this._trackLayer=new _t("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._groundPointersLayer=new _t("ground-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,5e3,.02],pickingScale:1.5}),this._headPointersLayer=new _t("head-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,1e4,.02],pickingScale:1}),this._columnPointersLayer=new _t("column-pointers",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._trackEntity=new G({polyline:{path3v:[],thickness:3.8,color:"rgba(0,305,0,0.8)",isClosed:!1}}),this._trackLayer=new _t("column-pointers",{entities:[this._trackEntity],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._heightsLayer=new _t("heights-labels",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._pointerHeadEntity=new G({cartesian:new v,billboard:Ql}),this._pointerLabelEntity=new G({cartesian:new v,label:Jl}),this._pointerRayEntity=new G({cartesian:new v,ray:Kl}),this._pointerLayer=new _t("pointer",{entities:[this._pointerHeadEntity,this._pointerLabelEntity,this._pointerRayEntity],pickingEnabled:!1,hideInLayerSwitcher:!0})}flyExtent(){let e=this._headPointersLayer.getEntities(),t=180,i=180,s=-180,r=-180,n=-1e6;if(e.length>1){for(let o=0;o<e.length;o++){let a=e[o].getLonLat();a.lon<t&&(t=a.lon),a.lat<i&&(i=a.lat),a.lon>s&&(s=a.lon),a.lat>r&&(r=a.lat),a.height>n&&(n=a.height)}this._planet.camera.flyExtent(new U(new L(t,i),new L(s,r)),n,{amplitude:0})}}get planet(){return this._planet}_createGroundPointer(e,t=10){let i=this.ellipsoid.getSurfaceNormal3v(e),s=e.add(i.scale(t)),r=new G({ray:{startPosition:e,endPosition:s,startColor:"rgba(255,255,255,0.2)",endColor:"rgba(355,355,355,1.0)",thickness:3.2}}),n=new G({cartesian:e,geoObject:th}),o=new G({cartesian:s,geoObject:eh,properties:{}}),a=new G({cartesian:s,label:Yn});a.appendChild(new G({cartesian:s,label:{...Yn,offset:[-47,45,0]}}));const l=this._groundPointersLayer.getEntities().length;return r.properties=n.properties=o.properties={index:l,altitude:t,lonLatEll:new L,headEntity:o,groundEntity:n,columnEntity:r,heightLabelEntity:a},{headEntity:o,groundEntity:n,columnEntity:r,heightLabelEntity:a}}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,s=t.length;i<s;i++){let s=e[i];t[i]=s.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,(s=>{if(this._planet){let i=this.getHeightMSL(e);t(s+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,s=e.length-1;t<s;t++){let s=i.lonLatToCartesian(e[t]),r=i.lonLatToCartesian(e[t+1]);if(s.distance(r)>1e5)throw new Error("Track is too long! 100 km is maximum.")}let s=new Array(e.length);for(let t=0,i=e.length;t<i;t++)s[t]=this.addPointLonLatAsync(e[t],!0);return Promise.all(s).then((()=>{t||this.events.dispatch(this.events.change,this)})),s}addPointLonLatAsync(e,t=!1){let i=this._planet.ellipsoid.lonLatToCartesian(e),s=this._planet.ellipsoid.getSurfaceNormal3v(i),r=new L(e.lon,e.lat),n=this._planet.ellipsoid.lonLatToCartesian(r),{headEntity:o,groundEntity:a,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(n);return this._groundPointersLayer.add(a),this._columnPointersLayer.add(l),this._headPointersLayer.add(o),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(o.getCartesian()),a.properties.lonLatEll.lon=r.lon,a.properties.lonLatEll.lat=r.lat,a.properties.lonLatEll.height=r.height,new Promise((r=>{this.getHeightELLAsync(e).then((n=>{var l;a.properties.lonLatEll.height=n;let c,d=10;0===e.height?(c=i.add(s.scaleTo(n)),i=c.add(s.scaleTo(d))):(d=e.height-n,c=i.sub(s.scaleTo(d))),a.setCartesian3v(c),h.setCartesian3v(i),h.label.setText(`${n.toFixed(1)} m`),h.childEntities[0].label.setText(`${d.toFixed(1)} m`),o.properties.altitude=d,o.setCartesian3v(i),o.properties.columnEntity.ray.setStartPosition3v(c),o.properties.columnEntity.ray.setEndPosition3v(i),null==(l=this._trackEntity.polyline)||l.setPoint3v(i,o.properties.index),t||(this.events.dispatch(this.events.addpoint,o,this),this.events.dispatch(this.events.change,this)),r(o)}))}))}addGroundPointLonLatAsync(e,t=10,i=!1){let s=this._planet.ellipsoid.lonLatToCartesian(e);return this._addPoint(s,e,t,i)}addGroundPoint3vAsync(e,t=10,i=!1){let s=this._planet.ellipsoid.cartesianToLonLat(e);return this._addPoint(e,s,t,i)}_addPoint(e,t,i,s=!1){return new Promise(((r,n)=>{let{headEntity:o,groundEntity:a,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(e,i);this._groundPointersLayer.add(a),this._columnPointersLayer.add(l),this._headPointersLayer.add(o),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(o.getCartesian()),a.properties.lonLatEll.lon=t.lon,a.properties.lonLatEll.lat=t.lat,a.properties.lonLatEll.height=t.height,this.getHeightELLAsync(t).then((e=>{var n;a.properties.lonLatEll.height=t.height=e;let l=this._planet.ellipsoid.lonLatToCartesian(t),c=this._planet.ellipsoid.getSurfaceNormal3v(l),d=l.add(c.scale(i));h.setCartesian3v(d),h.label.setText(`${e.toFixed(1)} m`),h.childEntities[0].label.setText(`${i.toFixed(1)} m`),o.setCartesian3v(d),o.properties.columnEntity.ray.setEndPosition3v(d),null==(n=this._trackEntity.polyline)||n.setPoint3v(d,o.properties.index),s||(this.events.dispatch(this.events.addpoint,o,this),this.events.dispatch(this.events.change,this)),r(o)}))}))}setHeadPointCartesian3v(e,t){const i=this._headPointersLayer.getEntities()[e];if(i){let s=this._planet.ellipsoid.lonLatToCartesian(i.properties.lonLatEll),r=t.length()-s.length();r<=0&&(t=s,r=0),i.properties.altitude=r,i.setCartesian3v(t),i.properties.columnEntity.ray.setEndPosition3v(t),i.properties.heightLabelEntity.setCartesian3v(t),i.properties.heightLabelEntity.childEntities[0].label.setText(`${r.toFixed(1)} m`),this._trackEntity.polyline.setPoint3v(t,e),this.events.dispatch(this.events.change,this._pickedHeadEntity)}}setGroundPointCartesian3v(e,t){var i;let s=this._groundPointersLayer.getEntities()[e];if(s){let e=this._planet.ellipsoid.cartesianToLonLat(t);s.properties.lonLatEll.lon=e.lon,s.properties.lonLatEll.lat=e.lat,s.properties.lonLatEll.height=e.height;let r=this._planet.ellipsoid.getSurfaceNormal3v(t),n=s.properties.headEntity,o=s.properties.heightLabelEntity,a=s.properties.altitude;s.setCartesian3v(t);let l=t.add(r.scale(a));n.setCartesian3v(l),n.properties.columnEntity.ray.setStartPosition3v(t),n.properties.columnEntity.ray.setEndPosition3v(l),null==(i=this._trackEntity.polyline)||i.setPoint3v(l,n.properties.index),o.setCartesian3v(l),o.label.setText(`${e.height.toFixed(1)} m`),o.childEntities[0].label.setText(`${a.toFixed(1)} m`),this.events.dispatch(this.events.change,s.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 v;const t=this._planet.quadTreeStrategy._renderedNodes,i=this._groundPointersLayer.getEntities();for(let s=0;s<i.length;s++){let r=i[s];for(let i=0;i<t.length;i++){let s=t[i];if(s.segment.isEntityInside(r)){s.segment.getEntityTerrainPoint(r,e),r.setCartesian3v(e),r.properties.columnEntity.ray.setStartPosition3v(e);break}}}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const sh=["change","addpoint"],rh=["reset","list","location"];class nh extends ut{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-buttons"></div>'}),this.events=this.events.registerNames(rh),this.pointListBtn=new dt({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 ce({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 ce({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 oh extends Kt{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 s=e[i];t[i]=new L(s[0],s[1],s[2])}this.model.addPointLonLatArrayAsync(t)}catch(e){console.error(e)}},this.$textarea=null}render(e){super.render(e);let t=new ut({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 ce({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 ah extends ut{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=Ge(e);this.$trackValue.innerText=t[0],this.$trackUnits.innerText=t[1]}setGroundLength(e){let t=Ge(e);this.$groundValue.innerText=t[0],this.$groundUnits.innerText=t[1]}setWarningLength(e){let t=Ge(e);this.$warningValue.innerText=t[0],this.$warningUnits.innerText=t[1]}setCollisionLength(e){let t=Ge(e);this.$collisionValue.innerText=t[0],this.$collisionUnits.innerText=t[1]}}const Xe="rgb(253,77,77)",nn="rgb(248,115,115)",as="rgb(73,73,239)",on="rgb(90,90,253)",ls="rgb(26,122,26)",an="rgb(55,191,55)",Wn="rgba(255,255,255,0.8)",Wi=.1,ya=new v(Wi,Wi,Wi),xa=.17,$n=.0095,lh=$.createCylinder($n,$n,.83).scale(ya),hh=$.createCylinder(0,.04,xa,16,16,!1,!0,0,-.17).scale(ya);class Ks extends G{constructor(e={}){super({independentPicking:!0,yaw:e.yaw||0,pitch:e.pitch||0,roll:e.roll||0,forceGlobalPosition:!0,geoObject:{color:e.color||Xe,scale:1,tag:"line",object3d:lh},properties:e.properties}),this._size=null!=e.size?e.size:1,this.appendChild(new G({yaw:e.yaw||0,pitch:e.pitch||0,roll:e.roll||0,forceGlobalPosition:!0,geoObject:{color:e.color||Xe,scale:1,tag:"tip",object3d:hh},properties:e.properties}))}setSize(e){this._size=e;const t=new v(1,(this._size-xa)/.83,1),i=new v(0,this._size*Wi,0);let s=this.childEntities[0];this.setScale3v(t),s.geoObject.setTranslate3v(i)}setColorHTML(e){let t=this.childEntities[0];this.geoObject.setColorHTML(e),t.geoObject.setColorHTML(e)}}class ch extends G{constructor(e={}){super(e),this._size=null!=e.size?e.size:1,this.childEntities=[],this._init()}_init(){let e=new Ks({color:Xe,yaw:0,pitch:0,roll:90*j,properties:{opName:"move_x",noEdit:!0,style:{color:Xe,selectColor:nn}}}),t=new Ks({color:as,yaw:0,pitch:0,roll:0,properties:{opName:"move_y",noEdit:!0,style:{color:as,selectColor:on}}}),i=new Ks({color:ls,yaw:0,pitch:90*j,roll:0,properties:{opName:"move_z",noEdit:!0,style:{color:ls,selectColor:an}}});this.appendChild(e),this.appendChild(t),this.appendChild(i),this.setSize(this._size)}setSize(e){this.childEntities[0].setSize(e),this.childEntities[1].setSize(e),this.childEntities[2].setSize(e)}setPitch(e){let t=this.childEntities[0],i=t.childEntities[0];t.setPitch(e),i.setPitch(e),t=this.childEntities[1],i=t.childEntities[0],t.setPitch(e),i.setPitch(e),t=this.childEntities[2],i=t.childEntities[0],t.setPitch(e+90),i.setPitch(e+90)}setYaw(e){let t=this.childEntities[0],i=t.childEntities[0];t.setYaw(e),i.setYaw(e),t=this.childEntities[1],i=t.childEntities[0],t.setYaw(e),i.setYaw(e),t=this.childEntities[2],i=t.childEntities[0],t.setYaw(e),i.setYaw(e)}setRoll(e){let t=this.childEntities[0],i=t.childEntities[0];t.setRoll(e+90),i.setRoll(e+90),t=this.childEntities[1],i=t.childEntities[0],t.setRoll(e),i.setRoll(e)}getY(){return this.childEntities[1].getAbsoluteRotation().mulVec3(v.UP).normalize()}}const dh=$.createPlane(1,1,-.5,0,.5);class uh extends G{constructor(e={}){super(e),this._init()}_init(){let e=new G({independentPicking:!0,scale:.025,forceGlobalPosition:!0,geoObject:{color:Wn,tag:"plane",object3d:dh},properties:{opName:"move_xz",noEdit:!0,style:{color:Wn,selectColor:"rgba(255,255,255,1.0)"}}});this.appendChild(e)}}const Li=360,Qs=.95,Xn=new Array(Li),Zn=new Array(Li),Kn=new Array(Li);class _h extends G{constructor(e={}){super(e),this._init()}_init(){const e=Li;let t=new G({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new v))],thickness:3.1,color:Xe,isClosed:!0},properties:{opName:"rotate_pitch",noEdit:!0,style:{color:Xe,selectColor:nn}}}),i=new G({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new v))],thickness:2.5,color:as,isClosed:!0},properties:{opName:"rotate_yaw",noEdit:!0,style:{color:as,selectColor:on}}}),s=new G({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new v))],thickness:2.5,color:ls,isClosed:!0},properties:{opName:"rotate_roll",noEdit:!0,style:{color:ls,selectColor:an}}});this.appendChild(t),this.appendChild(i),this.appendChild(s)}setCartesian3v(e,t=0){if(super.setCartesian3v(e),this._entityCollection&&this._entityCollection.renderNode){let i=this._entityCollection.renderNode,s=i.renderer.activeCamera,r=i.getFrameRotation(e).conjugate(),n=.15*s.eye.distance(e),o=F.xRotation(0),a=F.yRotation(t),l=F.zRotation(0).mul(o).mul(a).mul(i.getFrameRotation(e)).conjugate();for(let t=0,i=0,s=1;t<Li;t+=s,i++){let s=t*j,o=Math.cos(s),a=Math.sin(s),h=l.mulVec3(new v(0,a,o)).normalize().scale(n).add(e),c=r.mulVec3(new v(o,0,a)).normalize().scale(n).add(e),d=l.mulVec3(new v(o,a,0)).normalize().scale(n).add(e);Xn[i]=h,Zn[i]=c,Kn[i]=d}this.childEntities[0].polyline.setPath3v([Xn],void 0,!0),this.childEntities[1].polyline.setPath3v([Zn],void 0,!0),this.childEntities[2].polyline.setPath3v([Kn],void 0,!0);let h=l.mulVec3(new v(1,0,0)).normalize(),c=r.mulVec3(new v(0,1,0)).normalize(),d=l.mulVec3(new v(0,0,1)).normalize();this.childEntities[0].polyline.setVisibleSphere(e,Math.abs(h.dot(s.getForward()))>Qs?0:n),this.childEntities[1].polyline.setVisibleSphere(e,Math.abs(c.dot(s.getForward()))>Qs?0:n),this.childEntities[2].polyline.setVisibleSphere(e,Math.abs(d.dot(s.getForward()))>Qs?0:n)}}}class fh extends G{constructor(e={}){super({...e,forceGlobalPosition:!0}),this._init()}_init(){let e=[],t=[],i=[],s=ve(nn),r=ve(on),n=ve(an);for(let o=0;o<20;o++){let a=1;if(o<5){let e=o/5;a=.5*(1-Math.cos(Math.PI*e))}else if(o>15){let e=(o-15)/5;a=1-.5*(1-Math.cos(Math.PI*e))}t.push([n[0],n[1],n[2],a]),e.push([s[0],s[1],s[2],a]),i.push([r[0],r[1],r[2],a])}let o=new G({polyline:{path3v:[Array.from({length:20},((e,t)=>new v))],thickness:2.5,pathColors:[e],isClosed:!1}}),a=new G({polyline:{path3v:[Array.from({length:20},((e,t)=>new v))],thickness:2.5,pathColors:[i],isClosed:!1}}),l=new G({polyline:{path3v:[Array.from({length:20},((e,t)=>new v))],thickness:2.5,pathColors:[t],isClosed:!1}});this.appendChild(o),this.appendChild(a),this.appendChild(l)}setCartesian3v(e){if(super.setCartesian3v(e),this._entityCollection&&this._entityCollection.renderNode){let t=this._entityCollection.renderNode,i=.05*t.renderer.activeCamera.eye.distance(e);if(t.planet){let s=[],r=[],n=[],o=t.planet.ellipsoid.getSurfaceNormal3v(e),a=this._lonLat,l=10;for(let t=-10;t<l;t++)n.push(new L(a.lon,a.lat+t,a.height)),r.push(new L(a.lon+t,a.lat,a.height)),s.push(e.add(o.scaleTo(t*i)));this.childEntities[0].polyline.setPathLonLatFast([r]),this.childEntities[1].polyline.setPath3vFast([s]),this.childEntities[2].polyline.setPathLonLatFast([n])}else{let t=[],s=[],r=[],n=v.UNIT_Y,o=v.UNIT_X,a=v.UNIT_Z,l=10;for(let h=-10;h<l;h++)s.push(e.add(o.scaleTo(h*i))),r.push(e.add(n.scaleTo(h*i))),t.push(e.add(a.scaleTo(h*i)));this.childEntities[0].polyline.setPath3vFast([s]),this.childEntities[1].polyline.setPath3vFast([r]),this.childEntities[2].polyline.setPath3vFast([t])}}}}function Qn(e,t,i,s,r,n){let o=r.add(v.UP),a=r.add(e),l=new v;if(new V(t,i).hitPlaneRes(vt.fromPoints(r,o,a),l)===V.INSIDE){let i=v.proj_b_to_a(l,e);if(new V(t,s).hitPlaneRes(vt.fromPoints(r,o,a),l)===V.INSIDE){let t=v.proj_b_to_a(l,e).sub(i);n.copy(r.add(t))}}}class gh extends de{constructor(e={}){super(e.name||"GeoObjectEditorScene"),this._onAxisLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onAxisLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.setColorHTML(e.pickingObject.properties.style.color)},this._onAxisLayerLUp=e=>{this._selectedMove=null,this._navActivate(),this._setAxisTrackVisibility(!1)},this._onAxisLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._setAxisTrackVisibility(!0)),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onPlaneLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.geoObject.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onPlaneLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.geoObject.setColorHTML(e.pickingObject.properties.style.color)},this._onPlaneLayerLUp=e=>{this._selectedMove=null,this._navActivate(),this._setAxisTrackVisibility(!1)},this._onPlaneLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._setAxisTrackVisibility(!0)),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onRotateLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.polyline.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onRotateLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.polyline.setColorHTML(e.pickingObject.properties.style.color)},this._onRotateLayerLUp=e=>{this._selectedMove=null,this._navActivate()},this._onRotateLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._selectedEntity&&(this._selectedEntityPitch=this._selectedEntity.getAbsolutePitch(),this._selectedEntityYaw=this._selectedEntity.getAbsoluteYaw(),this._selectedEntityRoll=this._selectedEntity.getAbsoluteRoll())),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onMouseMove=e=>{this._selectedEntity&&this._selectedMove&&this._ops[this._selectedMove]&&this._ops[this._selectedMove](e)},this._onLclick=e=>{e.pickingObject&&e.pickingObject instanceof G&&this.select(e.pickingObject)},this._moveX=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),r=new v;if(this.planet){let n=new V(t.eye,s).hitSphere(new Ft(i.length(),new v)),o=new V(t.eye,e.direction).hitSphere(new Ft(i.length(),new v));if(!o)return;if(r=F.getRotationBetweenVectors(n.normal(),o.normal()).mulVec3(i),this.ellipsoid){let e=this.ellipsoid.cartesianToLonLat(i),t=this.ellipsoid.cartesianToLonLat(r);this.ellipsoid.lonLatToCartesianRes(new L(t.lon,e.lat,e.height),r)}}else Qn(v.UNIT_X,t.eye,s,e.direction,i,r);this._selectedEntity.setAbsoluteCartesian3v(r),this.events.dispatch(this.events.position,r,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveY=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=v.UP;this.planet&&(s=this._axisEntity.getY());let r=i.add(s),n=i.add(t.getRight()),o=new v,a=t.unproject(this._clickPos.x,this._clickPos.y);if(new V(t.eye,a).hitPlaneRes(vt.fromPoints(i,r,n),o)===V.INSIDE){let a=v.proj_b_to_a(o,s);if(new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,r,n),o)===V.INSIDE){let e=v.proj_b_to_a(o,s).sub(a),t=this._selectedEntityCart.add(e);this._selectedEntity.setAbsoluteCartesian3v(t),this.events.dispatch(this.events.position,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}}},this._moveZ=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),r=new v;if(this.planet){let n=new V(t.eye,s).hitSphere(new Ft(i.length(),new v)),o=new V(t.eye,e.direction).hitSphere(new Ft(i.length(),new v));if(!o)return;if(r=F.getRotationBetweenVectors(n.normal(),o.normal()).mulVec3(i),this.ellipsoid){let e=this.ellipsoid.cartesianToLonLat(i),t=this.ellipsoid.cartesianToLonLat(r);this.ellipsoid.lonLatToCartesianRes(new L(e.lon,t.lat,e.height),r)}}else Qn(v.UNIT_Z,t.eye,s,e.direction,i,r);this._selectedEntity.setAbsoluteCartesian3v(r),this.events.dispatch(this.events.position,r,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveXZ=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),r=new v;if(this.planet){let n=new V(t.eye,s).hitSphere(new Ft(i.length(),new v)),o=new V(t.eye,e.direction).hitSphere(new Ft(i.length(),new v));if(!o)return;if(r=F.getRotationBetweenVectors(n.normal(),o.normal()).mulVec3(i),this.ellipsoid){let e=this.ellipsoid.cartesianToLonLat(r),t=this._selectedEntity.getLonLat().height;this.ellipsoid.lonLatToCartesianRes(new L(e.lon,e.lat,t),r)}}else{let n=i.add(v.UNIT_X),o=i.add(v.UNIT_Z),a=new v,l=new v;if(new V(t.eye,s).hitPlaneRes(vt.fromPoints(i,n,o),a)===V.INSIDE&&new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,n,o),l)===V.INSIDE){let e=l.sub(a);r=i.add(e)}}this._selectedEntity.setAbsoluteCartesian3v(r),this.events.dispatch(this.events.position,r,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveXY=e=>{console.log("moveXY")},this._moveZY=e=>{console.log("moveZY")},this._rotatePitch=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=F.xRotation(0),r=F.yRotation(this._selectedEntity.getYaw()),n=F.zRotation(0).mul(s).mul(r).mul(this.getFrameRotation(i)).conjugate().mulVec3(new v(1,0,0)).normalize(),o=t.unproject(this._clickPos.x,this._clickPos.y),a=new vt(i,n),l=new v,h=new v;if(new V(t.eye,o).hitPlaneRes(a,l)===V.INSIDE&&new V(t.eye,e.direction).hitPlaneRes(a,h)===V.INSIDE){let e=l.sub(i).normalize(),t=h.sub(i).normalize(),s=Math.sign(e.cross(t).dot(n)),r=Math.acos(e.dot(t)),o=this._selectedEntityPitch+s*r;this._selectedEntity.setAbsolutePitch(o),this.events.dispatch(this.events.pitch,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._rotateYaw=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=this.getFrameRotation(i).conjugate().mulVec3(new v(0,1,0)).normalize(),r=t.unproject(this._clickPos.x,this._clickPos.y),n=new vt(i,s),o=new v,a=new v;if(new V(t.eye,r).hitPlaneRes(n,o)===V.INSIDE&&new V(t.eye,e.direction).hitPlaneRes(n,a)===V.INSIDE){let e=o.sub(i).normalize(),t=a.sub(i).normalize(),r=Math.sign(t.cross(e).dot(s)),n=Math.acos(e.dot(t)),l=this._selectedEntityYaw+r*n;this._selectedEntity.setAbsoluteYaw(l),this.events.dispatch(this.events.yaw,l,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._rotateRoll=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart;this.getFrameRotation(i).conjugate();let s=F.xRotation(0),r=F.yRotation(this._selectedEntity.getYaw()),n=F.zRotation(0).mul(s).mul(r).mul(this.getFrameRotation(i)).conjugate().mulVec3(new v(0,0,1)).normalize(),o=t.unproject(this._clickPos.x,this._clickPos.y),a=new vt(i,n),l=new v,h=new v;if(new V(t.eye,o).hitPlaneRes(a,l)===V.INSIDE&&new V(t.eye,e.direction).hitPlaneRes(a,h)===V.INSIDE){let e=l.sub(i).normalize(),t=h.sub(i).normalize(),s=Math.sign(e.cross(t).dot(n)),r=Math.acos(e.dot(t)),o=this._selectedEntityRoll+s*r;this._selectedEntity.setAbsoluteRoll(o),this.events.dispatch(this.events.roll,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._scale=e=>{this.events.dispatch(this.events.scale,1,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._scaleX=e=>{},this._scaleY=e=>{},this._scaleZ=e=>{},this.events=lt(ph),this._planet=e.planet||null,this._startPos=null,this._startClick=new H,this._axisEntity=new ch,this._planeEntity=new uh,this._rotateEntity=new _h,this._axisTrackEntity=new fh,this._moveLayer=new se({scaleByDistance:[.1,Ae,.1],useLighting:!1,pickingScale:[5,1.1,5],visibility:!1,depthOrder:1e3}),this._planeLayer=new se({scaleByDistance:[.1,Ae,.1],useLighting:!1,visibility:!1,depthOrder:1e3}),this._rotateLayer=new se({useLighting:!1,visibility:!1,depthOrder:1e3,pickingScale:5}),this._selectedEntity=null,this._clickPos=new H,this._selectedEntityCart=new v,this._selectedEntityPitch=0,this._selectedEntityYaw=0,this._selectedEntityRoll=0,this._selectedMove=null,this._axisTrackVisibility=!1,this._axisTrackLayer=new se({useLighting:!1,visibility:!1,pickingScale:5,pickingEnabled:!1,opacity:.6}),this._ops={move_x:this._moveX,move_y:this._moveY,move_z:this._moveZ,move_xz:this._moveXZ,move_xy:this._moveXY,move_zy:this._moveZY,rotate_pitch:this._rotatePitch,rotate_yaw:this._rotateYaw,rotate_roll:this._rotateRoll,scale:this._scale,scale_x:this._scaleX,scale_y:this._scaleY,scale_z:this._scaleZ}}get ellipsoid(){if(this._planet)return this._planet.ellipsoid}get planet(){return this._planet}bindPlanet(e){this._planet=e}init(){this.activate()}onremove(){this.deactivate()}_addAxisLayers(){this._moveLayer.addTo(this),this._planeLayer.addTo(this),this._rotateLayer.addTo(this),this._axisTrackLayer.addTo(this),this._moveLayer.add(this._axisEntity),this._moveLayer.events.on("mouseenter",this._onAxisLayerMouseEnter),this._moveLayer.events.on("mouseleave",this._onAxisLayerMouseLeave),this._moveLayer.events.on("lup",this._onAxisLayerLUp),this._moveLayer.events.on("ldown",this._onAxisLayerLDown),this._planeLayer.add(this._planeEntity),this._planeLayer.events.on("mouseenter",this._onPlaneLayerMouseEnter),this._planeLayer.events.on("mouseleave",this._onPlaneLayerMouseLeave),this._planeLayer.events.on("lup",this._onPlaneLayerLUp),this._planeLayer.events.on("ldown",this._onPlaneLayerLDown),this._rotateLayer.add(this._rotateEntity),this._rotateLayer.events.on("mouseenter",this._onRotateLayerMouseEnter),this._rotateLayer.events.on("mouseleave",this._onRotateLayerMouseLeave),this._rotateLayer.events.on("lup",this._onRotateLayerLUp),this._rotateLayer.events.on("ldown",this._onRotateLayerLDown),this._axisTrackLayer.add(this._axisTrackEntity)}_navActivate(){this.renderer&&(this.renderer.controls.navigation&&this.renderer.controls.navigation.activate(),this.renderer.controls.SimpleNavigation&&this.renderer.controls.SimpleNavigation.activate())}_navDeactivate(){this.renderer&&(this.renderer.controls.navigation&&this.renderer.controls.navigation.deactivate(),this.renderer.controls.SimpleNavigation&&this.renderer.controls.SimpleNavigation.deactivate())}_removeAxisLayers(){this._moveLayer.remove(),this._planeLayer.remove(),this._rotateLayer.remove()}activate(){this.renderer.events.on("lclick",this._onLclick),this.renderer.events.on("mousemove",this._onMouseMove),this._addAxisLayers()}deactivate(){this.renderer.events.off("lclick",this._onLclick),this.renderer.events.off("mousemove",this._onMouseMove),this._removeAxisLayers(),this.clear()}_setAxisTrackVisibility(e){e!==this._axisTrackVisibility&&(this._axisTrackVisibility=e,this._axisTrackLayer.setVisibility(e))}setVisibility(e){this._moveLayer.setVisibility(e),this._planeLayer.setVisibility(e),this._rotateLayer.setVisibility(e),this.unlockView()}readyToEdit(e){return!e.properties||!e.properties.noEdit}select(e){(!this._selectedEntity||this._selectedEntity&&!e.isEqual(this._selectedEntity))&&this.readyToEdit(e)&&(this._selectedEntity&&this.unselect(),this._selectedEntity=e,this.renderer&&this.renderer.setRelativeCenter(),this.setVisibility(!0),this.events.dispatch(this.events.select,this._selectedEntity))}unselect(){this.setVisibility(!1);let e=this._selectedEntity;this._selectedEntity=null,this.events.dispatch(this.events.unselect,e)}clear(){this.removeEntityCollection(this._moveLayer),this.removeEntityCollection(this._planeLayer),this.removeEntityCollection(this._rotateLayer)}frame(){if(this._selectedEntity){let e=this._selectedEntity.getAbsoluteCartesian();this._axisEntity.setCartesian3v(e),this._planeEntity.setCartesian3v(e),this._rotateEntity.setCartesian3v(e,this._selectedEntity.getAbsoluteYaw()),this._axisTrackEntity.setCartesian3v(e)}}getFrameRotation(e){return this._planet?this._planet.getFrameRotation(e):super.getFrameRotation(e)}getSelectedEntity(){return this._selectedEntity}lockView(){this.renderer&&this._selectedEntity&&this.renderer.controls.CameraLock.lockView(this._selectedEntity)}unlockView(){if(this.renderer&&this._selectedEntity){let e=this.renderer.controls.CameraLock;e&&e.unlockView()}}}const ph=["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","select","unselect","change","position","pitch","yaw","roll","scale"],mh=["change"];class yt extends ut{constructor(e={}){super({template:Dt('<div class="og-input">\n <div class="og-input-label">{label}</div>\n <input type="{type}"/>\n </div>',{label:e.label||"",type:e.type||"text"})}),this._onResize=()=>{},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation()},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onInput=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this._setValue(e.target.value)},this.events=this.events.registerNames(mh),this._value=e.value||"",this._maxFixed=null!=e.maxFixed?e.maxFixed:-1,this.$label=null,this.$input=null}render(e){return super.render(e),this.$label=this.select(".og-input-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="number"==typeof e?_r(e,this._maxFixed):e,this.$input&&(this.$input.value=this._value),this.events.dispatch(this.events.change,this._value,this))}_setValue(e){e!==this._value&&(this._value="number"==typeof e?_r(e,this._maxFixed):e,this.events.dispatch(this.events.change,this._value,this))}get value(){return this._value}_initEvents(){this.el.addEventListener("mousewheel",this._onMouseWheel),this.el.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.el.removeEventListener("mousewheel",this._onMouseWheel),this.el.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("input",this._onInput)}remove(){this._clearEvents(),super.remove()}set visibility(e){this.el&&(this.el.style.display=e?"":"none")}}const vh=["change"];class yh extends ut{constructor(e={}){super({template:Dt('<div class="og-checkbox">\n <div class="og-input-label">{label}</div>\n <div class="og-checkbox-input">\n <input type="checkbox" {checked}/>\n </div>\n </div>',{label:e.label||"",checked:e.checked?"checked":""})}),this._onResize=()=>{},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation()},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onClick=e=>{(e=e||window.event).stopPropagation(),this.checked=!this._checked},this._checked=e.checked||!1,this._disabled=e.disabled||!1,this.events=this.events.registerNames(vh),this.$label=null,this.$input=null}set disabled(e){this._disabled=e,this._updateDisabled()}_updateDisabled(){this.el&&(this._disabled?this.el.classList.add("og-input-disabled"):this.el.classList.remove("og-input-disabled"))}get disabled(){return this._disabled}render(e){return super.render(e),this.$label=this.select(".og-input-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this.$input.checked=this._checked,this._updateDisabled(),this._initEvents(),this}set checked(e){e!==this._checked&&(this._checked=e,this.$input&&(this.$input.checked=this._checked),this.events.dispatch(this.events.change,this._checked,this))}get checked(){return this._checked}_initEvents(){this.el.addEventListener("mousewheel",this._onMouseWheel),this.el.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("click",this._onClick)}_clearEvents(){this.el.removeEventListener("mousewheel",this._onMouseWheel),this.el.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("click",this._onClick)}remove(){this._clearEvents(),super.remove()}set visibility(e){this.el&&(this.el.style.display=e?"":"none")}}class xh extends Kt{constructor(e){super({title:"GeoObject Properties",visible:!1,resizable:!0,useHide:!0,top:25,right:85,width:252,height:480,minHeight:100,minWidth:100,model:e.model}),this._onVisibility=e=>{this.model.setVisibility(e)},this._onSelect=e=>{this.show(),this._refresh(e)},this._onUnselect=e=>{this.hide()},this._onChangeRelativePosition=e=>{let t=this.model.getSelectedEntity();t&&(t.relativePosition=e,this._refresh(t))},this._onPosition=(e,t)=>{this._refresh(t)},this._onPitch=(e,t)=>{this._pitchView.stopPropagation(),this._pitchView.value=t.getPitch()*J,this._absolutePitchView.stopPropagation(),this._absolutePitchView.value=t.getAbsolutePitch()*J},this._onYaw=(e,t)=>{this._yawView.stopPropagation(),this._yawView.value=t.getYaw()*J,this._absoluteYawView.stopPropagation(),this._absoluteYawView.value=t.getAbsoluteYaw()*J},this._onRoll=(e,t)=>{this._rollView.stopPropagation(),this._rollView.value=t.getRoll()*J,this._absoluteRollView.stopPropagation(),this._absoluteRollView.value=t.getAbsoluteRoll()*J},this._onChangeLon=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(parseFloat(e),i.lat,i.height),this._refresh(t)}},this._onChangeLat=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(i.lon,parseFloat(e),i.height),this._refresh(t)}},this._onChangeHeight=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(i.lon,i.lat,parseFloat(e)),this._refresh(t)}},this._onChangeX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(parseFloat(e),i.y,i.z),this._refresh(t)}},this._onChangeY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(i.x,parseFloat(e),i.z),this._refresh(t)}},this._onChangeZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(i.x,i.y,parseFloat(e)),this._refresh(t)}},this._onChangeAbsoluteX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(parseFloat(e),i.y,i.z),this._refresh(t)}},this._onChangeAbsoluteY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(i.x,parseFloat(e),i.z),this._refresh(t)}},this._onChangeAbsoluteZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(i.x,i.y,parseFloat(e)),this._refresh(t)}},this._onChangePitch=e=>{let t=this.model.getSelectedEntity();t&&(t.setPitch(parseFloat(e)*j),this._refresh(t))},this._onChangeYaw=e=>{let t=this.model.getSelectedEntity();t&&(t.setYaw(parseFloat(e)*j),this._refresh(t))},this._onChangeRoll=e=>{let t=this.model.getSelectedEntity();t&&(t.setRoll(parseFloat(e)*j),this._refresh(t))},this._onChangeAbsolutePitch=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsolutePitch(parseFloat(e)*j),this._refresh(t))},this._onChangeAbsoluteYaw=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsoluteYaw(parseFloat(e)*j),this._refresh(t))},this._onChangeAbsoluteRoll=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsoluteRoll(parseFloat(e)*j),this._refresh(t))},this._onChangeScale=e=>{let t=this.model.getSelectedEntity();if(t){let i=parseFloat(e);t.setScale(i),this._scaleXView.stopPropagation(),this._scaleYView.stopPropagation(),this._scaleZView.stopPropagation(),this._scaleXView.value=i,this._scaleYView.value=i,this._scaleZView.value=i}},this._onChangeScaleX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new v(parseFloat(e),i.y,i.z))}},this._onChangeScaleY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new v(i.x,parseFloat(e),i.z))}},this._onChangeScaleZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new v(i.x,i.y,parseFloat(e)))}},this._onGround=()=>{let e=this.model.getSelectedEntity();e&&this.model.planet&&(this.model.planet.terrain?this.model.planet.terrain.getHeightAsync(e.getLonLat(),(e=>{this._heightView.value=e})):this._heightView.value=0)},this._relativePositionView=new yh({label:"Relative position"}),this._lonView=new yt({label:"Lon",type:"number",min:-180,max:180,maxFixed:10}),this._latView=new yt({label:"Lat",type:"number",min:-90,max:90,maxFixed:10}),this._heightView=new yt({label:"Height",type:"number",maxFixed:4}),this._xView=new yt({label:"X",type:"number",maxFixed:10}),this._yView=new yt({label:"Y",type:"number"}),this._zView=new yt({label:"Z",type:"number"}),this._absXView=new yt({label:"Absolute X",type:"number",maxFixed:10}),this._absYView=new yt({label:"Absolute Y",type:"number"}),this._absZView=new yt({label:"Absolute Z",type:"number"}),this._pitchView=new yt({label:"Pitch",type:"number",maxFixed:2}),this._yawView=new yt({label:"Yaw",type:"number",maxFixed:2}),this._rollView=new yt({label:"Roll",type:"number",maxFixed:2}),this._absolutePitchView=new yt({label:"Absolute pitch",type:"number",maxFixed:2}),this._absoluteYawView=new yt({label:"Absolute yaw",type:"number",maxFixed:2}),this._absoluteRollView=new yt({label:"Absolute roll",type:"number",maxFixed:2}),this._scaleView=new yt({label:"Scale",type:"number",maxFixed:2}),this._scaleXView=new yt({label:"Scale X",type:"number",maxFixed:2}),this._scaleYView=new yt({label:"Scale Y",type:"number",maxFixed:2}),this._scaleZView=new yt({label:"Scale Z",type:"number",maxFixed:2}),this._groundBtn=new ce({text:"Ground",title:"Put on the ground",name:"ground",classList:["og-editor-ground_button"]})}render(e){var t;super.render(e),this._initSceneEvents();let i=document.createElement("div");i.classList.add("og-editor_toolbar"),null==(t=this.container)||t.appendChild(i);let s=new dt({classList:["og-editor_toolbar-button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" id="filter-center-focus">\n <path d="M5 15H3v4c0 1.1.9 2 2 2h4v-2H5v-4zM5 5h4V3H5c-1.1 0-2 .9-2 2v4h2V5zm14-2h-4v2h4v4h2V5c0-1.1-.9-2-2-2zm0 16h-4v2h4c1.1 0 2-.9 2-2v-4h-2v4zM12 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>\n</svg>',title:"Lock/Unlock camera view"});return s.appendTo(i),s.events.on("change",(e=>{e?this.model.lockView():this.model.unlockView()})),this.events.on("visibility",(e=>{e||(s.events.stopPropagation(),s.setActive(!1))})),this.events.on("visibility",this._onVisibility),this._relativePositionView.appendTo(this.container),this.model.planet&&(this._lonView.appendTo(this.container),this._latView.appendTo(this.container),this._heightView.appendTo(this.container)),this._xView.appendTo(this.container),this._yView.appendTo(this.container),this._zView.appendTo(this.container),this._absXView.appendTo(this.container),this._absYView.appendTo(this.container),this._absZView.appendTo(this.container),this._pitchView.appendTo(this.container),this._yawView.appendTo(this.container),this._rollView.appendTo(this.container),this._absolutePitchView.appendTo(this.container),this._absoluteYawView.appendTo(this.container),this._absoluteRollView.appendTo(this.container),this._scaleView.appendTo(this.container),this._scaleXView.appendTo(this.container),this._scaleYView.appendTo(this.container),this._scaleZView.appendTo(this.container),this.model.planet&&this._groundBtn.appendTo(this.container),this._relativePositionView.events.on("change",this._onChangeRelativePosition),this._lonView.events.on("change",this._onChangeLon),this._latView.events.on("change",this._onChangeLat),this._heightView.events.on("change",this._onChangeHeight),this._xView.events.on("change",this._onChangeX),this._yView.events.on("change",this._onChangeY),this._zView.events.on("change",this._onChangeZ),this._absXView.events.on("change",this._onChangeAbsoluteX),this._absYView.events.on("change",this._onChangeAbsoluteY),this._absZView.events.on("change",this._onChangeAbsoluteZ),this._pitchView.events.on("change",this._onChangePitch),this._yawView.events.on("change",this._onChangeYaw),this._rollView.events.on("change",this._onChangeRoll),this._absolutePitchView.events.on("change",this._onChangeAbsolutePitch),this._absoluteYawView.events.on("change",this._onChangeAbsoluteYaw),this._absoluteRollView.events.on("change",this._onChangeAbsoluteRoll),this._scaleView.events.on("change",this._onChangeScale),this._scaleXView.events.on("change",this._onChangeScaleX),this._scaleYView.events.on("change",this._onChangeScaleY),this._scaleZView.events.on("change",this._onChangeScaleZ),this._groundBtn.appendTo(this.container),this._groundBtn.events.on("click",this._onGround),this}remove(){super.remove(),this._clearSceneEvents()}_initSceneEvents(){this.model.events.on("select",this._onSelect),this.model.events.on("unselect",this._onUnselect),this.model.events.on("position",this._onPosition),this.model.events.on("pitch",this._onPitch),this.model.events.on("yaw",this._onYaw),this.model.events.on("roll",this._onRoll)}_clearSceneEvents(){this.model.events.off("select",this._onSelect),this.model.events.off("unselect",this._onUnselect),this.model.events.off("position",this._onPosition),this.model.events.off("pitch",this._onPitch),this.model.events.off("yaw",this._onYaw),this.model.events.off("roll",this._onRoll)}_refresh(e){e.parent?this._relativePositionView.disabled=!1:this._relativePositionView.disabled=!0,this._relativePositionView.checked=e.relativePosition;let t=e.getLonLat();this._lonView.stopPropagation(),this._latView.stopPropagation(),this._heightView.stopPropagation(),this._lonView.value=t.lon,this._latView.value=t.lat,this._heightView.value=t.height;let i=e.getCartesian();this._xView.stopPropagation(),this._yView.stopPropagation(),this._zView.stopPropagation(),this._xView.value=i.x,this._yView.value=i.y,this._zView.value=i.z,i=e.getAbsoluteCartesian(),this._absXView.stopPropagation(),this._absYView.stopPropagation(),this._absZView.stopPropagation(),this._absXView.value=i.x,this._absYView.value=i.y,this._absZView.value=i.z,this._pitchView.stopPropagation(),this._yawView.stopPropagation(),this._rollView.stopPropagation(),this._pitchView.value=e.getPitch()*J,this._yawView.value=e.getYaw()*J,this._rollView.value=e.getRoll()*J,this._absolutePitchView.stopPropagation(),this._absoluteYawView.stopPropagation(),this._absoluteRollView.stopPropagation(),this._absolutePitchView.value=e.getAbsolutePitch()*J,this._absoluteYawView.value=e.getAbsoluteYaw()*J,this._absoluteRollView.value=e.getAbsoluteRoll()*J,this._scaleView.stopPropagation();let s=e.getScale();s.x===s.y&&s.y===s.z?this._scaleView.value=s.x:this._scaleView.value=1,this._scaleXView.stopPropagation(),this._scaleYView.stopPropagation(),this._scaleZView.stopPropagation(),this._scaleXView.value=s.x,this._scaleYView.value=s.y,this._scaleZView.value=s.z}hide(){super.hide(),this.model.events.stopPropagation(),this.model.unselect()}}const bh=["lockview","unlockview"];class Jn extends Q{constructor(e={}){super(e),this._onLockViewDraw=()=>{this.renderer&&this._lockEntity&&(this._isFromTheBack||this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(),this._lockDistance))},this._onMouseWheel=e=>{if(this.renderer&&this._lockEntity&&!this._isFromTheBack){let t=this.renderer.activeCamera.eye.distance(this._lockEntity.getAbsoluteCartesian());this._lockDistance-=.33*t*Math.sign(e.wheelDelta),this._lockDistance<.001&&(this._lockDistance=.001),this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(),this._lockDistance)}},this._onMouseMove=e=>{if(this._lockEntity&&this.renderer&&(e.rightButtonDown||this.renderer.events.isKeyPressed(W.KEY_ALT))){let t=this._lockEntity.getAbsoluteCartesian(),i=this.renderer.activeCamera,s=.5/j;s>.007&&(s=.007),this.planet?i.rotateHorizontal(s*(e.x-e.prev_x),!1,t,t.isZero()?v.UP:t.normal()):i.rotateHorizontal(s*(e.x-e.prev_x),!1,t,v.UP),i.rotateVertical(s*(e.y-e.prev_y),t),this._viewDir=t.sub(i.eye).normalize()}},this.events=lt(bh),this._name="CameraLock",this.planet=e.planet||null,this._lockDistance=0,this._isFromTheBack=!1,this._lockEntity=null,this._viewDir=new v(0,0,0)}onactivate(){this.renderer}ondeactivate(){this.renderer&&this.unlockView()}oninit(){this.activate(),this.renderer}flyCartesian(e,t=120){if(!e.isZero()&&this.renderer)if(this.unlockView(),this.planet){let i=this.planet.camera;this.isVisibleDistance(e)&&i.flyDistance(e,t),i.eye.distance(e)<1e6?i.flyDistance(e,t):i.viewDistance(e,t)}else this.renderer.activeCamera.viewDistance(e,t)}lockView(e,t=!1){if(!this.renderer)return;this._lockDistance=this._getDistance(e,this._lockEntity),this._isFromTheBack=t,this._deactivateLockViewEvents(),this._lockEntity=e;let i=this.renderer.activeCamera;this.planet&&this.planet.camera.stopFlying(),i.viewDistance(e.getAbsoluteCartesian(),this._lockDistance),this._deactivateNav(),this._activateLockViewEvents(),this._viewDir=e.getAbsoluteCartesian().sub(i.eye).normalize(),this.events.dispatch(this.events.lockview,this._lockEntity,t)}_activateNav(){this.renderer&&this.renderer.controls.navigation&&this.renderer.controls.navigation.activate(),this.renderer&&this.renderer.controls.simpleNavigation&&this.renderer.controls.simpleNavigation.activate()}_deactivateNav(){this.renderer&&this.renderer.controls.navigation&&(this.renderer.controls.navigation.deactivate(),this.renderer.controls.navigation.stop()),this.renderer&&this.renderer.controls.simpleNavigation&&this.renderer.controls.simpleNavigation.deactivate()}unlockView(){this._lockEntity&&(this._deactivateLockViewEvents(),this._activateNav(),this.events.dispatch(this.events.unlockview,this._lockEntity),this._lockEntity=null)}_getCenterDist(){return this.renderer&&this.renderer.getDistanceFromPixel(this.renderer.handler.getCenter())||0}_getDistance(e,t){if(this.renderer){let i=e.getAbsoluteCartesian(),s=this.renderer.activeCamera,r=s.eye.distance(i);return t&&(r=s.eye.distance(t.getAbsoluteCartesian())),this.isVisibleDistance(i)?r:s.eye.distance(i)<1e6?this._getCenterDist():120}return 0}isVisibleDistance(e,t=0){if(this.planet){let i=this.planet.ellipsoid.equatorialSize,s=this.planet.camera.eye;return s.distance(e)<Math.sqrt(s.length2()-i*i)+t}return!0}get lockEntity(){return this._lockEntity}flyLonLat(e,t=120){if(this.planet){let i=this.planet.ellipsoid.lonLatToCartesian(e);this.flyCartesian(i,t)}}_activateLockViewEvents(){this.renderer&&(this.renderer.events.on("mousewheel",this._onMouseWheel),this.renderer.events.on("mousemove",this._onMouseMove),this.renderer.events.on("draw",this._onLockViewDraw))}_deactivateLockViewEvents(){this.renderer&&(this.renderer.events.off("mousewheel",this._onMouseWheel),this.renderer.events.off("mousemove",this._onMouseMove),this._lockEntity&&this.renderer.events.off("draw",this._onLockViewDraw))}}const wh=["click"];class Th extends ut{constructor(e){super({template:Dt('<button class="og-object3d-collection__item">\n <div class="og-object3d-collection__item_name">{name}</div>\n </button>',{name:e.model.name}),...e}),this.events=lt(wh)}render(e){var t;return super.render(e),null==(t=this.el)||t.addEventListener("click",(e=>{this.events.dispatch(this.events.click,this.model,this,e)})),this}}const Ch=["select"];class Eh extends ut{constructor(e){super({template:'<div class="og-object3d-collection"></div>',model:e.model,...e}),this._onAdd=e=>{this._addItem(e)},this.events=lt(Ch),this._activeView=null}_addItem(e){let t=new Th({model:e});t.appendTo(this.el),t.events.on("click",(e=>{var i,s;this._activeView&&(null==(i=this._activeView.el)||i.classList.remove("active")),this._activeView=t,null==(s=this._activeView.el)||s.classList.add("active"),this.events.dispatch(this.events.select,e,t)}))}render(e){super.render(e);let t=this.model.getItems();for(let e of t)this._addItem(e);return this._initEvents(),this}_initEvents(){this.model.events.on("add",this._onAdd)}}const Ah=["select"];class Lh extends Kt{constructor(e){super({classList:["og-object3d-manager"],title:"Object3D Collection",visible:!1,resizable:!0,useHide:!0,top:25,right:85,width:252,height:480,minHeight:100,minWidth:100}),this._onLoadClick=()=>{let e=new ut({initRender:!0,template:'<input type="file" accept=".obj,.mtl" multiple />'});e.el&&(e.el.addEventListener("change",(e=>{const t=e.target;if(t.files){const e=Array.from(t.files),i=e.find((e=>e.name.toLowerCase().endsWith(".obj"))),s=e.find((e=>e.name.toLowerCase().endsWith(".mtl")));i&&async function(e,t){return await $.readFileObj(e,t).then((i=>({name:e.name,objects:t?i:[$.merge(i)]})))}(i,s).then(this._addObject)}})),e.el.click())},this._addObject=e=>{this._object3dCollectionView.model.addItem(e)},this.events=lt(Ah),this._object3dCollectionView=new Eh({model:e.model})}render(e){var t;super.render(e);let i=document.createElement("div");i.classList.add("og-editor_toolbar"),null==(t=this.container)||t.appendChild(i);let s=new ce({classList:["og-editor_toolbar-button"],icon:'<svg class="svg-icon" style="vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M426.666667 170.666667H170.666667c-47.146667 0-84.906667 38.186667-84.906667 85.333333L85.333333 768c0 47.146667 38.186667 85.333333 85.333334 85.333333h682.666666c47.146667 0 85.333333-38.186667 85.333334-85.333333V341.333333c0-47.146667-38.186667-85.333333-85.333334-85.333333H512l-85.333333-85.333333z" /></svg>',title:"Load 3D object"});return s.appendTo(i),s.events.on("click",this._onLoadClick),this._object3dCollectionView.appendTo(this.container),this._object3dCollectionView.events.on("select",(e=>{this.events.dispatch(this.events.select,e)})),this}}const Ph=["add","remove"];class ln{constructor(e={}){this.events=lt(Ph,this),this._items=ln.createItemsMap(e.collection||[])}static createItemsMap(e){let t=new Map;for(let i=0;i<e.length;i++)t.set(e[i].name,e[i]);return t}getItem(e){return this._items.get(e)}addItem(e,t=!1){this._items.has(e.name)&&!t||(this._items.set(e.name,e),this.events.dispatch(this.events.add,e))}getItems(){return Array.from(this._items,(([e,t])=>t))}}class Fr extends Q{constructor(e={}){super({name:"CameraFrameComposer",autoActivate:!0,...e}),this._onPostdraw=()=>{for(let e=0,t=this._frameHandlers.length;e<t;e++)this._frameHandlers[e].frame()},this._cameraLayer=new se({scaleByDistance:[100,1e6,1],pickingEnabled:!1}),this._cameraScene=new de("CameraScene"),this._frameHandlers=e.frameHandlers||[]}get frameHandlers(){return[...this._frameHandlers]}add(e){e.addTo(this),this._cameraLayer.add(e.cameraEntity)}oninit(){super.oninit(),this._cameraLayer.addTo(this._cameraScene)}activate(){super.activate(),this.renderer&&(this.renderer.events.on("postdraw",this._onPostdraw),this.renderer.addNode(this._cameraScene))}deactivate(){super.deactivate(),this.renderer&&(this.renderer.events.off("postdraw",this._onPostdraw),this.renderer.removeNode(this._cameraScene))}}let Sh=$.createFrustum();class to{constructor(e){this.camera=e.camera,this.frameBuffer=e.frameBuffer,this.frameHandler=e.frameHandler||null,this._composer=null,this._composerIndex=-1,this.showFrustum=null==e.showFrustum||e.showFrustum,this.cameraEntity=new G({visibility:!0,scale:this.frustumScale,geoObject:{tag:"frustum",color:"rgba(0,255,0,0.20)",object3d:Sh}}),this.frameBuffer.init()}get frustumScale(){return $.getFrustumScaleByCameraAspectRatio(1e3,this.camera.getViewAngle(),this.camera.getAspectRatio())}addTo(e){this._composer||(this._composer=e,this._composerIndex=e.frameHandlers.length,this._composer._frameHandlers.push(this))}remove(){this._composer&&(this._composer._frameHandlers.splice(this._composerIndex,1),this._composer=null,this._composerIndex=-1)}frame(){if(this.frameHandler&&this.frameBuffer.handler.gl&&(this.frameHandler(this),this.showFrustum)){let e=this.camera,t=$.getFrustumScaleByCameraAngles(100,e.horizontalViewAngle,e.verticalViewAngle);this.cameraEntity.setScale3v(t),this.cameraEntity.setCartesian3v(e.eye),this.cameraEntity.setAbsolutePitch(e.getAbsolutePitch()),this.cameraEntity.setAbsoluteYaw(e.getAbsoluteYaw()),this.cameraEntity.setAbsoluteRoll(e.getAbsoluteRoll())}}}function Oe(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 eo{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 tt,this.inverseProjectionMatrix=new tt,this.projectionViewMatrix=new tt,this.projectionViewRTEMatrix=new tt,this.inverseProjectionViewMatrix=new tt,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}getProjectionViewRTEMatrix(){return this.projectionViewRTEMatrix._m}getProjectionMatrix(){return this.projectionMatrix._m}getInverseProjectionMatrix(){return this.inverseProjectionMatrix._m}setProjectionMatrix(e,t,i,s,r,n=10){if(r){let r=n*Math.tan(e*Qt),o=r*t;this._setFrustumParams(r,o,i,s),this.projectionMatrix.setOrthographic(this.left,this.right,this.bottom,this.top,this.near,this.far)}else{let r=i*Math.tan(e*Qt),n=r*t;this._setFrustumParams(r,n,i,s),this.projectionMatrix.setPerspective(this.left,this.right,this.bottom,this.top,this.near,this.far)}this.projectionMatrix.inverseTo(this.inverseProjectionMatrix)}_setFrustumParams(e,t,i,s){this.top=e,this.right=t,this.bottom=-this.top,this.left=-this.right,this.near=i,this.far=s}setProjectionViewRTEMatrix(e){this.projectionViewRTEMatrix=this.projectionMatrix.mul(e)}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],Oe(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],Oe(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],Oe(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],Oe(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],Oe(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],Oe(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,s=!0;for(let r=0;r<6;r++){t=0,i=0;for(let s=0;s<8&&(0===i||0===t);s++)e.vertices[s].dotArr(this._f[r])+this._f[r][3]<0?t++:i++;if(0===i)return!1;t>0&&(s=!0)}return s}}const K=class{};K.Linear=e=>e,K.QuadIn=e=>e*e,K.QuadOut=e=>1-(1-e)*(1-e),K.QuadInOut=e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,K.CubicIn=e=>e*e*e,K.CubicOut=e=>1-Math.pow(1-e,3),K.CubicInOut=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,K.QuartIn=e=>e*e*e*e,K.QuartOut=e=>1-Math.pow(1-e,4),K.QuartInOut=e=>e<.5?8*e*e*e*e:1-Math.pow(-2*e+2,4)/2,K.QuintIn=e=>e*e*e*e*e,K.QuintOut=e=>1-Math.pow(1-e,5),K.QuintInOut=e=>e<.5?16*e*e*e*e*e:1-Math.pow(-2*e+2,5)/2,K.SineIn=e=>1-Math.cos(e*Math.PI/2),K.SineOut=e=>Math.sin(e*Math.PI/2),K.SineInOut=e=>-(Math.cos(Math.PI*e)-1)/2,K.ExpoIn=e=>0===e?0:Math.pow(2,10*e-10),K.ExpoOut=e=>1===e?1:1-Math.pow(2,-10*e),K.ExpoInOut=e=>0===e?0:1===e?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2,K.CircIn=e=>1-Math.sqrt(1-Math.pow(e,2)),K.CircOut=e=>Math.sqrt(1-Math.pow(e-1,2)),K.CircInOut=e=>e<.5?(1-Math.sqrt(1-Math.pow(2*e,2)))/2:(Math.sqrt(1-Math.pow(-2*e+2,2))+1)/2,K.BackIn=e=>2.70158*e*e*e-1.70158*e*e,K.BackOut=e=>1+2.70158*Math.pow(e-1,3)+1.70158*Math.pow(e-1,2),K.BackInOut=e=>{const t=2.5949095;return e<.5?Math.pow(2*e,2)*(7.189819*e-t)/2:(Math.pow(2*e-2,2)*((t+1)*(2*e-2)+t)+2)/2},K.ElasticIn=e=>{const t=2*Math.PI/3;return 0===e?0:1===e?1:-Math.pow(2,10*e-10)*Math.sin((10*e-10.75)*t)},K.ElasticOut=e=>{const t=2*Math.PI/3;return 0===e?0:1===e?1:Math.pow(2,-10*e)*Math.sin((10*e-.75)*t)+1},K.ElasticInOut=e=>{const t=2*Math.PI/4.5;return 0===e?0:1===e?1:e<.5?-Math.pow(2,20*e-10)*Math.sin((20*e-11.125)*t)/2:Math.pow(2,-20*e+10)*Math.sin((20*e-11.125)*t)/2+1},K.BounceOut=e=>e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375,K.BounceIn=e=>1-K.BounceOut(1-e),K.BounceInOut=e=>e<.5?.5*(1-K.BounceOut(1-2*e)):.5*(K.BounceOut(2*e-1)+1);let Or=K;const Rh=["viewchange","moveend","flystart","flyend","flystop"],ba=Or.CubicInOut,Ss=class e{constructor(t={}){if(this.__id=e.__counter__++,this.events=lt(Rh,this),this._isOrthographic=t.isOrthographic??!1,this._focusDistance=null!=t.focusDistance?t.focusDistance:10,this._width=t.width||1,this._height=t.height||1,this.eye=t.eye||new v,this.eyeHigh=new Float32Array(3),this.eyeLow=new Float32Array(3),this._viewAngle=t.viewAngle||47,this._horizontalViewAngle=0,this._viewMatrix=new tt,this._viewMatrixRTE=new tt,this._normalMatrix=new Se,this._r=new v(1,0,0),this._u=new v(0,1,0),this._b=new v(0,0,1),this._f=this._b.negateTo(),this._pr=this._r.clone(),this._pu=this._u.clone(),this._pb=this._b.clone(),this._peye=this.eye.clone(),this.isMoving=!1,this._flight=null,this._completeCallback=null,this._frameCallback=null,this._flying=!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],s=new eo({fov:this._viewAngle,aspect:this.getAspectRatio(),near:i[0],far:i[1]});s.cameraFrustumIndex=this.frustums.length,this.frustums.push(s),this.frustumColors.push(s._pickingColorU[0],s._pickingColorU[1],s._pickingColorU[2])}else{let e=1,t=500,i=new eo({fov:this._viewAngle,aspect:this.getAspectRatio(),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.frustumColorIndex=0,this.isFirstPass=!1,this._projSizeConst=0,this.set(t.eye||new v(0,0,1),t.look||new v,t.up||new v(0,1,0))}get isOrthographic(){return this._isOrthographic}set isOrthographic(e){this._isOrthographic!==e&&(this._isOrthographic=e,this.refresh())}get focusDistance(){return this._focusDistance}set focusDistance(e){e!==this._focusDistance&&(this._focusDistance=e,this._isOrthographic&&this.refresh())}get id(){return this.__id}flyCartesian(e,t={}){this.stopFlying(),t.look=t.look||v.ZERO,t.up=t.up||v.UP,t.duration=t.duration||800;const i=t.ease||ba;this._completeCallback=t.completeCallback||(()=>{}),this._frameCallback=t.frameCallback||(()=>{}),t.startCallback&&t.startCallback.call(this);let s=this.eye.clone(),r=this._u,n=this._b,o=t.up,a=e.clone(),l=v.sub(e,t.look),h=o.cross(l);l.normalize(),h.normalize();let c=l.cross(h);this._flight={fly:e=>{let t=1-i(e),o=s.smerp(a,t),h=r.smerp(c,t),d=v.add(o,n.smerp(l,t).negateTo()),_=new v(o.x-d.x,o.y-d.y,o.z-d.z),u=h.cross(_);_.normalize(),u.normalize();let f=_.cross(u);return{eye:o,n:_,u:u,v:f}},duration:t.duration,startedAt:Date.now()},this._flying=!0,this.events.dispatch(this.events.flystart,this)}stopFlying(){this._flying&&(this._flying=!1,this._flight=null,this._frameCallback=null,this.events.dispatch(this.events.flystop,this))}checkFly(){if(this._flying&&null!==this._flight){let e=Math.min((Date.now()-this._flight.startedAt)/this._flight.duration,1);const t=this._flight.fly(e);this.eye=t.eye,this._r=t.u,this._u=t.v,this._b=t.n,this._f.set(-this._b.x,-this._b.y,-this._b.z),this._frameCallback&&this._frameCallback(),this.update(),e>=1&&(this.stopFlying(),this._completeCallback&&(this.events.dispatch(this.events.flyend,this),this._completeCallback(),this._completeCallback=null))}}isFlying(){return this._flying}checkMoveEnd(){let e=this._r,t=this._u,i=this._b,s=this.eye;this._peye.equal(s)&&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(s)}bindFrustumsPickingColors(e){for(let t=0;t<this.frustums.length;t++)e.assignPickingColor(this.frustums[t])}_init(e){this._setProj(this._viewAngle,this.getAspectRatio()),this.set(e.eye||new v(0,0,1),e.look||new v,e.up||new v(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._f.clone()}getBackward(){return this._b.clone()}update(){let e=this._r,t=this._u,i=this._b,s=this.eye;v.doubleToTwoFloat32Array(s,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,-s.dot(e),-s.dot(t),-s.dot(i),1]),this._viewMatrixRTE.set([e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1]);for(let e=0,t=this.frustums.length;e<t;e++)this.frustums[e].setViewMatrix(this._viewMatrix),this.frustums[e].setProjectionViewRTEMatrix(this._viewMatrixRTE);this.events.dispatch(this.events.viewchange,this)}refresh(){this._setProj(this._viewAngle,this.getAspectRatio()),this.update()}get width(){return this._width}get height(){return this._height}setViewportSize(e,t){this._width=e,this._height=t,this.refresh()}getAspectRatio(){return this._width/this._height}_setProj(e,t){this._viewAngle=e;for(let i=0,s=this.frustums.length;i<s;i++){let s=this.frustums[i];s.setProjectionMatrix(e,t,s.near,s.far,this._isOrthographic,this._focusDistance)}var i,s;this._horizontalViewAngle=(i=e,s=t,Gr*Math.atan(Math.tan(Qt*i)*s)),this._updateViewportParameters()}_updateViewportParameters(){this._tanViewAngle_hrad=Math.tan(this._viewAngle*Qt),this._tanViewAngle_hradOneByHeight=this._tanViewAngle_hrad*(1/this._height),this._projSizeConst=Math.min(this._width<512?512:this._width,this._height<512?512:this._height)/(this._viewAngle*j)}setViewAngle(e){this._viewAngle=e,this.refresh()}getViewAngle(){return this._viewAngle}get viewAngle(){return this._viewAngle}get verticalViewAngle(){return this._viewAngle}get horizontalViewAngle(){return this._horizontalViewAngle}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._f.set(-this._b.x,-this._b.y,-this._b.z),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._f.set(-this._b.x,-this._b.y,-this._b.z),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}setRoll(e){let t=Math.cos(e),i=Math.sin(e),s=this._r.clone();this._r.set(t*s.x-i*this._u.x,t*s.y-i*this._u.y,t*s.z-i*this._u.z),this._u.set(i*s.x+t*this._u.x,i*s.y+t*this._u.y,i*s.z+t*this._u.z)}setPitch(e){let t=Math.cos(e),i=Math.sin(e),s=this._b;this._b.set(t*s.x-i*this._u.x,t*s.y-i*this._u.y,t*s.z-i*this._u.z),this._u.set(i*s.x+t*this._u.x,i*s.y+t*this._u.y,i*s.z+t*this._u.z)}setYaw(e){let t=Math.cos(e),i=Math.sin(e),s=this._r;this._r.set(t*s.x-i*this._b.x,t*s.y-i*this._b.y,t*s.z-i*this._b.z),this._b.set(i*s.x+t*this._b.x,i*s.y+t*this._b.y,i*s.z+t*this._b.z)}setPitchYawRoll(e,t,i){let s=new F;s.setPitchYawRoll(e,t,i),this.setRotation(s)}getPitch(){return this.getRotation().getPitch()}getYaw(){return this.getRotation().getYaw()}getRoll(){return this.getRotation().getRoll()}getAbsolutePitch(){return this.getRotation().getPitch()}getAbsoluteYaw(){return this.getRotation().getYaw()}getAbsoluteRoll(){return this.getRotation().getRoll()}getRotation(){return F.getLookRotation(this._f,this._u).conjugate()}setRotation(e,t,i,s){e.mulVec3Res(t||new v(0,1,0),this._u),e.mulVec3Res(i||new v(1,0,0),this._r),e.mulVec3Res(s||new v(0,0,1),this._b),this._f.set(-this._b.x,-this._b.y,-this._b.z)}rotate(e){e.mulVec3Res(this._u,this._u),e.mulVec3Res(this._r,this._r),e.mulVec3Res(this._b,this._b),this._f.set(-this._b.x,-this._b.y,-this._b.z)}unproject2v(e,t,i){return this.unproject(e.x,e.y,t,i)}unproject(e,t,i,s){let r=.5*this._width,n=.5*this._height,o=(e-r)/r,a=-(t-n)/n,l=this.frustums[0];if(this.isOrthographic){if(i){let e=.5*(l.right-l.left)*o,t=.5*(l.top-l.bottom)*a,r=this.getUp().scale(t),n=this.getRight().scale(e),h=r.addA(n),c=this.eye.add(h),d=this.getForward(),_=c.addA(d.scaleTo(i));return s&&s.copy(_),_.sub(this.eye).normalize()}return this.getForward()}{let e=l.inverseProjectionViewMatrix,t=e.mulVec4(new et(o,a,-1,1)).affinity();return e.mulVec4(new et(o,a,0,1)).affinity().subA(t).toVec3().normalize()}}project3v(e){return this.project(e.x,e.y,e.z)}project(e,t,i){let s=this.frustums[0].projectionViewMatrix.mulVec4(new et(e,t,i,1));return new H((1+s.x/s.w)*this._width*.5,(1-s.y/s.w)*this._height*.5)}rotateAround(e,t=!1,i=v.ZERO,s=v.UP){s=t?this._u:s;let r=tt.getRotation(e,s),n=tt.getRotationAroundPoint(e,i,s);this.eye=n.mulVec3(this.eye),this._u=r.mulVec3(this._u).normalize(),this._r=r.mulVec3(this._r).normalize(),this._b=r.mulVec3(this._b).normalize(),this._f.set(-this._b.x,-this._b.y,-this._b.z)}rotateHorizontal(e,t,i,s){this.rotateAround(e,t,i,s)}rotateVertical(e,t){this.rotateAround(e,!1,t,this._r)}projectedSize(e,t){if(this.isOrthographic){const e=this.frustums[0].projectionMatrix._m;return t*(this._height*e[5]*.5)}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.frustumColorIndex=10*(e+1)/255,this.isFirstPass=e===this.FARTHEST_FRUSTUM_INDEX}getCurrentFrustum(){return this.currentFrustumIndex}containsSphere(e){for(let t=0;t<this.frustums.length;t++)if(this.frustums[t].containsSphere(e))return!0;return!1}get frustum(){return this.frustums[this.currentFrustumIndex]}getProjectionMatrix(){return this.frustum.projectionMatrix._m}getProjectionViewMatrix(){return this.frustum.projectionViewMatrix._m}getProjectionViewRTEMatrix(){return this.frustum.projectionViewRTEMatrix._m}getInverseProjectionViewMatrix(){return this.frustum.inverseProjectionViewMatrix._m}getInverseProjectionMatrix(){return this.frustum.inverseProjectionMatrix._m}viewDistance(e,t=1e4){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e),this.update()}copy(e){this.eye.copy(e.eye),this._r.copy(e._r),this._u.copy(e._u),this._b.copy(e._b),this._f.copy(e._f),this._width=e.width,this._height=e.height,this.setViewAngle(e.viewAngle),this.update()}getAltitude(){return this.eye.y}};Ss.__counter__=0;let Pi=Ss;class wa extends Pi{constructor(e,t={}){super({...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 v,this._insideSegment=null,this.slope=0,this._keyLock=new Me,this._flight=null,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)<=ct&&L.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 s=this.planet.ellipsoid,r=s.lonLatToCartesian(this._lonLat),n=t?s.lonLatToCartesian(t):v.ZERO;this.set(r,n,i||r.getNormal()),this.update()}getLonLat(){return this._lonLat}getHeight(){return this._lonLat.height}getExtentPosition(e,t){t=t||0;let i=e.getNorth(),s=e.getSouth(),r=e.getEast(),n=e.getWest();n>r&&(r+=360);let o=this.planet.ellipsoid,a=new L(r,i),l=o.lonLatToCartesian(a);a.lat=s;let h=o.lonLatToCartesian(a);a.lon=n;let c=o.lonLatToCartesian(a);a.lat=i;let d=o.lonLatToCartesian(a),_=v.sub(l,c).scale(.5).addA(c),u=_.length();u<1e-6&&(a.lon=.5*(r+n),a.lat=.5*(i+s),_=o.lonLatToCartesian(a)),d.subA(_),h.subA(_),l.subA(_),c.subA(_);let f=_.getNormal(),g=f.cross(v.NORTH).normalize(),p=g.cross(f).normalize(),m=Math.max(Math.abs(p.dot(d)),Math.abs(p.dot(h)),Math.abs(p.dot(l)),Math.abs(p.dot(c))),y=Math.max(Math.abs(g.dot(d)),Math.abs(g.dot(h)),Math.abs(g.dot(l)),Math.abs(g.dot(c))),x=Math.tan(this._viewAngle*j*.5),b=this.getAspectRatio()*x,w=Math.max(y/b,m/x);return _.normalize(),_.scale(u+w+t),_}viewExtent(e,t){this.stopFlying(),this.set(this.getExtentPosition(e,t),v.ZERO,v.NORTH),this.update()}flyExtent(e,t,i={}){i.look=v.ZERO,this.flyCartesian(this.getExtentPosition(e,t),i)}viewDistance(e,t=1e4){let i=this.eye.add(this.getForward().scaleTo(t)),s=F.getRotationBetweenVectors(i.getNormal(),e.getNormal());if(s.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let i=e.add(s.mulVec3(this.getBackward()).scale(t)),r=s.mulVec3(this.getUp());this.set(i,e,r)}this.update()}flyLonLat(e,t={}){let i=new L(e.lon,e.lat,e.height||this._lonLat.height);this.flyCartesian(this.planet.ellipsoid.lonLatToCartesian(i),t)}flyDistance(e,t=1e4,i={}){let s=this.eye.add(this.getForward().scaleTo(t)),r=F.getRotationBetweenVectors(s.getNormal(),e.getNormal());if(r.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let s=e.add(r.mulVec3(this.getBackward()).scale(t)),n=r.mulVec3(this.getUp());i.look=e,i.up=n,this.flyCartesian(s,i)}}flyCartesian(e,t={}){this.stopFlying(),t.preventLock||(this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet.normalMapCreator.lock(this._keyLock)),t.amplitude=null!=t.amplitude?t.amplitude:1,t.look=t.look||v.ZERO,t.up=t.up||v.NORTH,t.duration=t.duration||800;const i=t.ease||ba;this._completeCallback=t.completeCallback||(()=>{}),this._frameCallback=t.frameCallback||(()=>{}),t.startCallback&&t.startCallback.call(this),t.look instanceof L&&(t.look=this.planet.ellipsoid.lonLatToCartesian(t.look));let s=this.eye.clone(),r=this._u,n=this._b,o=this.planet.ellipsoid.cartesianToLonLat(e),a=t.up,l=this.planet.ellipsoid.lonLatToCartesian(new L(o.lon,o.lat,0)),h=v.sub(e,t.look),c=a.cross(h);h.normalize(),c.normalize();let d=h.cross(c),_=s.getNormal(),u=l.getNormal(),f=1-_.dot(u),g=t.amplitude*yo*Math.sqrt(f>0?f:0),p=6639613,m=Math.max(this._lonLat.height,o.height);m>p&&(p=m);let y=m+2.5*g*(p-m),x=v.ZERO;this._flight={fly:t=>{let a,l=i(t),c=1-l;if(l>=1)a=e.clone();else{let t=s.smerp(e,c).normalize(),i=this.planet.getRayIntersectionEllipsoid(new V(x,t)),r=this._lonLat.height*c*c*c+3*y*c*c*l+3*y*c*l*l+o.height*l*l*l;a=i.addA(t.scale(r))}let _=r.smerp(d,c),u=v.add(a,n.smerp(h,c).negateTo()),f=new v(a.x-u.x,a.y-u.y,a.z-u.z),g=_.cross(f);f.normalize(),g.normalize();let p=f.cross(g);return{eye:a,n:f,u:g,v:p}},duration:t.duration,startedAt:Date.now()},this._flying=!0,this.events.dispatch(this.events.flystart,this)}stopFlying(){this._flying&&(this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet.normalMapCreator.free(this._keyLock),super.stopFlying())}rotateLeft(e,t){this.rotateHorizontal(e,!0!==t,v.ZERO),this.update()}rotateRight(e,t){this.rotateHorizontal(-e,!0!==t,v.ZERO),this.update()}rotateUp(e){this.rotateVertical(e,v.ZERO),this.update()}rotateDown(e){this.rotateVertical(-e,v.ZERO),this.update()}rotateVertical(e,t,i=0){let s=(new tt).setRotation(this._r,e),r=(new tt).setIdentity().translate(t),n=(new tt).setIdentity().translate(t.negateTo()),o=r.mul(s).mul(n).mulVec3(this.eye),a=s.mulVec3(this._u).normalize(),l=s.mulVec3(this._r).normalize(),h=s.mulVec3(this._b).normalize(),c=o.getNormal(),d=h.dot(c);if(!(a.dot(c)<=0))if(i){let e=d-this.slope;if(d<i&&e<0)return;(d>.1&&a.dot(c)>0||this.slope<=.1||this._u.dot(this.eye.getNormal())<=0)&&(this.eye=o,this._u=a,this._r=l,this._b=h,this._f.set(-h.x,-h.y,-h.z))}else this.eye=o,this._u=a,this._r=l,this._b=h,this._f.set(-h.x,-h.y,-h.z)}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=v.proj_b_to_plane(this.slope>=.97?this.getUp():this.getForward(),e).normalize(),i=v.proj_b_to_plane(v.NORTH,e).normalize(),s=Math.sign(e.dot(t.cross(i)))*Math.acos(t.dot(i))*J;return s<0?360+s:s}isVisible(e){let t=this.eye.length();return this.eye.distance(e)<Math.sqrt(t*t-this.planet.ellipsoid.equatorialSizeSqr)}getPitch(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getPitch()}getYaw(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getYaw()}getRoll(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getRoll()}setPitch(e){let t=this.planet.getFrameRotation(this.eye),i=new F;i.setPitchYawRoll(e,this.getYaw(),this.getRoll(),t),this.setRotation(i)}setYaw(e){let t=this.planet.getFrameRotation(this.eye),i=new F;i.setPitchYawRoll(this.getPitch(),e,this.getRoll(),t),this.setRotation(i)}setRoll(e){let t=this.planet.getFrameRotation(this.eye),i=new F;i.setPitchYawRoll(this.getPitch(),this.getYaw(),e,t),this.setRotation(i)}setPitchYawRoll(e,t,i){let s=this.planet.getFrameRotation(this.eye),r=new F;r.setPitchYawRoll(e,t,i,s).conjugate(),this.setRotation(r)}}const Rs=class e{constructor(t,i={}){this.handler=t,this.__id=e.__counter__++,this._fbo=null,this._width=i.width||t.canvas.width,this._height=i.height||t.canvas.height,this._depthComponent=null!=i.depthComponent?i.depthComponent:"DEPTH_COMPONENT16",this._useDepth=null==i.useDepth||i.useDepth,this._active=!1,this._size=i.size||1,this._depthRenderbuffer=null,this._filter=i.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)}isEqual(e){return!!e&&this.__id===e.__id}};Rs.__counter__=0;let hs=Rs;class mi{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,s,r){this._context.drawImage(e,t||0,i||0,s||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,s="normal 14px Verdana",r="black"){this._context.fillStyle=r,this._context.font=s,this._context.fillText(e,t,i)}getWidth(){return this._canvas.width}getHeight(){return this._canvas.height}load(e,t){let i=new Image,s=this;i.onload=function(){s.resize(i.width,i.height),s._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}}const io={UNSIGNED_BYTE:Uint8Array,FLOAT:Float32Array};class Rt extends hs{constructor(e,t={}){super(e,t),this.readPixelBuffersAsync=e=>{const t=this.handler.gl;if(this._skipFrame)return;this._skipFrame=!0;let i=this.width,s=this.height,r=this.pixelBuffers;this.activate();for(let e=0;e<r.length;e++){let n=r[e];t.bindBuffer(t.PIXEL_PACK_BUFFER,n.buffer),t.bufferData(t.PIXEL_PACK_BUFFER,n.data.byteLength,t.STREAM_READ),t.readBuffer(n.glAttachment),t.readPixels(0,0,i,s,t.RGBA,n.glType,0),t.bindBuffer(t.PIXEL_PACK_BUFFER,null)}this.deactivate();const n=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);var o,a;t.flush(),(o=t,a=n,new Promise(((e,t)=>{!function i(){const s=o.clientWaitSync(a,0,0);s==o.WAIT_FAILED?t():s==o.TIMEOUT_EXPIRED?requestAnimationFrame(i):e()}()}))).then((()=>{this._skipFrame=!1,t.deleteSync(n);for(let e=0;e<r.length;e++){let i=r[e];i.data&&(t.bindBuffer(t.PIXEL_PACK_BUFFER,i.buffer),t.getBufferSubData(t.PIXEL_PACK_BUFFER,0,i.data))}t.bindBuffer(t.PIXEL_PACK_BUFFER,null),e&&e(this)}))},this._targets=Rt.createTargets(t.targets),this._size=this._targets.length,this._renderbufferTarget=null!=t.renderbufferTarget?t.renderbufferTarget:"DEPTH_ATTACHMENT",this.textures=t.textures||new Array(this._size),this.pixelBuffers=[],this._skipFrame=!1}static createTargets(e){let t=0,i=0;return e?e.map((e=>{let s=e.attachment||"COLOR_ATTACHMENT";"COLOR_ATTACHMENT"===s&&(s="COLOR_ATTACHMENT"+t++);let r=e.type||"UNSIGNED_BYTE";return{internalFormat:e.internalFormat||"RGBA",format:e.format||"RGBA",type:r,attachment:s,filter:e.filter||"NEAREST",pixelBufferIndex:e.readAsync?i++:-1,TypeArrayConstructor:io[r]}})):[{internalFormat:"RGBA",format:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT0",filter:"NEAREST",pixelBufferIndex:-1,TypeArrayConstructor:io.UNSIGNED_BYTE}]}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);for(let t=0;t<this.pixelBuffers.length;t++)this.pixelBuffers[t].data=null,e.deleteBuffer(this.pixelBuffers[t].buffer);this.pixelBuffers=[],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._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo);let t=[];for(let i=0;i<this._targets.length;i++){let s=this._targets[i],r=this.textures[i]||this.handler.createEmptyTexture2DExt(this._width,this._height,s.filter,s.internalFormat,s.format,s.type),n=e[s.attachment];r&&(this.bindOutputTexture(r,n),this.textures[i]=r),"DEPTH_ATTACHMENT"!==s.attachment&&t.push(n),-1!==s.pixelBufferIndex&&this._createPixelBuffer(s)}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)}getPixelBufferData(e=0){let t=this._targets[e].pixelBufferIndex;return-1!==t?this.pixelBuffers[t].data:null}_createPixelBuffer(e){let t=this.handler.gl,i=e.pixelBufferIndex,s=this.pixelBuffers[i];s||(s=this.pixelBuffers[i]={buffer:null,data:null,glType:-1,glAttachment:-1});let r=this.width*this.height*4;s.data=null,s.data=new e.TypeArrayConstructor(r),s.buffer=t.createBuffer(),t.bindBuffer(t.PIXEL_PACK_BUFFER,s.buffer),t.bufferData(t.PIXEL_PACK_BUFFER,r,t.STREAM_READ),t.bindBuffer(t.PIXEL_PACK_BUFFER,null),s.glType=t[e.type],s.glAttachment=t[e.attachment]}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,s=0,r=1,n=1){let o=this.handler.gl;o.bindFramebuffer(o.FRAMEBUFFER,this._fbo),o.readBuffer&&o.readBuffer(o.COLOR_ATTACHMENT0+s||0),o.readPixels(t*this._width,i*this._height,r,n,o.RGBA,o[this._targets[s].type],e),o.bindFramebuffer(o.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._targets[t].type],e),i.bindFramebuffer(i.FRAMEBUFFER,null)}getImage(){let e=new Uint8Array(4*this._width*this._height);this.readAllPixels(e);let t=new mi(this._width,this._height);return t.setData(e),t.getImage()}readData(e,t,i,s=0){const r=this.width,n=this.height,o=Math.floor(e*(r-1)),a=4*(Math.floor(t*(n-1))*r+o),l=this.pixelBuffers[s].data;l&&(i[0]=l[a],i[1]=l[a+1],i[2]=l[a+2],i[3]=l[a+3])}}const Mh=["tick","end","start","stop"],Ms=class e{constructor(t={}){this.__handler=null,this.active=!0,this.__id=e.__counter__++,this.events=lt(Mh,this),this.name=t.name||"",this.startDate=t.startDate||0,this.endDate=t.endDate||0;let i=t.currentDate||is(new Date);t.startDate&&i<t.startDate&&(i=t.startDate),t.endDate&&i>t.endDate&&(i=t.endDate),this.currentDate=i,this._multiplier=void 0!==t.multiplier?t.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*tn,this._intervalCallback=t}setDate(e){let t=is(e);this.startDate&&t<this.startDate&&(t=this.startDate),this.endDate&&t>this.endDate&&(t=this.endDate),this.currentDate=t}getDate(){return mr(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=Fo(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))}};Ms.__counter__=0;let Nr=Ms;class Bh{constructor(e,t){t._programController=this,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}}let so=class{constructor(){this.next=null,this.prev=null,this.data=null}};class Js{constructor(e=256){this._current=new so,this._head=this._current;for(let t=0;t<e;t++){let e=new so;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 ro=["","WEBKIT_","MOZ_"],tr=["webgl2","webgl"];class Be{constructor(e,t={}){this.framebufferStack=new Js,this._requestAnimationFrameId=0,this.drawFrame=()=>{let e=window.performance.now(),t=this.deltaTime;this.deltaTime=.5*(e-this._lastAnimationFrameTime+this.prevDeltaTime),this.deltaTime>3?this.deltaTime=3:this.deltaTime<1&&(this.deltaTime=1),this.prevDeltaTime=t,this._lastAnimationFrameTime=e,this.defaultClock.tick(this.deltaTime);for(let e=0;e<this._clocks.length;e++)this._clocks[e].tick(this.deltaTime);let i=this.canvas;Math.floor(i.clientWidth*this._params.pixelRatio)===i.width&&Math.floor(i.clientHeight*this._params.pixelRatio)===i.height||(0===i.clientWidth||0===i.clientHeight?this.stop():document.hidden||(this.start(),this.setSize(i.clientWidth,i.clientHeight))),this._frameCallback()},this.events=lt(["visibilitychange","resize"]),this._throttledDrawFrame=this.drawFrame,this.defaultClock=new Nr,this._clocks=[],this.prevDeltaTime=0,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:zo("og_dpi")||t.pixelRatio||1,extensions:t.extensions||[],context:t.context||{}},this.extensions={},this._canvasTarget=e,this._lastAnimationFrameTime=0,this._initialized=!1,this._frameCallback=function(){},this.transparentTexture=null,this.defaultTexture=null,this.framebufferStack=new Js,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||Gt(t.autoActivate))&&this.initialize()}set frameDelay(e){this._throttledDrawFrame=0===e?this.drawFrame:yi(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,s;for(i in ro)if(s=e.getExtension(ro[i]+t),s)return s}static getContext(e,t){let i=null;try{let s=new URLSearchParams(location.search).get("og_ver");if(s)i=e.getContext(s,t),i&&(i.type=s);else for(let s=0;s<tr.length;s++)if(i=e.getContext(tr[s],t),i){i.type=tr[s];break}}catch{ie.logErr("exception during the GL context initialization")}return i||ie.logErr("could not initialise WebGL"),i}setFrameCallback(e){e&&(this._frameCallback=e)}createEmptyTexture2DExt(e=1,t=1,i="NEAREST",s="RGBA",r="RGBA",n="UNSIGNED_BYTE",o="CLAMP_TO_EDGE",a=0){let l=this.gl,h=l.createTexture();return l.bindTexture(l.TEXTURE_2D,h),l.texImage2D(l.TEXTURE_2D,a,l[s.toUpperCase()],e,t,0,l[r.toUpperCase()],l[n.toUpperCase()],null),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l[i.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l[i.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l[o.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l[o.toUpperCase()]),l.bindTexture(l.TEXTURE_2D,null),h}createEmptyTexture_n(e,t,i,s){let r=this.gl,n=r.createTexture();return r.bindTexture(r.TEXTURE_2D,n),r.texImage2D(r.TEXTURE_2D,0,i||r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,s||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,s||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),n}createEmptyTexture_l(e,t,i,s){let r=this.gl,n=r.createTexture();return r.bindTexture(r.TEXTURE_2D,n),r.texImage2D(r.TEXTURE_2D,0,i||r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,s||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,s||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),n}createTexture_n_webgl1(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texImage2D(r.TEXTURE_2D,0,t||r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_l_webgl1(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texImage2D(r.TEXTURE_2D,0,t||r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_mm_webgl1(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texImage2D(r.TEXTURE_2D,0,t||r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_a_webgl1(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texImage2D(r.TEXTURE_2D,0,t||r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameterf(r.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_n_webgl2(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texStorage2D(r.TEXTURE_2D,1,t||r.RGBA8,e.width,e.height),r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.width,e.height,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_l_webgl2(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texStorage2D(r.TEXTURE_2D,1,t||r.RGBA8,e.width,e.height),r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.width,e.height,r.RGBA,r.UNSIGNED_BYTE,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_mm_webgl2(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texStorage2D(r.TEXTURE_2D,2,t||r.RGBA8,e.width,e.height),r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.width,e.height,r.RGBA,r.UNSIGNED_BYTE,e),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}createTexture_a_webgl2(e,t,i,s=null){let r=this.gl;return s=s||r.createTexture(),r.bindTexture(r.TEXTURE_2D,s),r.texStorage2D(r.TEXTURE_2D,2,t||r.RGBA8,e.width,e.height),r.texSubImage2D(r.TEXTURE_2D,0,0,0,e.width,e.height,r.RGBA,r.UNSIGNED_BYTE,e),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameterf(r.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,i||r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,i||r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),s}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 s=[[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 mi;r.fillEmpty();let n=r.getImage();for(let e=0;e<s.length;e++){let r=s[e][1];t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texImage2D(r,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,n)}for(let e=0;e<s.length;e++){let r=s[e][1],n=new Image;n.crossOrigin="",n.onload=function(e,i,s){return function(){t&&e&&(t.bindTexture(t.TEXTURE_CUBE_MAP,e),t.texImage2D(i,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s))}}(i,r,n),n.src=s[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 Bh(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=Be.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||!this.canvas||(this.gl=Be.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[e.length-1].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,s=4){let r=this.gl,n=r.createBuffer();return r.bindBuffer(r.ARRAY_BUFFER,n),r.bufferData(r.ARRAY_BUFFER,t*e*s,i||r.STREAM_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),n.itemSize=e,n.numItems=t,n}setStreamArrayBuffer(e,t,i=0){let s=this.gl;return s.bindBuffer(s.ARRAY_BUFFER,e),s.bufferSubData(s.ARRAY_BUFFER,i,t),s.bindBuffer(s.ARRAY_BUFFER,null),e}createArrayBuffer(e,t,i,s){let r=this.gl,n=r.createBuffer();return r.bindBuffer(r.ARRAY_BUFFER,n),r.bufferData(r.ARRAY_BUFFER,e,s||r.STATIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),n.itemSize=t,n.numItems=i||e.length/t,n}createArrayBufferLength(e,t){let i=this.gl,s=i.createBuffer();return i.bindBuffer(i.ARRAY_BUFFER,s),i.bufferData(i.ARRAY_BUFFER,e,t||i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),s.itemSize=1,s.numItems=e,s}createElementArrayBuffer(e,t,i,s){let r=this.gl,n=r.createBuffer();return r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,n),r.bufferData(r.ELEMENT_ARRAY_BUFFER,e,s||r.STATIC_DRAW),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,null),n.itemSize=t,n.numItems=i||e.length,n}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.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 H(Math.round(.5*e.width),Math.round(.5*e.height)):new H}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,s;if(e&&e.color)i=new mi(2,2),i.fillColor(e.color),s=this.createTexture_n(i.getCanvas()),s.default=!0,t(s);else if(e&&e.url){let i=new Image,r=this;i.onload=function(){s=r.createTextureDefault(i),s.default=!0,t(s)},i.src=e.url}else i=new mi(2,2),i.fillColor("#C5C5C5"),s=this.createTexture_n(i.getCanvas()),s.default=!0,t(s)}deleteTexture(e){e&&!e.default&&this.gl&&this.gl.deleteTexture(e)}destroy(){var e,t;null==(e=this.resizeObserver)||e.disconnect(),null==(t=this.intersectionObserver)||t.disconnect(),this.stop();for(let e in this.programs)this.removeProgram(e);let i=this.gl;if(i){i.deleteTexture(this.transparentTexture),this.transparentTexture=null,i.deleteTexture(this.defaultTexture),this.defaultTexture=null,this.framebufferStack=new Js;let e=i.getParameter(i.MAX_VERTEX_ATTRIBS),t=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,t);for(let t=0;t<e;++t)i.disableVertexAttribArray(t),i.vertexAttribPointer(t,4,i.FLOAT,!1,0,0),i.vertexAttrib1f(t,0);i.deleteBuffer(t);let s=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS);for(let e=0;e<s;++e)i.activeTexture(i.TEXTURE0+e),i.bindTexture(i.TEXTURE_CUBE_MAP,null),i.bindTexture(i.TEXTURE_2D,null);i.activeTexture(i.TEXTURE0),i.useProgram(null),i.bindBuffer(i.ARRAY_BUFFER,null),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindRenderbuffer(i.RENDERBUFFER,null),i.disable(i.BLEND),i.disable(i.CULL_FACE),i.disable(i.DEPTH_TEST),i.disable(i.DITHER),i.disable(i.SCISSOR_TEST),i.blendColor(0,0,0,0),i.blendEquation(i.FUNC_ADD),i.blendFunc(i.ONE,i.ZERO),i.clearColor(0,0,0,0),i.clearDepth(1),i.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 Ta extends hs{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 s=e.createRenderbuffer();e.bindRenderbuffer(e.RENDERBUFFER,s),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,s),t.push(e.COLOR_ATTACHMENT0+i),this.renderbuffers[i]=s,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)}}const Oc=Object.freeze(Object.defineProperty({__proto__:null,Framebuffer:Rt,Handler:Be,Multisample:Ta,Program:X,types:ht},Symbol.toStringTag,{value:"Module"}));class Ca extends Ai{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,ur(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=$e(2*e.width,4096),this._frameHeight=$e(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&&(ur(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}}const Nc=Object.freeze(Object.defineProperty({__proto__:null,AtmosphereConfig:class extends Q{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 dt({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 Kt({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 ut({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-groundAlbedo"></div>\n \n </div>'}),this._maxOpacity=new Z({label:"Max.opacity",max:5}),this._minOpacity=new Z({label:"Min.opacity",max:5}),this._rayleight=new Z({label:"Rayleight Scale",min:-10,max:10}),this._mie=new Z({label:"Mie Scale",min:-10,max:10}),this._height=new Z({label:"Height",max:1e6}),this._bottomRadius=new Z({label:"Polar Radius (BOTTOM_RADIUS)",max:31783761.571225896}),this._equatorialRadius=new Z({label:"Equatorial Radius (EQUATORIAL_RADIUS)",max:31890685}),this._mieScatteringCoefficient=new Z({label:"Mie Scattering Coefficient e-6",min:-39.96,max:39.96}),this._mieExtinctionCoefficient=new Z({label:"Mie Extinction Coef.e-6",min:4.44*-10,max:10*4.44}),this._rayleighScatteringCoefficientA=new Z({label:"Rayleight Scattering Coef A.e-6",min:5.802*-10,max:10*5.802}),this._rayleighScatteringCoefficientB=new Z({label:"Rayleight Scattering Coef B.e-6",min:13.558*-10,max:10*13.558}),this._rayleighScatteringCoefficientC=new Z({label:"Rayleight Scattering Coef C.e-6",min:-331,max:331}),this._ozoneAbsorptionCoefficientA=new Z({label:"Ozone absorbtion Coef A.e-6",min:-6.5,max:6.5}),this._ozoneAbsorptionCoefficientB=new Z({label:"Ozone absorbtion Coef B.e-6",min:-6.5,max:18.81}),this._ozoneAbsorptionCoefficientC=new Z({label:"Ozone absorbtion Coef C.e-6",min:.085*-10,max:10*.085}),this._ozoneDensityHeight=new Z({label:"Ozone Density Height",max:25e5}),this._ozoneDensityWide=new Z({label:"Ozone Density Wide",max:25e5}),this._sunAngularRadius=new Z({label:"Sun Angular Radius",max:4.685}),this._sunIntensity=new Z({label:"Sun Intensity",max:10}),this._groundAlbedo=new Z({label:"Ground Albedo (GROUND_ALBEDO)",max:.5}),this._parameters={ATMOS_HEIGHT:0,RAYLEIGH_SCALE:0,MIE_SCALE:0,GROUND_ALBEDO:0,BOTTOM_RADIUS:0,EQUATORIAL_RADIUS:0,rayleighScatteringCoefficient_0:0,rayleighScatteringCoefficient_1:0,rayleighScatteringCoefficient_2:0,mieScatteringCoefficient:0,mieExtinctionCoefficient:0,ozoneAbsorptionCoefficient_0:0,ozoneAbsorptionCoefficient_1:0,ozoneAbsorptionCoefficient_2:0,SUN_ANGULAR_RADIUS:0,SUN_INTENSITY:0,ozoneDensityHeight:0,ozoneDensityWide:0,disableSunDisk:!1}}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-groundAlbedo"),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._equatorialRadius.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._bottomRadius.max=5*this.planet.ellipsoid.getPolarSize(),this._equatorialRadius.max=5*this.planet.ellipsoid.getEquatorialSize(),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._equatorialRadius.value=this._parameters.EQUATORIAL_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._equatorialRadius.events.on("change",(e=>{this._parameters.EQUATORIAL_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)}},CameraDepthHandler:class extends Q{constructor(e){super(e),this._skipPreRender=!1,this._depthHandlerCallback=e=>{if(!this.planet)return;let t=e.frameBuffer;if(t.handler.gl,t.activate(),this._quadTreeStrategy){let t=e.camera;this._skipPreRender&&this._quadTreeStrategy.collectRenderNodes(t),this._skipPreRender=!0,console.log(this._quadTreeStrategy._renderedNodes)}t.deactivate(),t.readPixelBuffersAsync();let i=this.getLonLatFromPixelTerrain(1,1),s=this.getLonLatFromPixelTerrain(t.width-1,1),r=this.getLonLatFromPixelTerrain(t.width-1,t.height-1),n=this.getLonLatFromPixelTerrain(1,t.height-1);i&&s&&r&&n&&this.cameraGeoImage.setCorners([[i.lon,i.lat],[s.lon,s.lat],[r.lon,r.lat],[n.lon,n.lat]])},this._frameComposer=new Fr,this._frameHandler=null,this.cameraGeoImage=new Ca(`cameraGeoImage:${this.__id}`,{src:"test4.jpg",corners:[[0,1],[1,1],[1,0],[0,0]],visibility:!0,isBaseLayer:!1,opacity:.7}),this._quadTreeStrategy=null}_createCamera(){return this.planet?new wa(this.planet,{frustums:[[100,1e9]],width:640,height:480,viewAngle:45}):new Pi({frustums:[[100,1e9]],width:640,height:480,viewAngle:45})}get camera(){if(this._frameHandler)return this._frameHandler.camera}oninit(){if(super.oninit(),!this.renderer)return;this.renderer.handler.addProgram(new X("camera_depth",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"#version 300 es\n \n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in 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 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:"#version 300 es\n \n precision highp float; \n\n layout(location = 0) out vec4 depthColor;\n\n void main(void) {\n depthColor = vec4(gl_FragCoord.z, gl_FragCoord.z, gl_FragCoord.z, 1.0);\n }"})),this.planet&&this.planet.addLayer(this.cameraGeoImage);let e=new Rt(this.renderer.handler,{width:640,height:480,targets:[{internalFormat:"RGBA16F",type:"FLOAT",attachment:"COLOR_ATTACHMENT",readAsync:!0}],useDepth:!0});if(this._frameHandler=new to({camera:this._createCamera(),frameBuffer:e,frameHandler:this._depthHandlerCallback}),this.renderer.controls.CameraFrameComposer?this._frameComposer=this.renderer.controls.CameraFrameComposer:this.renderer.addControl(this._frameComposer),this._frameComposer.add(this._frameHandler),this.planet){const e={planet:this.planet,maxEqualZoomAltitude:this.planet.quadTreeStrategy.maxEqualZoomAltitude,minEqualZoomAltitude:this.planet.quadTreeStrategy.minEqualZoomAltitude,minEqualZoomCameraSlope:this.planet.quadTreeStrategy.minEqualZoomCameraSlope,transitionOpacityEnabled:!1};this._quadTreeStrategy=new this.planet.quadTreeStrategyPrototype(e),this._quadTreeStrategy.init(this.camera),this._quadTreeStrategy.preRender(),this._quadTreeStrategy.clearRenderedNodes(),this._skipPreRender=!1,this._quadTreeStrategy.preLoad()}}get framebuffer(){if(this._frameHandler)return this._frameHandler.frameBuffer}getCartesianFromPixelTerrain(e,t){if(this._frameHandler){let i=this._frameHandler.frameBuffer,s=this._frameHandler.camera,r=function(e,t,i,s){let r=new H(e,t),n=r.x/s.width,o=(s.height-r.y)/s.height,a=new Float32Array(4),l=0;if(s.readData(n,o,a,0),0===a[0])return 0;let h=a[0],c=i.frustums[0].inverseProjectionMatrix,d=new et(2*n-1,2*o-1,2*h-1,1),_=c.mulVec4(d),u=i.unproject(n*i.width,(1-o)*i.height);return l=-_.z/_.w/u.dot(i.getForward()),l}(e,t,s,i);if(0===r)return;let n=e/i.width,o=(i.height-t)/i.height;return s.unproject(n*s.width,(1-o)*s.height).scaleTo(r).addA(s.eye)}}getLonLatFromPixelTerrain(e,t){if(this.planet){let i=this.getCartesianFromPixelTerrain(e,t);if(i)return this.planet.ellipsoid.cartesianToLonLat(i)}}activate(){super.activate()}deactivate(){super.deactivate()}},CameraFrameComposer:Fr,CameraFrameHandler:to,CameraLock:Jn,CompassButton:Ho,Control:Q,DebugInfo:class extends Q{constructor(e={}){e.name&&""!==e.name||(e.name="DebugInfo"),super(e),this.el=null,this._watch=e.watch||[],this._toggleBtn=new dt({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 Kt({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 ss("Tile grid",{visibility:!0,isBaseLayer:!1,hideInLayerSwitcher:!0,drawTile:function(e,t){let i,s=document.createElement("canvas"),r=s.getContext("2d");s.width=256,s.height=256,r.clearRect(0,0,s.width,s.height),r.beginPath(),r.rect(0,0,s.width,s.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,s.width/2,s.height/2),t(s)}})}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(){var e;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 t=document.createElement("div");t.classList.add("og-debuginfo_controls"),this.el.appendChild(t);let i=this._watch;this._watch=[];for(let e=0;e<i.length;e++)this.addWatch(i[e]);null==(e=this._dialog.container)||e.appendChild(this.el),this.renderer.events.on("draw",this._frame,this);let s=this.planet;s&&this.addWatches([{label:"Nodes count",frame:()=>s.quadTreeStrategy._renderedNodes.length},{label:"Planet._fadingNodes",frame:()=>s.quadTreeStrategy._fadingNodes.size},{label:"createdNodes",frame:()=>s._createdNodesCount},{label:"indexesCache",frame:()=>s._indexesCacheToRemoveCounter},{label:"distBeforeMemClear",frame:()=>Math.round(s._distBeforeMemClear)},{label:"maxZoom/minZoom",frame:()=>s.quadTreeStrategy.maxCurrZoom+" / "+(null==s?void 0:s.quadTreeStrategy.minCurrZoom)},{label:"viewExtent",frame:()=>s.getViewExtent().toString()},{label:"Mouse distance, m",frame:()=>{let e=s.getCartesianFromMouseTerrain();return e?s.camera.eye.distance(e).toFixed(3):""}},{label:"lodSize",frame:()=>Math.round(s.quadTreeStrategy.lodSize)},{label:"deltaTime/FPS",frame:()=>`<div style="width:70px"><div style="width:20px; float: left;">\n ${Math.round(s.renderer.handler.deltaTime)}\n </div> <div style="float: left">\n ${Math.round(1e3/s.renderer.handler.deltaTime)}\n </div></div>`},{label:"-------------------------"},{label:"Pitch, deg",frame:()=>(s.camera.getPitch()*J).toFixed(2)},{label:"Yaw, deg",frame:()=>(s.camera.getYaw()*J).toFixed(2)},{label:"Roll, deg",frame:()=>(s.camera.getRoll()*J).toFixed(2)},{label:"Lon, Lat",frame:()=>`<div style="width:190px">${s.camera._lonLat.lon.toFixed(7)}, ${s.camera._lonLat.lon.toFixed(7)}</div>`},{label:"height/alt, m",frame:()=>`<div style="width:190px">${s.camera._lonLat.height.toFixed(2)+" / "+s.camera.getAltitude().toFixed(2)}</div>`},{label:"cam.slope",frame:()=>s.camera.slope.toFixed(3)},{label:"-------------------------"},{label:"_renderCompleted / renderCompletedActivated",frame:()=>`${s.quadTreeStrategy._renderCompleted} / ${s.quadTreeStrategy._renderCompletedActivated}`},{label:"_terrainCompleted / terrainCompletedActivated",frame:()=>`${s.quadTreeStrategy._terrainCompleted} / ${s.quadTreeStrategy._terrainCompletedActivated}`},{label:"PlainWorker",frame:()=>s._plainSegmentWorker.pendingQueue.length},{label:"TileLoader",frame:()=>`${s._tileLoader.loading} ${s._tileLoader.queue.length}`},{label:"TerrainLoader",frame:()=>s.terrain&&!s.terrain.isEmpty?`${s.terrain.loader.loading} ${s.terrain.loader.queue.length}`:""},{label:"TerrainWorker",frame:()=>s._terrainWorker.pendingQueue.length},{label:"NormalMapCreator",frame:()=>s._normalMapCreator.queueSize},{label:"VectorTileCreator",frame:()=>s._vectorTileCreator.queueSize}]);let r=new dt({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"});r.appendTo(t),r.events.on("change",(e=>{e?s.lockQuadTree():s.unlockQuadTree()}));let n=new dt({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"});n.appendTo(t),n.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:kn,DrawingSwitcher:class extends Q{constructor(e={}){super({name:"DrawingSwitcher",...e}),this.drawingControl=new kn(e)}oninit(){this.planet.addControl(this.drawingControl),this._createMenu()}onactivate(){this.drawingControl.activate()}ondeactivate(){this.drawingControl.deactivate()}_createMenu(){let e=new dt({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 dt({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 dt({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 jo({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:da,ElevationProfileControl:class extends Q{constructor(e={}){super({name:"ElevationProfileControl",...e}),this._onSceneChange=()=>{this._collectProfileThrottled()},this._onElevationProfilePointer=(e,t,i,s,r,n,o,a)=>{let l=this._elevationProfileScene.getPointLonLat(n),h=this._elevationProfileScene.getPointLonLat(n+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(_)),a)},this._onElevationProfileDblClick=(e,t,i,s,r,n,o,a)=>{let l=this._elevationProfileScene.getPointLonLat(n),h=this._elevationProfileScene.getPointLonLat(n+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 ih,this._elevationProfileView=new $l,this._elevationProfileLegend=new ah,this._elevationProfileButtonsView=new nh({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 Kt({title:"Elevation Profile",visible:!1,resizable:!0,useHide:!0,top:175,left:65,width:400,height:200,minHeight:100,minWidth:100}),this._graphView=new ut({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 oh({model:this._elevationProfileScene}),this._toggleBtn=new dt({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=yi((()=>{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.planet&&this._elevationProfileScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._elevationProfileScene)}ondeactivate(){this._poiListDialog.setVisibility(!1),this._elevationProfileView.model.clear(),this.renderer&&this.renderer.removeNode(this._elevationProfileScene),this._dialog.hide()}},FramebufferPreview:class extends Q{constructor(e){super({autoActivate:!0,...e}),this._onDraw=()=>{if(this._framebuffer&&this._screenFramebuffer){let e=this.renderer,t=e.handler.gl;t.disable(t.BLEND),this._screenFramebuffer.activate();let i=this._program._programController,s=i._program;t.bindBuffer(t.ARRAY_BUFFER,e.screenFramePositionBuffer),t.vertexAttribPointer(s.attributes.corners,2,t.FLOAT,!1,0,0),i.activate(),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._framebuffer.textures[this.framebufferCurrentTexture]),t.uniform1i(s.uniforms.inputTexture,0),t.drawArrays(t.TRIANGLE_STRIP,0,4),this._screenFramebuffer.deactivate(),t.enable(t.BLEND),this._screenFramebuffer.readPixelBuffersAsync((e=>{let t=e.getPixelBufferData();if(t){let i=e.width,s=e.height,r=this.$canvas.getContext("2d"),n=new Uint8ClampedArray(t.buffer,t.byteOffset,t.byteLength),o=new ImageData(n,i,s);createImageBitmap(o).then((e=>{r.clearRect(0,0,this.$canvas.width,this.$canvas.height),r.drawImage(e,0,0,this.$canvas.width,this.$canvas.height)}))}}))}},this._dialog=new Kt({title:e.title||"",width:580,height:340,left:100,top:100}),this.$canvas=function(e,t){let i=document.createElement("canvas");return i.width=e,i.height=t,i.style.position="absolute",i.style.width="100%",i.style.height="100%",i}(this._dialog.width,this._dialog.height),this._framebuffer=e.framebuffer||null,this._screenFramebuffer=null,this.framebufferCurrentTexture=0,this._program=function(e=0,t,i,s){return new X(`framebuffer_dialog_screen:${e.toString()}`,{uniforms:{inputTexture:"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 ${s?"tc.y = 1.0 - tc.y;":""} \n }`,fragmentShader:`#version 300 es\n\n precision highp float;\n\n uniform sampler2D inputTexture;\n \n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n\n ${t||""}\n \n ${i||"void mainImage(out vec4 fragColor, in vec2 fragCoord) { \n fragColor = texture(inputTexture, fragCoord);\n }"}\n \n void main(void) { \n mainImage(fragColor, tc);\n }`})}(this.__id,e.common,e.image,e.flippedUV)}bindFramebuffer(e){e.isEqual(this._framebuffer)||(this._framebuffer=e)}oninit(){var e,t;super.oninit(),this.renderer&&(this.renderer.handler.addProgram(this._program),this._screenFramebuffer=new Rt(this.renderer.handler,{width:null==(e=this._framebuffer)?void 0:e.width,height:null==(t=this._framebuffer)?void 0:t.height,useDepth:!1,targets:[{internalFormat:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT",readAsync:!0}]}),this._screenFramebuffer.init())}activate(){var e,t;super.activate(),this._dialog.appendTo(document.body),null==(e=this._dialog.container)||e.appendChild(this.$canvas),null==(t=this.renderer)||t.events.on("draw",this._onDraw)}deactivate(){var e;super.deactivate(),this._dialog.remove(),null==(e=this.renderer)||e.events.off("draw",this._onDraw)}},GeoImageDragControl:class extends Q{constructor(e={}){super(e),this._cornerIndex=-1,this._catchCorner=!1,this._toggleBtn=new dt({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 Ai&&(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 Ai&&(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.navigation.activate()}_onLDown(e){-1!==this._cornerIndex&&(this._catchCorner=!0,e.renderer.controls.navigation.deactivate())}_onMouseLeave(){document.body.style.cursor="auto"}_onMouseMove(e){let t=e.pickingObject;const i=this.planet;if(this._catchCorner){let s=t.getCornersLonLat();s[this._cornerIndex]=i.getLonLatFromPixelTerrain(e),t.setCornersLonLat(s)}else{this._cornerIndex=-1;for(let s=0;s<t._cornersWgs84.length;s++){let r=i.getLonLatFromPixelTerrain(e);if(r&&i.ellipsoid.getGreatCircleDistance(t._cornersWgs84[s],r)/i.getDistanceFromPixel(e)<=.05){this._cornerIndex=s,document.body.style.cursor="move";break}document.body.style.cursor="auto"}}}},GeoObjectEditor:class extends Q{constructor(e={}){super(e),this._geoObjectEditopScene=new gh({name:`geoObjectEditorScene:${this.__id}`}),this._dialog=new xh({model:this._geoObjectEditopScene})}oninit(){this.renderer&&(this.renderer.addControl(new Jn({planet:this.planet})),this._geoObjectEditopScene.bindPlanet(this.planet),this._dialog.appendTo(this.renderer.div||document.body),this.activate())}onactivate(){this.renderer&&this.renderer.addNode(this._geoObjectEditopScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._geoObjectEditopScene),this._dialog.hide()}},HeightRuler:Hn,KeyboardNavigation:class extends Q{constructor(e={}){e=e||{},super({name:"KeyboardNavigation",...e}),this.onCameraPitchUp=()=>{this._camera&&this._camera.setPitch(this._camera.getPitch()+.1*j)},this.onCameraPitchDown=()=>{this._camera&&this._camera.setPitch(this._camera.getPitch()-.1*j)},this.onCameraYawLeft=()=>{this._camera&&this._camera.setYaw(this._camera.getYaw()-.1*j)},this.onCameraYawRight=()=>{this._camera&&this._camera.setYaw(this._camera.getYaw()+.1*j)},this.onCameraMoveForward=()=>{this._camera&&this.force.addA(this._camera.getForward()).normalize()},this.onCameraMoveBackward=()=>{this._camera&&this.force.addA(this._camera.getBackward()).normalize()},this._camera=e.camera||null,this.speed=e.speed||10,this.force=new v,this.vel=new v,this.mass=1}bindCamera(e){this._camera=e}onactivate(){let e=this.renderer;e.events.on("keypress",W.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",W.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",W.KEY_UP,this.onCameraPitchUp,this),e.events.on("keypress",W.KEY_DOWN,this.onCameraPitchDown,this),e.events.on("keypress",W.KEY_LEFT,this.onCameraYawLeft,this),e.events.on("keypress",W.KEY_RIGHT,this.onCameraYawRight,this),e.events.on("draw",this.onDraw,this,-1e3)}ondeactivate(){this.renderer}oninit(){this.activate()}get dt(){return.001*this.renderer.handler.deltaTime}onDraw(){if(this.renderer&&this._camera){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(.96),this.force.set(0,0,0);let t=this._camera;t.eye=t.eye.add(this.vel.scaleTo(this.dt)),t.update()}}},LayerAnimation:class extends Q{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 s=this._layersArr[this._currVisibleIndex];if(s){s.opacity=0,s.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=lt(Tl),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,s=i>this._layersArr.length?this._layersArr.length:i;e<s;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,s=i>this._layersArr.length?this._layersArr.length:i;e<s;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){var t;this._layersArr.push(e),e.setVisibility(!1),e.setBaseLayer(!1),e.opacity=0,null==(t=this.planet)||t.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 s=this._currentIndex;this._currentIndex=e,this._playIndex=e;let r=this._getFrameIndex(s),n=this._getFrameIndex(this._currentIndex),o=this._layersArr[s],a=this._layersArr[e],l=n!=r;l&&this._appendFrameToPlanet(n),o&&(o.isIdle?this._currVisibleIndex=s:(o.opacity=0,o.setVisibility(!1))),a&&(a.opacity=0,a.setVisibility(!0),requestAnimationFrame((()=>{if(a.isIdle||t){a.opacity=1,l&&this._removeFrameFromPlanet(r),o&&(o.opacity=0,o.setVisibility(!1));let e=this._layersArr[this._currVisibleIndex];e&&(e.opacity=0,e.setVisibility(!1))}})),i||this.events.dispatch(this.events.change,this._currentIndex,s))}}},LayerSwitcher:class extends Q{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 Kt({title:"Layer Switcher",top:15,useHide:!0,visible:!1,width:300,maxHeight:500}),this._panel=new ut({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 dt({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 Cl({model:e})}onactivate(){}ondeactivate(){this._dialog.hide()}},Lighting:class extends Q{constructor(e={}){super(e),this._selectedLayer=null,this._toggleBtn=new dt({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 Kt({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 ut({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 Z({label:"Max.opacity",max:5}),this._atmosphereMinOpacity=new Z({label:"Min.opacity",max:5}),this._simpleSkyBackgroundColorOne=new zn({label:"Color One"}),this._simpleSkyBackgroundColorTwo=new zn({label:"Color Two"}),this._gamma=new Z({label:"Gamma",max:5}),this._exposure=new Z({label:"Exposure",max:5}),this._night=new Z({label:"Nightlight",max:5}),this._opacity=new Z({label:"Opacity",max:1}),this._diffuse_r=new Z({label:"Diffuse R",max:5}),this._diffuse_g=new Z({label:"Diffuse G",max:5}),this._diffuse_b=new Z({label:"Diffuse B",max:5}),this._ambient_r=new Z({label:"Ambient R",max:5}),this._ambient_g=new Z({label:"Ambient G",max:5}),this._ambient_b=new Z({label:"Ambient B",max:5}),this._specular_r=new Z({label:"Specular R",max:.2}),this._specular_g=new Z({label:"Specular G",max:.2}),this._specular_b=new Z({label:"Specular B",max:.2}),this._shininess=new Z({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 dt({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 dt({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 s=new dt({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"});s.appendTo(e),s.events.on("change",(e=>{this.planet.lightEnabled=e}));let r=new dt({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 n=this.planet.renderer.controls.SimpleSkyBackground;n&&(this._simpleSkyBackgroundColorOne.value=n.colorOne,this._simpleSkyBackgroundColorTwo.value=n.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 s=e&&e._specular?e._specular:this.planet._specular;this._specular_r.value=s[0],this._specular_g.value=s[1],this._specular_b.value=s[2],this._shininess.value=s[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){}},Navigation:Yi,Object3dManager:class extends Q{constructor(e={}){super(e),this._onSelect=e=>{this._currentItem=e},this._onClick=e=>{if(!this.planet||!this._layer||!this._currentItem)return;let t=this.planet.getLonLatFromPixelTerrain(e.pos);if(t&&(this.renderer.setRelativeCenter(this.planet.camera.eye),this.renderer.events.isKeyPressed(W.KEY_CTRL))){let e=this._createEntity(this._currentItem,t);this._layer.add(e)}},this._layer=e.layer||null,this._currentItem=null,this._collection=new ln({collection:e.collection}),this._dialog=new Lh({model:this._collection})}oninit(){this.renderer&&(this._dialog.appendTo(this.renderer.div||document.body),this._dialog.events.on("select",this._onSelect),this.activate())}onactivate(){this._dialog.show(),this._initEvents()}ondeactivate(){this._dialog.hide(),this._clearEvents()}bindLayer(e){this._layer=e}_initEvents(){this.planet&&this.planet.renderer&&this.planet.renderer.events.on("lclick",this._onClick)}_clearEvents(){this.planet&&this.planet.renderer&&this.planet.renderer.events.off("lclick",this._onClick)}_createEntity(e,t){let i=e.name,s=e.scale,r=new G({lonlat:t,pitch:0,yaw:0,roll:0,scale:s});for(let t=0;t<e.objects.length;t++){let s=e.objects[t],n=new G({forceGlobalPosition:!0,forceGlobalRotation:!0,forceGlobalScale:!0,geoObject:{tag:`${i}:${t.toString()}`,object3d:s}});r.appendChild(n)}return r}},OldMouseNavigation:rn,Ruler:_a,RulerSwitcher:class extends Q{constructor(e={}){super({name:"RulerSwitcher",...e}),this.ruler=new Hn({ignoreTerrain:e.ignoreTerrain})}oninit(){this.planet.addControl(this.ruler),this._createMenuBtn()}onactivate(){this.ruler.activate()}ondeactivate(){this.ruler.deactivate()}_createMenuBtn(){let e=new dt({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:fa,Selection:class extends Q{constructor(e={}){super(e),this._selectorScene=new Dl({name:`selectionScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain,onSelect:e.onSelect,autoSelectionHide:e.autoSelectionHide}),this._toggleBtn=new dt({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 Q{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(){Ro("ogShowFpsControl",(1e3/this.renderer.handler.deltaTime).toFixed(1),this.renderer.handler.canvas.clientWidth-60,0)}},SimpleNavigation:class extends Q{constructor(e={}){super({name:"SimpleNavigation",autoActivate:!0,...e}),this.focusVel=0,this.focusForce=0,this._nx=0,this._ny=0,this._onMouseLeftButtonDown=e=>{if(this._active&&this.renderer){if(this.stop(),this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this._grabbedPoint=this.renderer.getCartesianFromPixel(e),this._grabbedScreenPoint.set(e.nx,e.ny),!this._grabbedPoint){let t=this.renderer.activeCamera,i=new v,s=new v(1,0,0),r=new v(0,0,1),n=new v;new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(i,s,r),n)===V.INSIDE&&(this._grabbedPoint=n)}this._grabbedPoint&&this._eye0.copy(this.renderer.activeCamera.eye)}},this._onMouseLeftButtonUp=e=>{this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.x===e.prev_x&&(e.y,e.prev_y)},this._onMouseLeftButtonHold=e=>{if(this.renderer&&this._grabbedPoint&&e.moving){let t=this.renderer.activeCamera;if(t.isOrthographic){let i=e.nx-this._grabbedScreenPoint.x,s=e.ny-this._grabbedScreenPoint.y,r=t.frustum,n=-(r.right-r.left)*i,o=(r.top-r.bottom)*s,a=t.getUp().scale(o),l=t.getRight().scale(n);t.eye=this._eye0.add(l.add(a))}else{let i,s,r=Math.abs(t.getForward().dot(v.UP)),n=this._grabbedPoint;r>.7?(i=v.add(n,v.LEFT),s=v.add(n,t.getRight())):(i=v.add(n,t.getRight()),s=v.add(n,v.UP));let o=new v;new V(t.eye,e.direction).hitPlaneRes(vt.fromPoints(n,i,s),o)===V.INSIDE&&(t.eye=t.eye.add(n.sub(o)))}t.update()}},this._onRHold=e=>{if(this._lookPos&&e.moving&&this.renderer){const t=this.renderer.activeCamera;this.renderer.controlsBag.scaleRot=1;let i=.5/t.eye.distance(this._lookPos)*j;i>.007?i=.007:i<.003&&(i=.003),t.rotateHorizontal(i*(e.x-e.prev_x),!1,this._lookPos,this._up),t.rotateVertical(i*(e.y-e.prev_y),this._lookPos),t.update()}},this._onRDown=e=>{if(this.renderer)if(this.stop(),this._lookPos=this.renderer.getCartesianFromPixel(e.pos),this._lookPos)this._up=v.UP;else{const t=this.renderer.activeCamera;let i=new vt(v.ZERO,v.UP),s=new V(t.eye,e.direction);this._lookPos=new v,s.hitPlaneRes(i,this._lookPos),this._up=v.UP}},this._onMouseWheel=e=>{if(this.renderer){let t=this.renderer.activeCamera;if(t.isOrthographic){let i=t.frustums[0],s=-(i.right-i.left)*(.5-e.nx),r=(i.top-i.bottom)*(.5-e.ny),n=t.getUp().scale(r),o=t.getRight().scale(s),a=t.eye.add(o.add(n));this._wheelPos=a.add(t.getForward()),this._wheelDist=1,this._nx=e.nx,this._ny=e.ny,this.focusForce=.05*e.wheelDelta}else{let i=this.renderer.getCartesianFromPixel(e);if(!i){i=new v;let s=new vt(v.ZERO,v.UP);new V(t.eye,e.direction).hitPlaneRes(s,i)}let s=i.sub(t.eye).normalize(),r=8*t.eye.distance(i);this.force.addA(s.scale(e.wheelDelta)).normalize().scale(r)}}},this.onCameraMoveForward=()=>{this.force.addA(this.renderer.activeCamera.getForward()).normalize()},this.onCameraMoveBackward=()=>{this.force.addA(this.renderer.activeCamera.getBackward()).normalize()},this.onCameraStrifeLeft=()=>{this.force.addA(this.renderer.activeCamera.getLeft()).normalize()},this.onCameraStrifeRight=()=>{this.force.addA(this.renderer.activeCamera.getRight()).normalize()},this.onCameraLookUp=()=>{this.renderer.activeCamera.update()},this.onCameraLookDown=()=>{this.renderer.activeCamera.update()},this.onCameraTurnLeft=()=>{this.renderer.activeCamera.update()},this.onCameraTurnRight=()=>{this.renderer.activeCamera.update()},this.onCameraRollLeft=()=>{this.renderer.activeCamera.update()},this.onCameraRollRight=()=>{this.renderer.activeCamera.update()},this.speed=e.speed||1,this.force=new v,this.vel=new v,this.mass=1,this._lookPos=void 0,this._grabbedPoint=void 0,this._grabbedScreenPoint=new H,this._up=null,this._eye0=new v,this._wheelDist=0,this._wheelPos=new v}oninit(){}onactivate(){super.onactivate();let e=this.renderer;e.activeCamera.isOrthographic&&e.getDepthMinDistanceAsync().then((t=>{e.activeCamera.focusDistance=t})),e.events.on("mousewheel",this._onMouseWheel),e.events.on("keypress",W.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",W.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",W.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",W.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",W.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",W.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",W.KEY_LEFT,this.onCameraTurnLeft,this),e.events.on("keypress",W.KEY_RIGHT,this.onCameraTurnRight,this),e.events.on("keypress",W.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",W.KEY_E,this.onCameraRollRight,this),e.events.on("rhold",this._onRHold,this),e.events.on("rdown",this._onRDown,this),e.events.on("lhold",this._onMouseLeftButtonHold),e.events.on("ldown",this._onMouseLeftButtonDown),e.events.on("lup",this._onMouseLeftButtonUp),e.events.on("draw",this.onDraw,this,-1e3)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("mousewheel",this._onMouseWheel),e.events.off("keypress",W.KEY_W,this.onCameraMoveForward),e.events.off("keypress",W.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",W.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",W.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",W.KEY_UP,this.onCameraLookUp),e.events.off("keypress",W.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",W.KEY_LEFT,this.onCameraTurnLeft),e.events.off("keypress",W.KEY_RIGHT,this.onCameraTurnRight),e.events.off("keypress",W.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",W.KEY_E,this.onCameraRollRight),e.events.off("rhold",this._onRHold),e.events.off("rdown",this._onRDown),e.events.off("lhold",this._onMouseLeftButtonHold),e.events.off("ldown",this._onMouseLeftButtonDown),e.events.off("lup",this._onMouseLeftButtonUp),e.events.off("draw",this.onDraw)}_handleMouseWheel(){let e=this.renderer.activeCamera;if(e.isOrthographic&&Math.abs(this.focusVel)>.01){e.eye=this._wheelPos.add(e.getBackward().scale(this._wheelDist)),e.focusDistance-=e.focusDistance*this.focusVel*this.dt;let t=e.frustums[0],i=(t.right-t.left)*(.5-this._nx),s=-(t.top-t.bottom)*(.5-this._ny),r=e.getUp().scale(s),n=e.getRight().scale(i);e.eye.addA(n.add(r)),e.update()}else this.vel.length()>.01&&(e.eye=e.eye.add(this.vel.scaleTo(this.dt)),e.update())}onDraw(){this._updateVel(),this._handleMouseWheel()}get dt(){return.001*this.renderer.handler.deltaTime}_updateVel(){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(.77),this.force.set(0,0,0),this.focusVel+=this.focusForce,this.focusVel*=.77,this.focusForce=0}stop(){this.focusVel=0,this.vel.clear()}},SimpleSkyBackground:ga,Sun:Dr,TimelineControl:class extends Q{constructor(e={}){super({name:"timeline",...e});let t=e.current||new Date,i=e.rangeStart||jn(t,-12),s=e.rangeEnd||jn(t,12);this._timelineView=new jl({rangeStart:i,rangeEnd:s,currentDate:t}),this._toggleBtn=new dt({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 Kt({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",(()=>{var e;null==(e=this.planet)||e.sun.stop(),this.renderer&&this.renderer.controls.navigation.deactivate()})),this._timelineView.events.on("stopdrag",(()=>{this.renderer&&this.renderer.controls.navigation.activate()})),this._timelineView.events.on("startdragcurrent",(()=>{var e;null==(e=this.planet)||e.sun.stop(),this.renderer&&this.renderer.controls.navigation.deactivate()})),this._timelineView.events.on("stopdragcurrent",(()=>{this.renderer&&this.renderer.controls.navigation.activate()}))}},ToggleWireframe:class extends Q{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",W.KEY_X,this.toogleWireframe,this),this._isActive&&this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP)}},TouchNavigation:pa,ZoomControl:ma},Symbol.toStringTag,{value:"Module"}));function Ke(e){return new Uint32Array(e)}function kh(e){let t=[],i=0,s=0,r=0;for(let n=1;n<e-1-1;n++){for(let o=1;o<e-1;o++)i=n*e+o,r=(n+1)*e,s=r+o,t.push(i,s);t.push(s,r+1)}return t.push(t[t.length-1],e*e-e),Ke(t)}function Ih(e,t){let i=[];const s=(e-1)/t,r=e*e-e;let n=0;for(let t=0;t<e-2;t++){t%s==0&&(n=t);let o=r-e*t-e+1,a=r-e*n;i.push(a,o)}return t===e-1&&(i.push(e),i.push(0)),Ke(i)}function zh(e,t){let i=[];const s=(e-1)/t;let r=0;for(let t=0;t<e-2;t++){t%s==0&&(r=t);let n=e+t+1,o=r;i.push(o,n)}return t===e-1&&(i.push(e-2),i.push(e-1)),Ke(i)}function Dh(e,t){let i=[];const s=(e-1)/t;let r=0;for(let t=0;t<e-2;t++){t%s==0&&(r=t);let n=e*(t+1)+e-2,o=e+e*r-1;i.push(o,n)}return t===e-1&&(i.push(e*(e-1)-1),i.push(e*e-1)),Ke(i)}function Fh(e,t){let i=[];const s=(e-1)/t;let r=0;const n=e*(e-1)-2,o=e*e-1;for(let t=0;t<e-2;t++){t%s==0&&(r=t);let e=n-t,a=o-r;i.push(a,e)}return t===e-1&&i.push(e*e-e+1),i.push(e*e-e),Ke(i)}function no(e){let t=[[],[],[],[]];for(let i=0;i<=e;i++){let s=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]=Ih(s,e),t[0][i][r]=zh(s,e),t[1][i][r]=Dh(s,e),t[2][i][r]=Fh(s,e)}}return t}function oo(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=kh(e+1)}return t}function Oh(e){let t=new Uint16Array((e+1)*(e+1)*2),i=0;for(let s=0;s<=e;s++)for(let r=0;r<=e;r++)t[i++]=r/e*65535,t[i++]=s/e*65535;return t}let Nh=new class{constructor(e=0){this._maxGridSize=e,this.centerIndexesTable=oo(this._maxGridSize),this.skirtsIndexesTable=no(this._maxGridSize)}get maxGridSize(){return this._maxGridSize}init(){this.centerIndexesTable=oo(this._maxGridSize),this.skirtsIndexesTable=no(this._maxGridSize)}setMaxGridSize(e){this._maxGridSize=e,this.init()}createSegmentIndexes(e,t){if(e){let s=this.centerIndexesTable[e],r=this.skirtsIndexesTable[3][e][t[3]],n=this.skirtsIndexesTable[0][e][t[0]],o=this.skirtsIndexesTable[1][e][t[1]],a=this.skirtsIndexesTable[2][e][t[2]],l=(i=s.length+r.length+n.length+o.length+a.length,new Uint32Array(i));return l.set(s,0),l.set(r,s.length),l.set(n,s.length+r.length),l.set(o,s.length+r.length+n.length),l.set(a,s.length+r.length+n.length+o.length),l}var i;return Ke([0,2,1,3])}initTextureCoordsTable(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=Oh(e)}return t}};function $i(){return Nh}function ao(){return new X("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",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"attribute vec3 aVertexPositionHigh;attribute vec3 aVertexPositionLow;attribute vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec4 uGlobalTextureCoord;uniform vec3 uNormalMapBias;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;varying vec4 vTextureCoord;varying vec3 v_vertex;varying vec3 cameraPosition;varying vec2 vGlobalTextureCoord;varying float v_height;void main(void){vec3 aVertexPosition=aVertexPositionHigh+aVertexPositionLow;vec3 nh=height*normalize(aVertexPosition);vTextureCoord.xy=aTextureCoord;vGlobalTextureCoord=uGlobalTextureCoord.xy+(uGlobalTextureCoord.zw-uGlobalTextureCoord.xy)*aTextureCoord;vTextureCoord.zw=uNormalMapBias.z*(aTextureCoord+uNormalMapBias.xy);cameraPosition=eyePositionHigh+eyePositionLow;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);v_height=height;v_vertex=aVertexPosition+nh;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"precision highp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<-1e-6){return false;}d=max(d,0.0);t1=-b-sqrt(d);t2=-b+sqrt(d);if(t2<0.0){return false;}return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);uniform vec4 specular;uniform vec3 diffuse;uniform vec3 ambient;uniform sampler2D uNormalMap;uniform sampler2D nightTexture;uniform sampler2D specularTexture;uniform sampler2D defaultTexture;uniform sampler2D samplerArr[SLICE_SIZE];uniform vec4 tileOffsetArr[SLICE_SIZE];uniform vec3 lightPosition;uniform float layerOpacityArr[SLICE_SIZE];uniform int samplerCount;uniform float nightTextureCoefficient;uniform float camHeight;varying vec4 vTextureCoord;varying vec3 v_vertex;varying vec3 cameraPosition;varying vec2 vGlobalTextureCoord;varying float v_height;vec3 sunPos;void main(void){sunPos=lightPosition;vec3 texNormal=texture2D(uNormalMap,vTextureCoord.zw).rgb;vec3 normal=normalize((texNormal-0.5)*2.0);float minH=1200000.0;float maxH=minH*3.0;float nightCoef=getLerpValue(minH,maxH,camHeight)*nightTextureCoefficient;vec3 lightDir=normalize(sunPos);vec3 viewDir=normalize(cameraPosition-v_vertex);float overGround=1.0-step(0.1,v_height);float shininess=texture2D(specularTexture,vGlobalTextureCoord.st).r*255.0*overGround;vec3 reflectionDirection=reflect(-lightDir,normal);float reflection=max(dot(reflectionDirection,viewDir),0.0);vec3 spec=specular.rgb*pow(reflection,specular.w)*shininess;float diffuseLightWeighting=max(dot(normal,lightDir),0.0);vec4 nightImageColor=texture2D(nightTexture,vGlobalTextureCoord.st);vec3 night=nightStep*(.18-diffuseLightWeighting*3.0)*nightImageColor.rgb*nightCoef;night*=overGround*step(0.0,night);vec4 lightWeighting=vec4(ambient+diffuse*diffuseLightWeighting+night,1.0);gl_FragColor=texture2D(defaultTexture,vTextureCoord.xy);if(samplerCount==0){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}vec4 src;blend(gl_FragColor,samplerArr[0],tileOffsetArr[0],layerOpacityArr[0]);if(samplerCount==1){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}blend(gl_FragColor,samplerArr[1],tileOffsetArr[1],layerOpacityArr[1]);if(samplerCount==2){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}blend(gl_FragColor,samplerArr[2],tileOffsetArr[2],layerOpacityArr[2]);if(samplerCount==3){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}blend(gl_FragColor,samplerArr[3],tileOffsetArr[3],layerOpacityArr[3]);if(samplerCount==4){gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);return;}blend(gl_FragColor,samplerArr[4],tileOffsetArr[4],layerOpacityArr[4]);gl_FragColor=gl_FragColor*lightWeighting+vec4(spec,0.0);}"})}function lo(e){return new X("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",lightPosition:"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\nprecision highp float;in vec3 aVertexPositionHigh;in vec3 aVertexPositionLow;in vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec4 uGlobalTextureCoord;uniform vec3 uNormalMapBias;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;out vec4 vTextureCoord;out vec3 v_vertex;out vec3 cameraPosition;out vec2 vGlobalTextureCoord;out float v_height;void main(void){vec3 aVertexPosition=aVertexPositionHigh+aVertexPositionLow;vec3 nh=height*normalize(aVertexPosition);vTextureCoord.xy=aTextureCoord;vGlobalTextureCoord=uGlobalTextureCoord.xy+(uGlobalTextureCoord.zw-uGlobalTextureCoord.xy)*aTextureCoord;vTextureCoord.zw=uNormalMapBias.z*(aTextureCoord+uNormalMapBias.xy);cameraPosition=eyePositionHigh+eyePositionLow;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);v_height=height;v_vertex=aVertexPosition+nh;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:di("#version 300 es\nprecision highp float;\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<-1e-6){return false;}d=max(d,0.0);t1=-b-sqrt(d);t2=-b+sqrt(d);if(t2<0.0){return false;}return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#define PI 3.1415926538\n#define ATMOS_HEIGHT float(${ATMOS_HEIGHT})\n#define RAYLEIGH_SCALE float(${RAYLEIGH_SCALE})\n#define MIE_SCALE float(${MIE_SCALE})\n#define SAMPLE_COUNT 16\n#define SQRT_SAMPLE_COUNT 4\nconst float GROUND_ALBEDO=float(${GROUND_ALBEDO})/PI;const float BOTTOM_RADIUS=float(${BOTTOM_RADIUS});const float TOP_RADIUS=BOTTOM_RADIUS+ATMOS_HEIGHT;const float EQUATORIAL_RADIUS=float(${EQUATORIAL_RADIUS});const vec3 bottomRadii=vec3(EQUATORIAL_RADIUS,EQUATORIAL_RADIUS,BOTTOM_RADIUS);const vec3 topRadii=bottomRadii+ATMOS_HEIGHT;const vec3 SPHERE_TO_ELLIPSOID_SCALE=vec3(BOTTOM_RADIUS)/bottomRadii;const vec2 rayleighMieHeights=vec2(RAYLEIGH_SCALE,MIE_SCALE)*ATMOS_HEIGHT;const vec3 rayleighScatteringCoefficient=vec3(float(${rayleighScatteringCoefficient_0}),float(${rayleighScatteringCoefficient_1}),float(${rayleighScatteringCoefficient_2}))*1e-6;const float mieScatteringCoefficient=float(${mieScatteringCoefficient})*1e-6;const float mieExtinctionCoefficient=float(${mieExtinctionCoefficient})*1e-6;const vec3 ozoneAbsorptionCoefficient=vec3(float(${ozoneAbsorptionCoefficient_0}),float(${ozoneAbsorptionCoefficient_1}),float(${ozoneAbsorptionCoefficient_2}))*1e-6;const float SUN_ANGULAR_RADIUS=float(${SUN_ANGULAR_RADIUS});const float SUN_INTENSITY=float(${SUN_INTENSITY});const float ozoneDensityHeight=float(${ozoneDensityHeight});const float ozoneDensityWide=float(${ozoneDensityWide});vec3 sunWithBloom(vec3 rayDir,vec3 sunDir){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}vec3 sunWithBloomScaled(vec3 rayDir,vec3 sunDir,float angularScale){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS*angularScale);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}float rayleighPhase(float angle){return 3.0/(16.0*PI)*(1.0+(angle*angle));}float miePhase(float angle){float g=0.8;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));}vec3 opticalDepth(float height,float angle){vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 rayDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);float t1,t2;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,t1,t2);float segmentLength=t2/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 opticalDepth=vec3(0.0);for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;opticalDepth.xy+=exp(-height/rayleighMieHeights)*segmentLength;opticalDepth.z+=(1.0-min(abs(height-ozoneDensityHeight)/ozoneDensityWide,1.0))*segmentLength;t+=segmentLength;}return opticalDepth;}vec3 transmittance(float height,float angle){vec3 opticalDepth=opticalDepth(height,angle);return exp(-(rayleighScatteringCoefficient*opticalDepth.x+mieExtinctionCoefficient*opticalDepth.y+ozoneAbsorptionCoefficient*opticalDepth.z));}uniform vec4 specular;uniform vec3 diffuse;uniform vec3 ambient;uniform vec3 lightPosition;uniform sampler2D uNormalMap;uniform sampler2D nightTexture;uniform sampler2D specularTexture;uniform sampler2D transmittanceTexture;uniform sampler2D scatteringTexture;uniform sampler2D defaultTexture;uniform sampler2D samplerArr[SLICE_SIZE];uniform vec4 tileOffsetArr[SLICE_SIZE];uniform float layerOpacityArr[SLICE_SIZE];uniform int samplerCount;uniform float nightTextureCoefficient;uniform vec2 maxMinOpacity;uniform float camHeight;uniform float transitionOpacity;in vec4 vTextureCoord;in vec3 v_vertex;in vec3 cameraPosition;in vec2 vGlobalTextureCoord;in float v_height;vec3 sunPos;layout(location=0)out vec4 diffuseColor;vec3 transmittanceFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture(transmittanceTexture,vec2(u,v)).xyz;}vec3 multipleScatteringContributionFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture(scatteringTexture,vec2(u,v)).xyz;}void getSunIlluminance(in vec3 point,in vec3 lightDir,out vec3 sunIlluminance){float mu_s=dot(normalize(point),lightDir);float height=length(point)-BOTTOM_RADIUS;sunIlluminance=SUN_INTENSITY*transmittanceFromTexture(height,mu_s);}void atmosGroundColor(out vec4 fragColor,in vec3 normal){vec3 cameraPosition=cameraPosition;if(length(cameraPosition*SPHERE_TO_ELLIPSOID_SCALE)<BOTTOM_RADIUS+1.0){cameraPosition=normalize(cameraPosition*SPHERE_TO_ELLIPSOID_SCALE)*(BOTTOM_RADIUS+1.0)/SPHERE_TO_ELLIPSOID_SCALE;}vec3 rayDirection=normalize(v_vertex-cameraPosition);vec3 lightDir=normalize(sunPos);rayDirection=normalize(rayDirection*SPHERE_TO_ELLIPSOID_SCALE);vec3 camPos=cameraPosition*SPHERE_TO_ELLIPSOID_SCALE;lightDir=normalize(lightDir*SPHERE_TO_ELLIPSOID_SCALE);vec3 light=vec3(0.0);vec3 transmittanceFromCameraToSpace=vec3(1.0);float offset=0.0;float distanceToSpace=0.0;intersectSphere(camPos,rayDirection,TOP_RADIUS,offset,distanceToSpace);vec3 rayOrigin=camPos;if(offset>0.0){rayOrigin+=rayDirection*offset;}float height=length(rayOrigin)-BOTTOM_RADIUS;float rayAngle=dot(rayOrigin,rayDirection)/length(rayOrigin);bool cameraBelow=rayAngle<0.0;transmittanceFromCameraToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);float phaseAngle=dot(lightDir,rayDirection);float rayleighPhase=rayleighPhase(phaseAngle);float miePhase=miePhase(phaseAngle);float distanceToGround=0.0;bool hitGround=intersectSphere(camPos,rayDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>0.0;if(length(v_vertex*SPHERE_TO_ELLIPSOID_SCALE)>BOTTOM_RADIUS){distanceToGround=distance(camPos,v_vertex*SPHERE_TO_ELLIPSOID_SCALE);}float segmentLength=(distanceToGround-max(offset,0.0))/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 transmittanceCamera;vec3 transmittanceLight;for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;vec3 up=position/length(position);float rayAngle=dot(up,rayDirection);float lightAngle=dot(up,lightDir);vec3 transmittanceToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);transmittanceCamera=cameraBelow ?(transmittanceToSpace/transmittanceFromCameraToSpace):(transmittanceFromCameraToSpace/transmittanceToSpace);transmittanceLight=transmittanceFromTexture(height,lightAngle);vec2 opticalDensity=exp(-height/rayleighMieHeights);vec3 scatteredLight=transmittanceLight*(rayleighScatteringCoefficient*opticalDensity.x*rayleighPhase+mieScatteringCoefficient*opticalDensity.y*miePhase);scatteredLight+=multipleScatteringContributionFromTexture(height,lightAngle)*(rayleighScatteringCoefficient*opticalDensity.x+mieScatteringCoefficient*opticalDensity.y);light+=transmittanceCamera*scatteredLight*segmentLength;t+=segmentLength;}light*=SUN_INTENSITY;vec3 hitPoint=camPos+rayDirection*distanceToGround;vec3 up=normalize(hitPoint);float diffuseAngle=max(dot(up,lightDir),0.0);float lightAngle=dot(normal,lightDir);vec3 tA=transmittanceCamera*GROUND_ALBEDO*SUN_INTENSITY;vec3 scatteringLight=multipleScatteringContributionFromTexture(height,lightAngle);vec3 diffuseTransmittanceLight=transmittanceLight*diffuseAngle;light+=tA*(scatteringLight+diffuseTransmittanceLight);fragColor=vec4(pow(light*8.0,vec3(1.0/2.2)),1.0);}void getAtmosFadingOpacity(out float opacity){float c=length(cameraPosition);float maxDist=sqrt(c*c-BOTTOM_RADIUS*BOTTOM_RADIUS);float minDist=c-BOTTOM_RADIUS;float vertDist=distance(cameraPosition,v_vertex);opacity=clamp(maxMinOpacity.y+(maxMinOpacity.x-maxMinOpacity.y)*getLerpValue(minDist,maxDist,vertDist),0.0,1.0);}void main(void){sunPos=lightPosition;vec3 texNormal=texture(uNormalMap,vTextureCoord.zw).rgb;vec3 normal=normalize((texNormal-0.5)*2.0);float minH=1200000.0;float maxH=minH*3.0;float nightCoef=getLerpValue(minH,maxH,camHeight)*nightTextureCoefficient;vec3 lightDir=normalize(sunPos);vec3 viewDir=normalize(cameraPosition-v_vertex);vec4 atmosColor;atmosGroundColor(atmosColor,normal);vec3 sunIlluminance;getSunIlluminance(v_vertex*SPHERE_TO_ELLIPSOID_SCALE,lightDir*SPHERE_TO_ELLIPSOID_SCALE,sunIlluminance);float overGround=1.0-step(0.1,v_height);float shininess=texture(specularTexture,vGlobalTextureCoord.st).r*255.0*overGround;vec3 reflectionDirection=reflect(-lightDir,normal);float reflection=max(dot(reflectionDirection,viewDir),0.0);vec3 spec=sunIlluminance*specular.rgb*pow(reflection,specular.w)*shininess;float diffuseLightWeighting=max(dot(normal,lightDir),0.0);vec4 nightImageColor=texture(nightTexture,vGlobalTextureCoord.st);vec3 night=nightStep*(.18-diffuseLightWeighting*3.0)*nightImageColor.rgb*nightCoef;night*=overGround*step(0.0,night);vec4 lightWeighting=vec4(ambient+sunIlluminance*diffuse*diffuseLightWeighting+night,1.0);float fadingOpacity;getAtmosFadingOpacity(fadingOpacity);getSunIlluminance(cameraPosition,viewDir*SPHERE_TO_ELLIPSOID_SCALE,sunIlluminance);spec*=sunIlluminance;diffuseColor=texture(defaultTexture,vTextureCoord.xy);if(samplerCount==0){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}vec4 src;blend(diffuseColor,samplerArr[0],tileOffsetArr[0],layerOpacityArr[0]);if(samplerCount==1){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[1],tileOffsetArr[1],layerOpacityArr[1]);if(samplerCount==2){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[2],tileOffsetArr[2],layerOpacityArr[2]);if(samplerCount==3){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[3],tileOffsetArr[3],layerOpacityArr[3]);if(samplerCount==4){diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[4],tileOffsetArr[4],layerOpacityArr[4]);diffuseColor=mix(diffuseColor*lightWeighting,atmosColor*diffuseColor.a,fadingOpacity)+vec4(spec,0.0);diffuseColor*=transitionOpacity;}",e)})}const er={ATMOS_HEIGHT:1e5,RAYLEIGH_SCALE:.08,MIE_SCALE:.012,GROUND_ALBEDO:.05,BOTTOM_RADIUS:6356752.314245179,EQUATORIAL_RADIUS:6378137,rayleighScatteringCoefficient_0:5.802,rayleighScatteringCoefficient_1:13.558,rayleighScatteringCoefficient_2:33.1,mieScatteringCoefficient:3.996,mieExtinctionCoefficient:4.44,ozoneAbsorptionCoefficient_0:.65,ozoneAbsorptionCoefficient_1:1.881,ozoneAbsorptionCoefficient_2:.085,SUN_ANGULAR_RADIUS:.004685,SUN_INTENSITY:1,ozoneDensityHeight:25e3,ozoneDensityWide:15e3,disableSunDisk:!1};var Hh="attribute vec2 corners;void main(void){gl_Position=vec4(corners,0.0,1.0);}",Vh="precision lowp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<-1e-6){return false;}d=max(d,0.0);t1=-b-sqrt(d);t2=-b+sqrt(d);if(t2<0.0){return false;}return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#define PI 3.1415926538\n#define ATMOS_HEIGHT float(${ATMOS_HEIGHT})\n#define RAYLEIGH_SCALE float(${RAYLEIGH_SCALE})\n#define MIE_SCALE float(${MIE_SCALE})\n#define SAMPLE_COUNT 16\n#define SQRT_SAMPLE_COUNT 4\nconst float GROUND_ALBEDO=float(${GROUND_ALBEDO})/PI;const float BOTTOM_RADIUS=float(${BOTTOM_RADIUS});const float TOP_RADIUS=BOTTOM_RADIUS+ATMOS_HEIGHT;const float EQUATORIAL_RADIUS=float(${EQUATORIAL_RADIUS});const vec3 bottomRadii=vec3(EQUATORIAL_RADIUS,EQUATORIAL_RADIUS,BOTTOM_RADIUS);const vec3 topRadii=bottomRadii+ATMOS_HEIGHT;const vec3 SPHERE_TO_ELLIPSOID_SCALE=vec3(BOTTOM_RADIUS)/bottomRadii;const vec2 rayleighMieHeights=vec2(RAYLEIGH_SCALE,MIE_SCALE)*ATMOS_HEIGHT;const vec3 rayleighScatteringCoefficient=vec3(float(${rayleighScatteringCoefficient_0}),float(${rayleighScatteringCoefficient_1}),float(${rayleighScatteringCoefficient_2}))*1e-6;const float mieScatteringCoefficient=float(${mieScatteringCoefficient})*1e-6;const float mieExtinctionCoefficient=float(${mieExtinctionCoefficient})*1e-6;const vec3 ozoneAbsorptionCoefficient=vec3(float(${ozoneAbsorptionCoefficient_0}),float(${ozoneAbsorptionCoefficient_1}),float(${ozoneAbsorptionCoefficient_2}))*1e-6;const float SUN_ANGULAR_RADIUS=float(${SUN_ANGULAR_RADIUS});const float SUN_INTENSITY=float(${SUN_INTENSITY});const float ozoneDensityHeight=float(${ozoneDensityHeight});const float ozoneDensityWide=float(${ozoneDensityWide});vec3 sunWithBloom(vec3 rayDir,vec3 sunDir){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}vec3 sunWithBloomScaled(vec3 rayDir,vec3 sunDir,float angularScale){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS*angularScale);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}float rayleighPhase(float angle){return 3.0/(16.0*PI)*(1.0+(angle*angle));}float miePhase(float angle){float g=0.8;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));}vec3 opticalDepth(float height,float angle){vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 rayDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);float t1,t2;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,t1,t2);float segmentLength=t2/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 opticalDepth=vec3(0.0);for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;opticalDepth.xy+=exp(-height/rayleighMieHeights)*segmentLength;opticalDepth.z+=(1.0-min(abs(height-ozoneDensityHeight)/ozoneDensityWide,1.0))*segmentLength;t+=segmentLength;}return opticalDepth;}vec3 transmittance(float height,float angle){vec3 opticalDepth=opticalDepth(height,angle);return exp(-(rayleighScatteringCoefficient*opticalDepth.x+mieExtinctionCoefficient*opticalDepth.y+ozoneAbsorptionCoefficient*opticalDepth.z));}\n#define DISABLE_SUN_DISK ${ disableSunDisk }\nuniform mat4 viewMatrix;uniform vec3 sunPos;uniform vec3 camPos;uniform vec2 iResolution;uniform float fov;uniform float opacity;uniform float isOrthographic;uniform vec4 frustumParams;uniform sampler2D transmittanceTexture;uniform sampler2D scatteringTexture;float valueHSV(vec3 rgb){return max(max(rgb.r,rgb.g),rgb.b);}vec3 transmittanceFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture2D(transmittanceTexture,vec2(u,v)).xyz;}vec3 multipleScatteringContributionFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture2D(scatteringTexture,vec2(u,v)).xyz;}bool intersectEllipsoidToSphere(in vec3 ro,in vec3 rd,in vec3 ellRadii,in float sphereRadius,out float t1,out float t2){float offset=0.0,distanceToSpace=0.0;if(intersectEllipsoid(ro,rd,ellRadii,offset,distanceToSpace)){vec3 hitEll=ro+rd*offset;vec3 nEll=normalEllipsoid(hitEll,ellRadii);float t=0.0;bool intersectsSphere=intersectSphere(hitEll,nEll,sphereRadius,t);vec3 hitSphere=hitEll+nEll*t;t1=length(hitSphere-ro);hitEll=ro+rd*distanceToSpace;nEll=normalEllipsoid(hitEll,ellRadii);t=0.0;intersectsSphere=intersectSphere(hitEll,nEll,sphereRadius,t);hitSphere=hitEll+nEll*t;t2=length(hitSphere-ro);return true;}return false;}mat4 transpose(in mat4 m){vec4 i0=m[0];vec4 i1=m[1];vec4 i2=m[2];vec4 i3=m[3];mat4 outMatrix=mat4(vec4(i0.x,i1.x,i2.x,i3.x),vec4(i0.y,i1.y,i2.y,i3.y),vec4(i0.z,i1.z,i2.z,i3.z),vec4(i0.w,i1.w,i2.w,i3.w));return outMatrix;}void mainImage(out vec4 fragColor){vec3 cameraPosition=camPos;vec3 lightDirection=normalize(sunPos);vec2 uv=(2.0*gl_FragCoord.xy-iResolution.xy)/iResolution.y;vec3 rayDirection;if(isOrthographic!=0.0){float px=uv.x*iResolution.y/iResolution.x;float py=uv.y;float dx=0.5*frustumParams.x*px;float dy=0.5*frustumParams.y*py;mat4 viewMatrixT=transpose(viewMatrix);vec3 right=normalize(viewMatrixT[0].xyz);vec3 up=normalize(viewMatrixT[1].xyz);vec3 backward=normalize(viewMatrixT[2].xyz);vec3 forward=-backward;rayDirection=forward;cameraPosition=cameraPosition+right*dx+up*dy;}else{float fieldOfView=fov;float z=1.0/tan(fieldOfView*0.5*PI/180.0);rayDirection=normalize(vec3(uv,-z));vec4 rd=transpose(viewMatrix)*vec4(rayDirection,1.0);rayDirection=rd.xyz;}vec3 light=vec3(0.0);vec3 transmittanceFromCameraToSpace=vec3(1.0);float offset=0.0;float distanceToSpace=0.0;rayDirection=normalize(rayDirection*SPHERE_TO_ELLIPSOID_SCALE);cameraPosition*=SPHERE_TO_ELLIPSOID_SCALE;lightDirection=normalize(lightDirection*SPHERE_TO_ELLIPSOID_SCALE);if(length(cameraPosition)<BOTTOM_RADIUS+100.0){cameraPosition=normalize(cameraPosition)*(BOTTOM_RADIUS+100.0);}if(intersectSphere(cameraPosition,rayDirection,TOP_RADIUS,offset,distanceToSpace)){vec3 rayOrigin=cameraPosition;if(offset>0.0){rayOrigin=cameraPosition+rayDirection*offset;}float height=length(rayOrigin)-BOTTOM_RADIUS;float rayAngle=dot(rayOrigin,rayDirection)/length(rayOrigin);bool cameraBelow=rayAngle<0.0;transmittanceFromCameraToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);float phaseAngle=dot(lightDirection,rayDirection);float rayleighPhase=rayleighPhase(phaseAngle);float miePhase=miePhase(phaseAngle);float distanceToGround=0.0;bool hitGround=intersectSphere(cameraPosition,rayDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>0.0;if(intersectSphere(cameraPosition,rayDirection,BOTTOM_RADIUS-100000.0,distanceToGround)&&hitGround){fragColor=vec4(0.47,0.47,0.5,1.0);return;}float segmentLength=abs(((hitGround ? distanceToGround : distanceToSpace)-max(offset,0.0))/float(SAMPLE_COUNT));float t=segmentLength*0.5;vec3 transmittanceCamera;vec3 transmittanceLight;for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;vec3 up=position/length(position);float rayAngle=dot(up,rayDirection);float lightAngle=dot(up,lightDirection);vec3 transmittanceToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);transmittanceCamera=cameraBelow ?(transmittanceToSpace/transmittanceFromCameraToSpace):(transmittanceFromCameraToSpace/transmittanceToSpace);transmittanceLight=transmittanceFromTexture(height,lightAngle);vec2 opticalDensity=exp(-height/rayleighMieHeights);vec3 scatteredLight=transmittanceLight*(rayleighScatteringCoefficient*opticalDensity.x*rayleighPhase+mieScatteringCoefficient*opticalDensity.y*miePhase);scatteredLight+=multipleScatteringContributionFromTexture(height,lightAngle)*(rayleighScatteringCoefficient*opticalDensity.x+mieScatteringCoefficient*opticalDensity.y);light+=transmittanceCamera*scatteredLight*segmentLength;t+=segmentLength;}light*=SUN_INTENSITY;if(hitGround){vec3 hitPoint=cameraPosition+rayDirection*distanceToGround;vec3 up=hitPoint/length(hitPoint);float diffuseAngle=max(dot(up,lightDirection),0.0);float lightAngle=dot(up,lightDirection);light+=transmittanceCamera*GROUND_ALBEDO*multipleScatteringContributionFromTexture(height,lightAngle)*SUN_INTENSITY;light+=transmittanceCamera*transmittanceLight*GROUND_ALBEDO*diffuseAngle*SUN_INTENSITY;}}\n#if !DISABLE_SUN_DISK\n{float distanceToGround=0.0;bool hitGround=intersectSphere(cameraPosition,rayDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>0.0;if(!hitGround){vec3 sunLum;if(isOrthographic!=0.0){float z=1.0/tan(fov*0.5*PI/180.0);vec3 viewRay=normalize(vec3(uv,-z));vec4 rd=transpose(viewMatrix)*vec4(viewRay,1.0);vec3 pseudoRayDirection=normalize(rd.xyz);const float sunOrthoAngularScale=2.0;sunLum=sunWithBloomScaled(pseudoRayDirection,lightDirection,sunOrthoAngularScale)*vec3(1.0,1.0,0.8);}else{sunLum=sunWithBloom(rayDirection,lightDirection)*vec3(1.0,1.0,0.8);}sunLum=smoothstep(0.002,1.0,sunLum);light+=sunLum*SUN_INTENSITY*transmittanceFromCameraToSpace;}}\n#endif\nvec4 color=vec4(pow(opacity*light*8.0,vec3(1.0/2.2)),valueHSV(light)*clamp(opacity,0.0,1.0));fragColor=color;}void main(void){mainImage(gl_FragColor);}";class Uh extends Q{constructor(e={}){super({name:"Atmosphere",...e}),this._transmittanceBuffer=null,this._scatteringBuffer=null,this.opacity=1;const t=e;this._parameters=JSON.parse(JSON.stringify({...er,...t}))}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(){var e;null==(e=this.planet)||e.initAtmosphereShader(this._parameters)}oninit(){this.renderer&&(this._initLookupTextures(),this.initLookupTexturesShaders(),this.drawLookupTextures(),this.removeLookupTexturesShaders(),this.initBackgroundShader(),this.activate())}initLookupTexturesShaders(){var e,t;this.renderer&&(this.renderer.handler.addProgram((e=this._parameters,new X("transmittance",{uniforms:{iResolution:"vec2"},attributes:{a_position:"vec2"},vertexShader:"attribute vec2 a_position;void main(void){gl_Position=vec4(a_position,0.0,1.0);}",fragmentShader:di("precision highp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<-1e-6){return false;}d=max(d,0.0);t1=-b-sqrt(d);t2=-b+sqrt(d);if(t2<0.0){return false;}return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#define PI 3.1415926538\n#define ATMOS_HEIGHT float(${ATMOS_HEIGHT})\n#define RAYLEIGH_SCALE float(${RAYLEIGH_SCALE})\n#define MIE_SCALE float(${MIE_SCALE})\n#define SAMPLE_COUNT 16\n#define SQRT_SAMPLE_COUNT 4\nconst float GROUND_ALBEDO=float(${GROUND_ALBEDO})/PI;const float BOTTOM_RADIUS=float(${BOTTOM_RADIUS});const float TOP_RADIUS=BOTTOM_RADIUS+ATMOS_HEIGHT;const float EQUATORIAL_RADIUS=float(${EQUATORIAL_RADIUS});const vec3 bottomRadii=vec3(EQUATORIAL_RADIUS,EQUATORIAL_RADIUS,BOTTOM_RADIUS);const vec3 topRadii=bottomRadii+ATMOS_HEIGHT;const vec3 SPHERE_TO_ELLIPSOID_SCALE=vec3(BOTTOM_RADIUS)/bottomRadii;const vec2 rayleighMieHeights=vec2(RAYLEIGH_SCALE,MIE_SCALE)*ATMOS_HEIGHT;const vec3 rayleighScatteringCoefficient=vec3(float(${rayleighScatteringCoefficient_0}),float(${rayleighScatteringCoefficient_1}),float(${rayleighScatteringCoefficient_2}))*1e-6;const float mieScatteringCoefficient=float(${mieScatteringCoefficient})*1e-6;const float mieExtinctionCoefficient=float(${mieExtinctionCoefficient})*1e-6;const vec3 ozoneAbsorptionCoefficient=vec3(float(${ozoneAbsorptionCoefficient_0}),float(${ozoneAbsorptionCoefficient_1}),float(${ozoneAbsorptionCoefficient_2}))*1e-6;const float SUN_ANGULAR_RADIUS=float(${SUN_ANGULAR_RADIUS});const float SUN_INTENSITY=float(${SUN_INTENSITY});const float ozoneDensityHeight=float(${ozoneDensityHeight});const float ozoneDensityWide=float(${ozoneDensityWide});vec3 sunWithBloom(vec3 rayDir,vec3 sunDir){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}vec3 sunWithBloomScaled(vec3 rayDir,vec3 sunDir,float angularScale){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS*angularScale);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}float rayleighPhase(float angle){return 3.0/(16.0*PI)*(1.0+(angle*angle));}float miePhase(float angle){float g=0.8;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));}vec3 opticalDepth(float height,float angle){vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 rayDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);float t1,t2;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,t1,t2);float segmentLength=t2/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 opticalDepth=vec3(0.0);for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;opticalDepth.xy+=exp(-height/rayleighMieHeights)*segmentLength;opticalDepth.z+=(1.0-min(abs(height-ozoneDensityHeight)/ozoneDensityWide,1.0))*segmentLength;t+=segmentLength;}return opticalDepth;}vec3 transmittance(float height,float angle){vec3 opticalDepth=opticalDepth(height,angle);return exp(-(rayleighScatteringCoefficient*opticalDepth.x+mieExtinctionCoefficient*opticalDepth.y+ozoneAbsorptionCoefficient*opticalDepth.z));}uniform vec2 iResolution;void main(void){vec2 uv=gl_FragCoord.xy/iResolution.xy;float height=uv.y*ATMOS_HEIGHT;float angle=uv.x*2.0-1.0;gl_FragColor=vec4(transmittance(height,angle),1.0);}",e||er)}))),this.renderer.handler.addProgram((t=this._parameters,new X("scattering",{uniforms:{iResolution:"vec2",transmittanceTexture:"sampler2d"},attributes:{a_position:"vec2"},vertexShader:"attribute vec2 a_position;void main(void){gl_Position=vec4(a_position,0.0,1.0);}",fragmentShader:di("precision highp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<-1e-6){return false;}d=max(d,0.0);t1=-b-sqrt(d);t2=-b+sqrt(d);if(t2<0.0){return false;}return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#define PI 3.1415926538\n#define ATMOS_HEIGHT float(${ATMOS_HEIGHT})\n#define RAYLEIGH_SCALE float(${RAYLEIGH_SCALE})\n#define MIE_SCALE float(${MIE_SCALE})\n#define SAMPLE_COUNT 16\n#define SQRT_SAMPLE_COUNT 4\nconst float GROUND_ALBEDO=float(${GROUND_ALBEDO})/PI;const float BOTTOM_RADIUS=float(${BOTTOM_RADIUS});const float TOP_RADIUS=BOTTOM_RADIUS+ATMOS_HEIGHT;const float EQUATORIAL_RADIUS=float(${EQUATORIAL_RADIUS});const vec3 bottomRadii=vec3(EQUATORIAL_RADIUS,EQUATORIAL_RADIUS,BOTTOM_RADIUS);const vec3 topRadii=bottomRadii+ATMOS_HEIGHT;const vec3 SPHERE_TO_ELLIPSOID_SCALE=vec3(BOTTOM_RADIUS)/bottomRadii;const vec2 rayleighMieHeights=vec2(RAYLEIGH_SCALE,MIE_SCALE)*ATMOS_HEIGHT;const vec3 rayleighScatteringCoefficient=vec3(float(${rayleighScatteringCoefficient_0}),float(${rayleighScatteringCoefficient_1}),float(${rayleighScatteringCoefficient_2}))*1e-6;const float mieScatteringCoefficient=float(${mieScatteringCoefficient})*1e-6;const float mieExtinctionCoefficient=float(${mieExtinctionCoefficient})*1e-6;const vec3 ozoneAbsorptionCoefficient=vec3(float(${ozoneAbsorptionCoefficient_0}),float(${ozoneAbsorptionCoefficient_1}),float(${ozoneAbsorptionCoefficient_2}))*1e-6;const float SUN_ANGULAR_RADIUS=float(${SUN_ANGULAR_RADIUS});const float SUN_INTENSITY=float(${SUN_INTENSITY});const float ozoneDensityHeight=float(${ozoneDensityHeight});const float ozoneDensityWide=float(${ozoneDensityWide});vec3 sunWithBloom(vec3 rayDir,vec3 sunDir){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}vec3 sunWithBloomScaled(vec3 rayDir,vec3 sunDir,float angularScale){float minSunCosTheta=cos(SUN_ANGULAR_RADIUS*angularScale);float cosTheta=dot(rayDir,sunDir);if(cosTheta>=minSunCosTheta)return vec3(1.0);float offset=minSunCosTheta-cosTheta;float gaussianBloom=exp(-offset*15000.0)*0.7;float invBloom=1.0/(0.09+offset*200.0)*0.01;return vec3(gaussianBloom+invBloom);}float rayleighPhase(float angle){return 3.0/(16.0*PI)*(1.0+(angle*angle));}float miePhase(float angle){float g=0.8;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));}vec3 opticalDepth(float height,float angle){vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 rayDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);float t1,t2;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,t1,t2);float segmentLength=t2/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 opticalDepth=vec3(0.0);for(int i=0;i<SAMPLE_COUNT;i++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;opticalDepth.xy+=exp(-height/rayleighMieHeights)*segmentLength;opticalDepth.z+=(1.0-min(abs(height-ozoneDensityHeight)/ozoneDensityWide,1.0))*segmentLength;t+=segmentLength;}return opticalDepth;}vec3 transmittance(float height,float angle){vec3 opticalDepth=opticalDepth(height,angle);return exp(-(rayleighScatteringCoefficient*opticalDepth.x+mieExtinctionCoefficient*opticalDepth.y+ozoneAbsorptionCoefficient*opticalDepth.z));}uniform sampler2D transmittanceTexture;uniform vec2 iResolution;vec3 transmittanceFromTexture(float height,float angle){float u=(angle+1.0)*0.5;float v=height/ATMOS_HEIGHT;return texture2D(transmittanceTexture,vec2(u,v)).xyz;}void main(void){vec2 uv=gl_FragCoord.xy/iResolution.xy;float height=uv.y*ATMOS_HEIGHT;float angle=uv.x*2.0-1.0;vec3 rayOrigin=vec3(0.0,BOTTOM_RADIUS+height,0.0);vec3 up=rayOrigin/length(rayOrigin);vec3 lightDirection=vec3(sqrt(1.0-angle*angle),angle,0.0);const float isotropicPhase=1.0/(4.0*PI);vec3 light=vec3(0.0);vec3 lightTransferFactor=vec3(0.0);for(int i=0;i<SQRT_SAMPLE_COUNT;i++){for(int j=0;j<SQRT_SAMPLE_COUNT;j++){float u=((0.5+float(i))/float(SQRT_SAMPLE_COUNT))*2.0-1.0;float v=(0.5+float(j))/float(SQRT_SAMPLE_COUNT);float r=sqrt(1.0-u*u);float theta=2.0*PI*v;vec3 rayDirection=vec3(cos(theta)*r,sin(theta)*r,u);float rayAngle=dot(up,rayDirection);bool cameraBelow=rayAngle<0.0;vec3 transmittanceFromCameraToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);float offset=0.0;float distanceToSpace=0.0;intersectSphere(rayOrigin,rayDirection,TOP_RADIUS,offset,distanceToSpace);float distanceToGround=0.0;bool hitGround=intersectSphere(rayOrigin,rayDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>0.0;float segmentLength=(hitGround ? distanceToGround : distanceToSpace)/float(SAMPLE_COUNT);float t=segmentLength*0.5;vec3 transmittanceCamera;vec3 transmittanceLight;for(int k=0;k<SAMPLE_COUNT;k++){vec3 position=rayOrigin+t*rayDirection;float height=length(position)-BOTTOM_RADIUS;vec3 up=position/length(position);float rayAngle=dot(up,rayDirection);float lightAngle=dot(up,lightDirection);float distanceToGround;float shadow=intersectSphere(position,lightDirection,BOTTOM_RADIUS,distanceToGround)&&distanceToGround>=0.0 ? 0.0 : 1.0;vec3 transmittanceToSpace=transmittanceFromTexture(height,cameraBelow ?-rayAngle : rayAngle);transmittanceCamera=cameraBelow ?(transmittanceToSpace/transmittanceFromCameraToSpace):(transmittanceFromCameraToSpace/transmittanceToSpace);transmittanceLight=transmittanceFromTexture(height,lightAngle);vec2 opticalDensity=exp(-height/rayleighMieHeights);vec3 scatteredLight=transmittanceLight*(rayleighScatteringCoefficient*opticalDensity.x+mieScatteringCoefficient*opticalDensity.y)*isotropicPhase;light+=shadow*transmittanceCamera*scatteredLight*segmentLength;lightTransferFactor+=transmittanceCamera*(rayleighScatteringCoefficient*opticalDensity.x+mieScatteringCoefficient*opticalDensity.y)*segmentLength;t+=segmentLength;}if(hitGround){vec3 hitPoint=rayOrigin+rayDirection*distanceToGround;vec3 normal=normalize(hitPoint);float diffuseAngle=max(dot(normal,lightDirection),0.0);light+=transmittanceCamera*transmittanceLight*GROUND_ALBEDO*diffuseAngle;}}}light/=float(SAMPLE_COUNT);lightTransferFactor/=float(SAMPLE_COUNT);vec3 color=light/(1.0-lightTransferFactor);gl_FragColor=vec4(color,1.0);}",t||er)}))))}initBackgroundShader(){var e;this.renderer&&this.renderer.handler.addProgram((e=this._parameters,new X("atmosphereBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",viewMatrix:"mat4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",sunPos:"vec3",opacity:"float",isOrthographic:"float",frustumParams:"vec4"},attributes:{corners:"vec3"},vertexShader:Hh,fragmentShader:di(Vh,{...e,disableSunDisk:null!=e&&e.disableSunDisk?1:0})})))}removeBackgroundShader(){this.renderer&&this.renderer.handler.removeProgram("atmosphereBackground")}removeLookupTexturesShaders(){var e,t;if(this.renderer){let i=this.renderer.handler;null!=(e=this._scatteringBuffer)&&e.isComplete()&&i.removeProgram("scattering"),null!=(t=this._transmittanceBuffer)&&t.isComplete()&&i.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 Rt(this.renderer.handler,{width:1024,height:1024,useDepth:!1,targets:[{filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}]}),this._transmittanceBuffer.init(),this._scatteringBuffer=new Rt(this.renderer.handler,{width:1024,height:1024,useDepth:!1,targets:[{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 s=t.programs.transmittance,r=s._program.attributes,n=s._program.uniforms;s.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(n.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 s=t.programs.scattering,r=s._program.attributes,n=s._program.uniforms;s.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(n.iResolution,[this._scatteringBuffer.width,this._scatteringBuffer.height]),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._transmittanceBuffer.textures[0]),i.uniform1i(n.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,s=i.uniforms,r=e.gl,n=this.renderer,o=this.planet.camera;r.disable(r.DEPTH_TEST),n.enableBlendOneSrcAlpha(),t.activate(),r.bindBuffer(r.ARRAY_BUFFER,n.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(s.transmittanceTexture,0),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,this._scatteringBuffer.textures[0]),r.uniform1i(s.scatteringTexture,1),r.uniformMatrix4fv(s.viewMatrix,!1,o.getViewMatrix());let a=this.planet.sunPos;r.uniform3fv(s.sunPos,[a.x,a.y,a.z]),r.uniform3fv(s.camPos,[o.eye.x,o.eye.y,o.eye.z]),r.uniform2fv(s.iResolution,[n.sceneFramebuffer.width,n.sceneFramebuffer.height]),r.uniform1f(s.fov,o.getViewAngle()),r.uniform1f(s.opacity,this.opacity);let l=o.frustum;r.uniform1f(s.isOrthographic,o.isOrthographic?1:0),r.uniform4fv(s.frustumParams,[l.right-l.left,l.top-l.bottom,l.right,l.top]),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST),n.enableBlendDefault()}}const Ea="degrees",Gh="m";let jh=0;class hn{constructor(e){this.id=jh++,this.code=e.code,this.units=e.units}equal(e){return e.id===this.id}}const cn=new hn({code:"epsg:3857",units:Gh});class qh{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 s=4*i,r=e.applyMaterial(t);this.tileOffsetArr[s]=r[0],this.tileOffsetArr[s+1]=r[1],this.tileOffsetArr[s+2]=r[2],this.tileOffsetArr[s+3]=r[3]}}function At(e,t,i){return Math.floor(Math.abs(i-e)/t)}function Si(e,t,i,s){let r=1/(1<<i),n=s.getWidth()*r,o=s.getHeight()*r,a=s.southWest.lon+e*n,l=s.northEast.lat-t*o;return new U(new L(a,l-o),new L(a+n,l))}const Le=20,Pe=300;let ye=new v,xe=new v,ir=new v,Qe=new v,Je=new v,sr=new v,ti=new V,Di=new V;const hi=new Array(4);hi[0]=0,hi[1]=1,hi[2]=1,hi[3]=0;const ci=new Array(4);ci[0]=!1,ci[1]=!0,ci[2]=!1,ci[3]=!0;class Aa{constructor(e,t,i,s){this.isPole=!1,this._tileGroup=0,this._projection=cn,this.node=e,this.quadTreeStrategy=t,this.planet=t.planet,this.handler=t.planet.renderer.handler,this.bsphere=new Ft,this._plainRadius=0,this.bbox=new No,this._sw=new v,this._nw=new v,this._se=new v,this._ne=new v,this.centerNormal=new v,this._extent=this._extentMerc=s,this._extentLonLat=new U,this.gridSize=this.planet.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 s=this.tempVertices;if(s&&s.length){let r=this.planet.ellipsoid.getSurfaceNormal3v(e);ti.set(e,r.negateTo());let n=this._extent.northEast,o=this._extent.southWest,a=Math.sqrt(s.length/3)-1,l=n.lon,h=n.lat,c=o.lon,d=o.lat,_=(l-c)/a,u=(h-d)/a,f=t.lon-c,g=t.lat-d,p=Math.floor(f/_),m=Math.floor(a-g/u),v=3*((a+1)*m+p),y=3*((a+1)*(m+1)+p);ir.set(s[v],s[v+1],s[v+2]),Qe.set(s[v+3],s[v+4],s[v+5]),Je.set(s[y],s[y+1],s[y+2]);let x=ti.hitTriangleRes(ir,Qe,Je,i);return x===V.INSIDE?e.distance(i):x===V.AWAY&&(Di.set(e,r),Di.hitTriangleRes(ir,Qe,Je,i)===V.INSIDE)?-e.distance(i):(sr.set(s[y+3],s[y+4],s[y+5]),x=ti.hitTriangleRes(Qe,sr,Je,i),x===V.INSIDE?e.distance(i):x===V.AWAY&&(Di.set(e,r),Di.hitTriangleRes(Qe,sr,Je,i)===V.INSIDE)||x===V.AWAY?-e.distance(i):e.distance(i))}return e.distance(this.planet.ellipsoid.hitRay(ti.origin,ti.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[ui[e]]}equalize(){if(this.tileZoom<2||this.gridSize<2)return;this.readyToEngage=!0;let e=this.node.neighbors,t=this.tempVertices,i=this.tempVerticesHigh,s=this.tempVerticesLow,r=this.gridSize,n=r+1,o=e[0][0];if(this._checkEqualization(0,o)){this.node.equalizedSideWithNodeId[0]=o.equalizedSideWithNodeId[2],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,0),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let r=0,o=e*c;r<n;r+=u,o+=f){const e=3*r,n=3*(d*c+o);t[e]=a[n],t[e+1]=a[n+1],t[e+2]=a[n+2],i[e]=l[n],i[e+1]=l[n+1],i[e+2]=l[n+2],s[e]=h[n],s[e+1]=h[n+1],s[e+2]=h[n+2]}}if(o=e[1][0],this._checkEqualization(1,o)){this.node.equalizedSideWithNodeId[1]=o.equalizedSideWithNodeId[3],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,1),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let o=0,_=e*c;o<n;o+=u,_+=f){const e=3*(n*o+r),c=d*_*3;t[e]=a[c],t[e+1]=a[c+1],t[e+2]=a[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],s[e]=h[c],s[e+1]=h[c+1],s[e+2]=h[c+2]}}if(o=e[2][0],this._checkEqualization(2,o)){this.node.equalizedSideWithNodeId[2]=o.equalizedSideWithNodeId[0],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,2),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=1/(1<<this.tileZoom-o.segment.tileZoom),_=Math.max(r/(c*d),1),u=Math.max(c*d/r,1);for(let o=0,d=e*c;o<n;o+=_,d+=u){const e=3*(n*r+o),c=3*d;t[e]=a[c],t[e+1]=a[c+1],t[e+2]=a[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],s[e]=h[c],s[e+1]=h[c+1],s[e+2]=h[c+2]}}if(o=e[3][0],this._checkEqualization(3,o)){this.node.equalizedSideWithNodeId[3]=o.equalizedSideWithNodeId[1],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,3),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(r/(c*_),1),f=Math.max(c*_/r,1);for(let r=0,o=e*c;r<n;r+=u,o+=f){const e=n*r*3,_=3*(d*o+c);t[e]=a[_],t[e+1]=a[_+1],t[e+2]=a[_+2],i[e]=l[_],i[e+1]=l[_+1],i[e+2]=l[_+2],s[e]=h[_],s[e+1]=h[_+1],s[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],s=i&&i[0],r=this.planet.terrain.maxZoom;this.tileZoom===r&&i&&!(t[0].length||t[1].length||t[2].length||t[3].length)&&(s=this.node.getEqualNeighbor(e));let n=s&&s.segment,o=this;if(s&&n&&n.terrainReady&&n.terrainExists&&n.tileZoom<=r&&o._appliedNeighborsZoom[e]!==n.tileZoom){o._appliedNeighborsZoom[e]=n.tileZoom;let t=o.normalMapNormals,i=n.normalMapNormals;if(!t||!i)return;let s=o.normalMapNormals,r=n.normalMapNormals,a=Math.sqrt(t.length/3),l=a-1;const h=l*hi[e];let c,d,_,u;if(o.tileZoom===n.tileZoom){const f=l-h;if(ci[e])for(let e=0;e<a;e++){let n=3*(e*a+h),o=3*(e*a+f);c=s[n]+r[o],d=s[n+1]+r[o+1],_=s[n+2]+r[o+2],u=1/Math.sqrt(c*c+d*d+_*_),i[o]=t[n]=c*u,i[o+1]=t[n+1]=d*u,i[o+2]=t[n+2]=_*u}else for(let e=0;e<a;e++){let n=3*(h*a+e),o=3*(f*a+e);c=s[n]+r[o],d=s[n+1]+r[o+1],_=s[n+2]+r[o+2],u=1/Math.sqrt(c*c+d*d+_*_),i[o]=t[n]=c*u,i[o+1]=t[n+1]=d*u,i[o+2]=t[n+2]=_*u}n._inTheQueue||n._appliedNeighborsZoom[ui[e]]===o.tileZoom||(n._appliedNeighborsZoom[ui[e]]=o.tileZoom,o.planet._normalMapCreator.queue(n))}}}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),s=e.geodeticToCartesian(t.northEast.lon,t.northEast.lat),r=e.geodeticToCartesian(t.southWest.lon,t.northEast.lat),n=e.geodeticToCartesian(t.northEast.lon,t.southWest.lat);this._sw.copy(i),this._nw.copy(r),this._ne.copy(s),this._se.copy(n)}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,s=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*s,n=r*i,o=e.segment.gridSize+1,a=3*((t+r)*o+n),l=3*(t*o+n),h=3*(t*o+n+r),c=3*((t+r)*o+n+r),d=e.segment.tempVertices,_=new v(d[a],d[a+1],d[a+2]),u=new v(d[h],d[h+1],d[h+2]),f=new v(d[l],d[l+1],d[l+2]),g=new v(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,n=e.segment,o=Math.floor(r*s),a=Math.floor(r*i),l=1/r,h=s-l*o,c=i-l*a;t=1===n.gridSize?n.tempVertices:Kr(n.tempVertices,n.gridSize,o,a,1);let d,_,u=new v(t[0],t[1],t[2]),f=new v(t[9],t[10],t[11]),g=new v(t[3]-t[0],t[4]-t[1],t[5]-t[2]),p=new v(t[6]-t[0],t[7]-t[1],t[8]-t[2]),m=new v(t[3]-t[9],t[4]-t[10],t[5]-t[11]),y=new v(t[6]-t[9],t[7]-t[10],t[8]-t[11]),x=h,b=c;d=x+b<l?v.add(g.scaleTo(b/l),p.scaleTo(x/l)).addA(u):v.add(y.scaleTo(1-b/l),m.scaleTo(1-x/l)).addA(f),x=h+1,b=c+1,_=x+b<l?v.add(g.scaleTo(b/l),p.scaleTo(x/l)).addA(u):v.add(y.scaleTo(1-b/l),m.scaleTo(1-x/l)).addA(f),this._createExtentNormals(),this.setBoundingVolume3v(d,_)}}else this.createBoundsByExtent()}setBoundingSphere(e,t,i,s){this.bsphere.center.x=e,this.bsphere.center.y=t,this.bsphere.center.z=i,this.bsphere.radius=this.bsphere.center.distance(s)}setBoundingVolume(e,t,i,s,r,n){this.bbox.setFromBoundsArr([e,t,i,s,r,n]);let o=e+.5*(s-e),a=t+.5*(r-t),l=i+.5*(n-i);this.bsphere.center.set(o,a,l),this.bsphere.radius=this.bsphere.center.distance(new v(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),s=e.y+.5*(t.y-e.y),r=e.z+.5*(t.z-e.z);this.bsphere.center.set(i,s,r),this.bsphere.radius=this.bsphere.center.distance(new v(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]),s=e[2]+.5*(e[5]-e[2]);this.bsphere.center.set(t,i,s),this.bsphere.radius=this.bsphere.center.distance(new v(e[0],e[1],e[2]))}createCoordsBuffers(e,t,i){const s=(i+1)*(i+1),r=this.handler;this.vertexPositionBufferHigh&&this.vertexPositionBufferHigh.numItems===s?(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,s),this.vertexPositionBufferLow=r.createArrayBuffer(t,3,s))}_addViewExtent(){const e=this._extentLonLat;let t=this.quadTreeStrategy._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=Lt;this.tileX=At(t.getCenter().lon,t.getWidth(),-20037508.34),this.tileY=At(t.getCenter().lat,t.getHeight(),i);const s=this.powTileZoom;this.tileXE=(this.tileX+1)%s,this.tileXW=(s+this.tileX-1)%s,this.tileYN=this.tileY-1,this.tileYS=this.tileY+1,this.tileIndex=zt.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+Lt)*ri,this._globalTextureCoordinates[1]=(Lt-e.northEast.lat)*ri,this._globalTextureCoordinates[2]=(e.northEast.lon+Lt)*ri,this._globalTextureCoordinates[3]=(Lt-e.southWest.lat)*ri}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 L.inverseMercator(e,t)}_createPlainVertices(){const e=this.planet.terrain.gridSizeByZoom[this.tileZoom],t=this.planet.terrain.plainGridSize,i=Math.max(t,e),s=this._extent,r=s.getWidth()/i,n=s.getHeight()/i,o=s.southWest.lon,a=s.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,y=this.plainNormals,x=this.normalMapVertices,b=this.normalMapVerticesHigh,w=this.normalMapVerticesLow,T=this.normalMapNormals;for(let e=0;e<d;e++){let t=e%h,i=~~(e/h),s=this.planet.ellipsoid.lonLatToCartesian(this._projToDeg(o+t*r,a-i*n)),d=s.x*c.x,_=s.y*c.y,C=s.z*c.z,E=1/Math.sqrt(d*d+_*_+C*C),A=d*E,L=_*E,P=C*E;v.doubleToTwoFloats(s,ye,xe),x[f]=s.x,b[f]=ye.x,w[f]=xe.x,T[f++]=A,x[f]=s.y,b[f]=ye.y,w[f]=xe.y,T[f++]=L,x[f]=s.z,b[f]=ye.z,w[f]=xe.z,T[f++]=P,i%l==0&&t%l==0&&(g[u]=s.x,p[u]=ye.x,m[u]=xe.x,y[u++]=A,g[u]=s.y,p[u]=ye.y,m[u]=xe.y,y[u++]=L,g[u]=s.z,p[u]=ye.z,m[u]=xe.z,y[u++]=P)}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,s=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/s,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/s,(i.northEast.lat-i.southWest.lat)/r]}initSlice(e){let t=this._slices[e];return t?t.layers=[]:t=this._slices[e]=new qh(this),t}screenRendering(e,t,i,s,r=!1,n){const o=this.handler.gl,a=e.attributes,l=e.uniforms,h=this.materials,c=this.planet,d=this.quadTreeStrategy;let _,u;t&&t.length?(u=t[0],_=u._height):_=0,o.activeTexture(o.TEXTURE0+c.SLICE_SIZE+2),o.bindTexture(o.TEXTURE_2D,s||this.getDefaultTexture()),o.uniform1i(l.defaultTexture,c.SLICE_SIZE+2);let f=0,g=0,p=!1,m=this.initSlice(i);for(this._indexBuffer=this._getIndexBuffer();u;){if(this.layerOverlap(u)&&(u._fading&&u._fadingOpacity>0||(u.minZoom>=d.minCurrZoom||u.maxZoom>=d.minCurrZoom)&&(u.minZoom<=d.maxCurrZoom||u.maxZoom<=d.maxCurrZoom))){p=!0;let e=h[u.__id];e||(e=h[u.__id]=u.createMaterial(this)),e.isReady||(d._renderCompleted=!1),m.append(u,e),c._samplerArr[f]=f,o.activeTexture(o.TEXTURE0+f),o.bindTexture(o.TEXTURE_2D,e.texture||c.transparentTexture),f++}g++,u=t[g]}!p&&r||(o.uniform1f(l.transitionOpacity,n||this._transitionOpacity>1?1:this._transitionOpacity),o.uniform1i(l.samplerCount,f),o.uniform1f(l.height,_),o.uniform1iv(l.samplerArr,c._samplerArr),o.uniform4fv(l.tileOffsetArr,m.tileOffsetArr),o.uniform1fv(l.layerOpacityArr,m.layerOpacityArr),c.lightEnabled&&(o.activeTexture(o.TEXTURE0+c.SLICE_SIZE+3),o.bindTexture(o.TEXTURE_2D,this.normalMapTexture||c.transparentTexture),o.uniform1i(l.uNormalMap,c.SLICE_SIZE+3),o.uniform3fv(l.uNormalMapBias,this.normalMapTextureBias),o.uniform4fv(l.uGlobalTextureCoord,this._globalTextureCoordinates)),o.bindBuffer(o.ARRAY_BUFFER,this.vertexPositionBufferHigh),o.vertexAttribPointer(a.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.vertexPositionBufferLow),o.vertexAttribPointer(a.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.vertexTextureCoordBuffer),o.vertexAttribPointer(a.aTextureCoord,2,o.UNSIGNED_SHORT,!0,0,0),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,this._indexBuffer),o.drawElements(c.drawMode,this._indexBuffer.numItems,o.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.quadTreeStrategy._fadingNodes.has(t.__id)&&(this.quadTreeStrategy._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,s,r=!1){const n=this.handler.gl,o=e.attributes,a=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,n.activeTexture(n.TEXTURE0+e),n.bindTexture(n.TEXTURE_2D,h[t.__id].texture||this.planet.transparentTexture),c._pickingMaskArr[e]=e+c.SLICE_SIZE,n.activeTexture(n.TEXTURE0+e+c.SLICE_SIZE),n.bindTexture(n.TEXTURE_2D,h[t.__id].pickingMask||this.planet.transparentTexture)}!d&&r||(n.uniform1i(a.samplerCount,u),n.uniform1f(a.height,l),n.uniform1iv(a.samplerArr,c._samplerArr),n.uniform1iv(a.pickingMaskArr,c._pickingMaskArr),n.uniform4fv(a.pickingColorArr,c._pickingColorArr),n.uniform4fv(a.tileOffsetArr,_.tileOffsetArr),n.uniform1fv(a.layerOpacityArr,_.layerOpacityArr),n.bindBuffer(n.ARRAY_BUFFER,this.vertexPositionBufferHigh),n.vertexAttribPointer(o.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this.vertexPositionBufferLow),n.vertexAttribPointer(o.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,n.FLOAT,!1,0,0),n.bindBuffer(n.ARRAY_BUFFER,this.vertexTextureCoordBuffer),n.vertexAttribPointer(o.aTextureCoord,2,n.UNSIGNED_SHORT,!0,0,0),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,this._indexBuffer),n.drawElements(n.TRIANGLE_STRIP,this._indexBuffer.numItems,n.UNSIGNED_INT,0))}depthRendering(e,t){const i=this.handler.gl,s=e.attributes,r=e.uniforms;var n;n=t&&t.length?t[0]._height:0,i.uniform1f(r.height,n),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(s.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(s.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=$i().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}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 Fi=new v,Oi=new v;const be=[new H(0,0),new H(1,0),new H(0,1),new H(1,1)],Yh=Math.sqrt(be.length)-1;let at={xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0},Wh=0;class qt{constructor(e,t,i,s,r,n){t.planet._createdNodesCount++,this.__id=Wh++,this.SegmentPrototype=e,this.quadTreeStrategy=t,this.parentNode=s,this.partId=i,this.nodeId=i+(s?4*s.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,n),this._cameraInside=!1,this.inFrustum=0,this._fadingNodes=[],this.createBounds()}createChildNodes(){this.ready=!0;const e=this.quadTreeStrategy,t=this.segment,i=t._extent,s=t.tileZoom+1,r=.5*i.getWidth(),n=.5*i.getHeight(),o=i.northEast,a=i.southWest,l=new L(a.lon+r,a.lat+n),h=this.nodes;h[0]=new qt(this.SegmentPrototype,e,0,this,s,new U(new L(a.lon,a.lat+n),new L(a.lon+r,o.lat))),h[1]=new qt(this.SegmentPrototype,e,1,this,s,new U(l,new L(o.lon,o.lat))),h[2]=new qt(this.SegmentPrototype,e,2,this,s,new U(new L(a.lon,a.lat),l)),h[3]=new qt(this.SegmentPrototype,e,3,this,s,new U(new L(a.lon+r,a.lat),new L(o.lon,a.lat+n)))}createBounds(){let e=this.segment;e._setExtentLonLat(),0===e.tileZoom?e.setBoundingSphere(0,0,0,new v(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,s=e.bsphere.center.z,r=1/Math.sqrt(t*t+i*i+s*s);e.centerNormal.x=t*r,e.centerNormal.y=i*r,e.centerNormal.z=s*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=wn[e][t.partId];if(-1!==i)return t.parentNode.nodes[i];{let s=[];for(;t.parentNode;)if(s.push(t.partId),i=wn[e][t.partId],t=t.parentNode,-1!==i){let r=s.length;for(e=ui[e];t&&r--;)i=Ya[e][s[r]],t=t.nodes[i];return t}}}traverseNodes(e,t,i,s,r){this.ready||this.createChildNodes();let n=this.nodes;n[0].renderTree(e,t,i,s,r),n[1].renderTree(e,t,i,s,r),n[2].renderTree(e,t,i,s,r),n[3].renderTree(e,t,i,s,r)}renderTree(e,t,i,s,r){if(this.quadTreeStrategy._renderedNodes.length>=1e3)return;(!t||r&&this.segment.tileZoom>r.segment.tileZoom)&&(this.prevState=this.state),this.state=2,this.clearNeighbors();let n=this.segment,o=this.quadTreeStrategy.planet;if(this._cameraInside=!1,!this.parentNode||this.parentNode._cameraInside){let t;t=n._projection.id===cn.id?n._extent.isInside(e._lonLatMerc):n._extent.isInside(e._lonLat),t&&(e._insideSegment=n,this._cameraInside=!0)}this.inFrustum=0;let a=e.frustums,l=a.length;if(n.tileZoom<6)for(let e=0;e<l;e++)a[e].containsSphere(n.bsphere)&&(this.inFrustum|=1<<e);else for(let e=0;e<l;e++)n.terrainReady?a[e].containsBox(n.bbox)&&(this.inFrustum|=1<<e):a[e].containsSphere(n.bsphere)&&(this.inFrustum|=1<<e);if(this.inFrustum||this._cameraInside||n.tileZoom<3){let a=Math.abs(e._lonLat.height),l=e.eye.length2()-o.ellipsoid.polarSizeSqr,h=106876472875.63281*o._heightFactor;l=l<h?h:l;let c=n.tileZoom<2||n.tileZoom>19||n.tileZoom<6&&!n.terrainReady;if(e.isOrthographic){let t=e.getForward();c=c||t.dot(n._sw.getNormal())<-0||t.dot(n._nw.getNormal())<-0||t.dot(n._ne.getNormal())<-0||t.dot(n._se.getNormal())<-0}else c=c||e.eye.distance2(n._sw)<l||e.eye.distance2(n._nw)<l||e.eye.distance2(n._ne)<l||e.eye.distance2(n._se)<l;(this.inFrustum&&(c||a>1e4)||this._cameraInside)&&this.quadTreeStrategy.collectVisibleNode(this),n.tileZoom<2?this.traverseNodes(e,t,i,s,r):n.terrainReady&&(!t&&e.projectedSize(n.bsphere.center,n._plainRadius)<this.quadTreeStrategy.lodSize||t&&(n.tileZoom===t||!c))?c?(n.passReady=!0,this.renderNode(this.inFrustum,!this.inFrustum,i,s)):this.state=0:n.terrainReady&&n.checkZoom()&&(!t||e.projectedSize(n.bsphere.center,n.bsphere.radius)>this.quadTreeStrategy._maxLodSize)?this.traverseNodes(e,t,n,s,r):c?(n.passReady=!!t&&n.terrainReady,this.renderNode(this.inFrustum,!this.inFrustum,i,s)):this.state=0}else this.state=0}renderNode(e,t,i,s){let r=this.segment;r.terrainReady||(r.initialized||r.initialize(),this.whileTerrainLoading(i),r.plainProcessing||r.createPlainSegmentAsync(),r.plainReady&&!s&&r.loadTerrain()),r.planet.lightEnabled&&!r.normalMapReady&&this.whileNormalMapCreating(),t?this.state=-1:(!this._cameraInside&&r.tileZoom>this.quadTreeStrategy.maxCurrZoom&&(this.quadTreeStrategy.maxCurrZoom=r.tileZoom),r.tileZoom<this.quadTreeStrategy.minCurrZoom&&(this.quadTreeStrategy.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.quadTreeStrategy._renderedNodes;this.quadTreeStrategy._transitionOpacityEnabled?Zr(t,this,((e,t)=>e.segment.tileZoom-t.segment.tileZoom)):(this.getRenderedNodesNeighbors(t),t.push(this)),this.segment.terrainReady||(this.quadTreeStrategy._renderCompleted=!1,this.quadTreeStrategy._terrainCompleted=!1);let i=0,s=this.quadTreeStrategy._renderedNodesInFrustum;for(;e;)1&e&&s[i].push(this),i++,e>>=1}applyNeighbor(e,t){const i=ui[t];if(0===this.neighbors[t].length||0===e.neighbors[i].length){const s=this.segment,r=e.segment,n=s.gridSize/(r.gridSize*Math.pow(2,r.tileZoom-s.tileZoom));let o=s.gridSize,a=r.gridSize;n>1?(o=Math.ceil(s.gridSize/n),a=r.gridSize):n<1&&(o=s.gridSize,a=Math.ceil(r.gridSize*n)),this.sideSizeLog2[t]=Math.log2(o),e.sideSizeLog2[i]=Math.log2(a)}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],s=this.getCommonSide(i);-1!==s&&this.applyNeighbor(i,s)}}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,s=i._extentLonLat;let r=e.northEast,n=e.southWest,o=s.northEast,a=s.southWest,l=r.lon,h=r.lat,c=n.lon,d=n.lat,_=o.lon,u=o.lat,f=a.lon,g=a.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&&20===i._tileGroup&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(0===t._tileGroup&&i._tileGroup===Pe&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=f&&l<=_||c<=f&&l>=_))return 2;if(t._tileGroup===Pe&&0===i._tileGroup&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=f&&l<=_||c<=f&&l>=_))return 0;if(20===t._tileGroup&&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,s=t.tileX-i.segment.tileX*e,r=t.tileY-i.segment.tileY*e;const n=i.segment;let o,a,l,h;this.appliedTerrainNodeId=i.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId;let c=i.segment.gridSize/e,d=i.segment.fileGridSize/e;if(at.xmin=xt,at.xmax=Ct,at.ymin=xt,at.ymax=Ct,at.zmin=xt,at.zmax=Ct,c>=1){t.gridSize=c;let e=(c+1)*(c+1)*3;o=new Float64Array(e),a=new Float32Array(e),l=new Float32Array(e),n.noDataVertices&&(h=new Uint8Array(e/3)),dr(n.terrainVertices,n.terrainVerticesHigh,n.terrainVerticesLow,n.noDataVertices,n.gridSize,c*r,c*s,c,o,a,l,at,h)}else if(d>=1&&i.segment.terrainExists){t.gridSize=d;let e=(d+1)*(d+1)*3;o=new Float64Array(e),a=new Float32Array(e),l=new Float32Array(e),n.noDataVertices&&(h=new Uint8Array(e/3)),dr(n.normalMapVertices,n.normalMapVerticesHigh,n.normalMapVerticesLow,n.noDataVertices,i.segment.fileGridSize,d*r,d*s,d,o,a,l,at,h)}else{t.gridSize=Yh;let e,i=Math.floor(c*r),h=Math.floor(c*s);e=1===n.gridSize?n.terrainVertices:Kr(n.terrainVertices,n.gridSize,i,h,1);let d=1/c,_=r-d*i,u=s-d*h,f=new v(e[0],e[1],e[2]),g=new v(e[9],e[10],e[11]),p=new v(e[3]-e[0],e[4]-e[1],e[5]-e[2]),m=new v(e[6]-e[0],e[7]-e[1],e[8]-e[2]),y=new v(e[3]-e[9],e[4]-e[10],e[5]-e[11]),x=new v(e[6]-e[9],e[7]-e[10],e[8]-e[11]),b=new v;o=new Float64Array(3*be.length),a=new Float32Array(3*be.length),l=new Float32Array(3*be.length);for(let e=0;e<be.length;e++){let t=be[e].y+_,i=be[e].x+u,s=i*c,r=t*c;b=t+i<d?p.scaleTo(s).addA(m.scaleTo(r)).addA(f):x.scaleTo(1-s).addA(y.scaleTo(1-r)).addA(g),v.doubleToTwoFloats(b,Fi,Oi);let n=3*e;o[n]=b.x,o[n+1]=b.y,o[n+2]=b.z,a[n]=Fi.x,a[n+1]=Fi.y,a[n+2]=Fi.z,l[n]=Oi.x,l[n+1]=Oi.y,l[n+2]=Oi.z,b.x<at.xmin&&(at.xmin=b.x),b.x>at.xmax&&(at.xmax=b.x),b.y<at.ymin&&(at.ymin=b.y),b.y>at.ymax&&(at.ymax=b.y),b.z<at.zmin&&(at.zmin=b.z),b.z>at.zmax&&(at.zmax=b.z)}}if(t.readyToEngage=!0,t.terrainVertices=o,t.terrainVerticesHigh=a,t.terrainVerticesLow=l,t.tempVertices=o,t.tempVerticesHigh=a,t.tempVerticesLow=l,t.noDataVertices=h,t.setBoundingVolume(at.xmin,at.ymin,at.zmin,at.xmax,at.ymax,at.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=o,t.terrainVerticesHigh=a,t.terrainVerticesLow=l,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=o,t.fileGridSize=Math.sqrt(o.length/3)-1;let i=Math.sqrt(n.normalMapNormals.length/3)-1,a=i/e;t.normalMapNormals=i>1?Io(n.normalMapNormals,i,a*r,a*s,a):n.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,s=e.segment.tileZoom,r=0;for(;i.segment.tileZoom>s;)r+=Wa[i.partId][t]/(1<<i.segment.tileZoom-s),i=i.parentNode;return r}}class dn{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 un{constructor(e,t,i){this.quadTreeStrategy=e,this._layer=t,this._nodeCapacity=i,this._secondPASS=[],this._counter=0,this._deferredEntitiesPendingQueue=new dn,this._renderingNodes={}}insertEntity(e,t=!1){}setPickingEnabled(e){}dispose(){}insertEntities(e){}collectVisibleEntityCollections(e){}_queueDeferredNode(e){this._layer.getVisibility()&&(e._inTheQueue=!0,this._counter>=1?this._deferredEntitiesPendingQueue.push(e):this._execDeferredNode(e))}_execDeferredNode(e){this._counter++,requestAnimationFrame((()=>{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)}}))}}class Is{constructor(e){this._skipPreRender=!1,this.events=lt($h),this.name=e.name||"",this.projection=e.proj||cn,this.planet=e.planet,this._quadTreeList=[],this._visibleNodes={},this._renderedNodes=[],this._renderedNodesInFrustum=[],this._fadingNodes=new Map,this._fadingNodesInFrustum=[],this._fadingOpaqueSegments=[],this.minCurrZoom=xt,this.maxCurrZoom=Ct,this._viewExtent=new U(new L(180,180),new L(-180,-180)),this._lodSize=256,this._curLodSize=256,this._minLodSize=512,this._maxLodSize=256,this.maxEqualZoomAltitude=e.maxEqualZoomAltitude||15e6,this.minEqualZoomAltitude=e.minEqualZoomAltitude||1e4,this.minEqualZoomCameraSlope=e.minEqualZoomCameraSlope||.8,this._renderCompleted=!1,this._renderCompletedActivated=!1,this._terrainCompleted=!1,this._terrainCompletedActivated=!1,this._transitionOpacityEnabled=null==e.transitionOpacityEnabled||e.transitionOpacityEnabled}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}createEntityCollectionsTreeStrategy(e,t){return new un(this,e,t)}destroyBranches(){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1;for(let e=0,t=this._quadTreeList.length;e<t;e++)this._quadTreeList[e].destroyBranches()}clearLayerMaterial(e,t=!1){let i=e.__id;for(let e=0,s=this._quadTreeList.length;e<s;e++)this._quadTreeList[e].traverseTree((e=>{if(t&&this._renderedNodes.includes(e))return;let s=e.segment.materials;s[i]&&(s[i].clear(),s[i]=null)}))}get terrainReady(){return this._terrainCompleted&&this._terrainCompletedActivated}_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}_initEvents(){this.planet.renderer.events.on("resize",(()=>{this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1})),this.planet.renderer.events.on("postdraw",(()=>{this._checkRendercompleted()}))}init(e){this._initEvents(),this._renderedNodesInFrustum=new Array(e.frustums.length);for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e]=[];this.preRender(),this.clearRenderedNodes(),this.preLoad()}clearRenderedNodes(){this._clearRenderedNodeList(),this._clearRenderNodesInFrustum()}_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.isOrthographic||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,s=[];this._clearRenderNodesInFrustum(),this._renderedNodes=[];for(let r=0,n=t.length;r<n;r++){let n=t[r],o=n.segment.centerNormal.dot(e.getBackward());if(n.segment.tileZoom===this.maxCurrZoom||o<.81){this._renderedNodes.push(n);let e=0,t=n.inFrustum;for(;t;)1&t&&i[e].push(n),e++,t>>=1}else s.push(n)}for(let t=0,i=s.length;t<i;t++)s[t].renderTree(e,this.maxCurrZoom,null,!1,s[t])}}set transitionOpacityEnabled(e){this._transitionOpacityEnabled=e}get transitionOpacityEnabled(){return this._transitionOpacityEnabled}collectRenderNodes(e){if(this._skipPreRender&&(this._lodSize=wo(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.minCurrZoom=xt,this.maxCurrZoom=Ct,this._collectRenderNodes(e),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 s=i._fadingNodes[t];s.segment&&s.segment._transitionOpacity>=1&&(s.clearNeighbors(),s.getRenderedNodesNeighbors(e),e.push(s))}}}this._skipPreRender=!0}preRender(){this._skipPreRender=!1;for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.createChildNodes(),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)}}_clearVisibleNodes(){this._visibleNodes={}}_collectRenderNodes(e){this._clearVisibleNodes();for(let t=0;t<this._quadTreeList.length;t++)this._quadTreeList[t].renderTree(e,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,s,r=t,n=1<<r;return i=At(e.lon,360/n,-180),s=At(e.lat,180/n,90),[i,s,r,0]}getLonLatTileOffset(e,t,i,s,r){let n;n=Si(t,i,s,U.createFromArray([-180,-90,180,90]));let o=n.getWidth()/(r-1),a=n.getHeight()/(r-1);return[r-Math.ceil((e.lat-n.southWest.lat)/a)-1,Math.floor((e.lon-n.southWest.lon)/o)]}collectVisibleNode(e){this._visibleNodes[e.nodeId]=e}}const $h=["rendercompleted","terraincompleted"],zs=new hn({code:"epsg:4326",units:Ea}),ho=(90-ct)/Math.pow(2,7);class Hr extends Aa{constructor(e,t,i,s){super(e,t,i,s),this._projection=zs,this._extentLonLat=this._extent,this._extentMerc=new U(s.southWest.forwardMercatorEPS01(),s.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;if(this._isNorth){let t=Math.floor((90-this._extent.northEast.lat)/ho);e=Math.floor(t/16)+7}else{let t=Math.floor((Ot-this._extent.northEast.lat)/ho);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=zt.getTileIndex(this.tileX,this.tileY,this.tileZoom,this._tileGroup)}_assignTileXIndexes(e){this.tileX=At(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=20,this.tileY=At(t,e.getHeight(),90)):(this._tileGroup=Pe,this.tileY=At(t,e.getHeight(),Ot)),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_projToDeg(e,t){return new L(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}_getLayerExtentOffset(e){const t=e._extent,i=this._extent,s=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/s,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/s,(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 pe{constructor(e,t,i,s,r,n){this.strategy=e,this.layer=e._layer,this.parentNode=i,this.childNodes=[],this.partId=t,this.nodeId=t+(i?4*i.nodeId+1:0),this.state=null,this.extent=s,this.count=0,this.deferredEntities=[],this.entityCollection=null,this.zoom=n,this._inTheQueue=!1,this.bsphere=new Ft,r&&this._setExtentBounds()}insertEntity(e,t=!1){this.buildTree([e],t)}_addEntitiesToCollection(e,t=!1){if(e.length){const i=this.layer,s=i._planet;let r=this.entityCollection;r||(r=new se({pickingEnabled:i._pickingEnabled,labelMaxLetters:i.labelMaxLetters}),r._layer=this.layer,r.addTo(s,!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 v)}__setLonLat__(e){return e._lonLat.isZero()&&!e._cartesian.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),Math.abs(e._lonLat.lat)<ct?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc=new L,e._lonLatMerc}buildTree(e,t=!1){if(this.count+=e.length,e.length>this.layer._nodeCapacity){const i=this.childNodes;i.length||this.createChildNodes();let s=[],r=[],n=[],o=[],a=e.length;for(;a--;){const t=e[a];i[0].isInside(t)?(t._nodePtr=i[0],s.push(t)):i[1].isInside(t)?(t._nodePtr=i[1],r.push(t)):i[2].isInside(t)?(t._nodePtr=i[2],n.push(t)):i[3].isInside(t)&&(t._nodePtr=i[3],o.push(t))}s.length&&i[0].buildTree(s,t),r.length&&i[1].buildTree(r,t),n.length&&i[2].buildTree(n,t),o.length&&i[3].buildTree(o,t)}else this._addEntitiesToCollection(e,t)}isInside(e){return!!e._lonLatMerc&&this.extent.isInside(e._lonLatMerc)}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),r=t.northEast,n=t.southWest,o=new L(n.lon+i,n.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new pe(e,0,this,new U(new L(n.lon,n.lat+s),new L(n.lon+i,r.lat)),l,h),a[1]=new pe(e,1,this,new U(o,new L(r.lon,r.lat)),l,h),a[2]=new pe(e,2,this,new U(new L(n.lon,n.lat),o),l,h),a[3]=new pe(e,3,this,new U(new L(n.lon+i,n.lat),new L(r.lon,n.lat+s)),l,h)}collectRenderCollectionsPASS1(e,t){const i=e[this.nodeId];if(i){const s=this.childNodes;this.entityCollection?this.renderCollection(t,e):s.length&&(1===i.state?this.strategy._secondPASS.push(this):(s[0].collectRenderCollectionsPASS1(e,t),s[1].collectRenderCollectionsPASS1(e,t),s[2].collectRenderCollectionsPASS1(e,t),s[3].collectRenderCollectionsPASS1(e,t)))}}collectRenderCollectionsPASS2(e,t,i){const s=this.layer._planet.camera,r=s.eye.distance(this.bsphere.center)-this.bsphere.radius<3570*Math.sqrt(s._lonLat.height)||s._lonLat.height>1e4;if(this.count>0&&r&&s.containsSphere(this.bsphere)){const s=this.childNodes;this.entityCollection?this.renderCollection(t,e,i):s.length&&(s[0].collectRenderCollectionsPASS2(e,t,i),s[1].collectRenderCollectionsPASS2(e,t,i),s[2].collectRenderCollectionsPASS2(e,t,i),s[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.childNodes;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 s=this.strategy;s._renderingNodes[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?s._queueDeferredNode(this):this.applyCollection());let r=this.entityCollection,n=this.layer;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 r=e[s];this.alignEntityToTheGround(r,t[i].segment)}else{const t=this.strategy.quadTreeStrategy._renderedNodes;for(;s--;){let i=e[s],r=t.length;for(;r--;)if(t[r].segment.isEntityInside(i)){this.alignEntityToTheGround(i,t[r].segment);break}}}}}alignEntityToTheGround(e,t){let i=new v;t.getEntityTerrainPoint(e,i);let s=Number(this.layer.relativeToGround)&&e._altitude||0;if(s){let t=this.layer._planet.ellipsoid.getSurfaceNormal3v(i);e._setCartesian3vSilent(i.addA(t.scale(s)))}else e._setCartesian3vSilent(i)}isVisible(){return!!this.strategy._renderingNodes[this.nodeId]}}class Ce extends pe{constructor(e,t,i,s,r,n){super(e,t,i,s,r,n),this.strategy=e,this.isNorth=!1}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),r=t.northEast,n=t.southWest,o=new L(n.lon+i,n.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new Ce(e,0,this,new U(new L(n.lon,n.lat+s),new L(n.lon+i,r.lat)),l,h),a[1]=new Ce(e,1,this,new U(o,new L(r.lon,r.lat)),l,h),a[2]=new Ce(e,2,this,new U(new L(n.lon,n.lat),o),l,h),a[3]=new Ce(e,3,this,new U(new L(n.lon+i,n.lat),new L(r.lon,n.lat+s)),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.strategy._renderingNodesNorth[this.nodeId])||!!this.strategy._renderingNodesSouth[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.isNorth?this.strategy._renderingNodesNorth[this.nodeId]=!0:this.strategy._renderingNodesSouth[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.strategy._queueDeferredNode(this):this.applyCollection());const s=this.entityCollection;s._fadingOpacity=this.layer._fadingOpacity,s.scaleByDistance=this.layer.scaleByDistance,s.pickingScale=this.layer.pickingScale,s.isEmpty()||e.push(s)}}class Xh extends un{constructor(e,t,i){super(e,t,i);let s=t._planet;this._entityCollectionsTree=new pe(this,0,null,U.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34]),s,0),this._entityCollectionsTreeNorth=new Ce(this,0,null,U.createFromArray([-180,ct,180,90]),s,0),this._entityCollectionsTreeSouth=new Ce(this,0,null,U.createFromArray([-180,-90,180,Ot]),s,0),this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={}}insertEntity(e,t=!1){e._lonLat.lat>ct?(this._entityCollectionsTreeNorth.__setLonLat__(e),this._entityCollectionsTreeNorth.insertEntity(e,t)):e._lonLat.lat<Ot?(this._entityCollectionsTreeSouth.__setLonLat__(e),this._entityCollectionsTreeSouth.insertEntity(e,t)):(this._entityCollectionsTree.__setLonLat__(e),this._entityCollectionsTree.insertEntity(e,t))}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)}))}dispose(){this._entityCollectionsTree=null,this._entityCollectionsTreeNorth=null,this._entityCollectionsTreeSouth=null,this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={}}insertEntities(e){let t=[],i=[],s=[];for(let r=0,n=e.length;r<n;r++){let n=e[r];n._lonLat.lat>ct?(t.push(n),this._entityCollectionsTreeNorth.__setLonLat__(n)):n._lonLat.lat<Ot?(i.push(n),this._entityCollectionsTreeSouth.__setLonLat__(n)):(s.push(n),this._entityCollectionsTree.__setLonLat__(n))}this._entityCollectionsTree.buildTree(s),this._entityCollectionsTreeNorth.buildTree(t),this._entityCollectionsTreeSouth.buildTree(i)}collectVisibleEntityCollections(e){this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={};let t=this._layer._planet.quadTreeStrategy;this._secondPASS=[],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.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.collectRenderCollectionsPASS1(t._visibleNodesSouth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesSouth,e,this._secondPASS[i].nodeId)}}class La extends Is{constructor(e){super({name:"Earth",...e}),this._visibleNodesNorth={},this._visibleNodesSouth={}}collectVisibleNode(e){let t=e.segment._tileGroup;20===t?this._visibleNodesNorth[e.nodeId]=e:t===Pe?this._visibleNodesSouth[e.nodeId]=e:this._visibleNodes[e.nodeId]=e}_clearVisibleNodes(){super._clearVisibleNodes(),this._visibleNodesNorth={},this._visibleNodesSouth={}}createEntityCollectionsTreeStrategy(e,t){return new Xh(this,e,t)}init(e){this._quadTreeList=[new qt(Aa,this,0,null,0,U.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34])),new qt(Hr,this,0,null,0,U.createFromArray([-180,ct,180,90])),new qt(Hr,this,0,null,0,U.createFromArray([-180,-90,180,Ot]))],super.init(e)}getTileXY(e,t){let i,s,r=function(e,t=ct){return e>t?20:e<-t?Pe:0}(e.lat,ct),n=t,o=1<<n;if(20===r)i=At(e.lon,360/o,-180),s=At(e.lat,(90-ct)/o,90);else if(r===Pe)i=At(e.lon,360/o,-180),s=At(e.lat,(90-ct)/o,Ot);else{let t=Ji(e);i=At(t.lon,Qi/o,-20037508.34),s=At(t.lat,Qi/o,Lt)}return[i,s,n,r]}getLonLatTileOffset(e,t,i,s,r){let n,o=e;e.lat>ct?n=Si(t,i,s,U.createFromArray([-180,ct,180,90])):e.lat<Ot?n=Si(t,i,s,U.createFromArray([-180,-90,180,Ot])):(o=Ji(e),n=Ze(t,i,s));let a=n.getWidth()/(r-1),l=n.getHeight()/(r-1);return[r-Math.ceil((o.lat-n.southWest.lat)/l)-1,Math.floor((o.lon-n.southWest.lon)/a)]}}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,s=13===e[2]?4:3,r=null,n=null;function o(){let t=s;for(var i=s;;i++){if(i>=e.length)throw new Error("Geoid model file: missing newline in header");if(10===e[i]){s=i+1;break}}return i>t&&13===e[i-1]&&i--,String.fromCharCode.apply(null,e.slice(t,i))}for(;"#"===(i=o())[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 (.*)$/))&&(n=parseFloat(t[1]),!isFinite(n)))throw new Error("Geoid model file: bad scale "+t[1]);let a=0,l=0;if((t=i.match(/^\s*(\d+)\s+(\d+)\s*$/))&&(a=parseInt(t[1],10),l=parseInt(t[2],10)),!(t&&a>=0&&l>=0))throw new Error("Geoid model file: bad PGM width&height line");if(65535!=parseInt(o()))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===n)throw new Error("Geoid model file: PGM file does not contain scale");if(a<2||l<2)throw new Error("Geoid model file: Raster size too small");if(e.length-s!=a*l*2)throw new Error("Geoid model file: File has the wrong length");return{scale:n,offset:r,width:a,height:l,rlonres:a/360,rlatres:(l-1)/180,i:s,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 s=2*(t*i.width+e)+i.i;return i.rawfile[s]<<8|i.rawfile[s+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 s=(90-t)*i.rlatres,r=e*i.rlonres,n=Math.floor(s),o=Math.floor(r);r-=o,s-=n,n===i.height-1&&n--,this._cached_ix===o&&this._cached_iy===n||(this._cached_ix=o,this._cached_iy=n,this._v00=this._rawval(o,n),this._v01=this._rawval(o+1,n),this._v10=this._rawval(o,n+1),this._v11=this._rawval(o+1,n+1));let a=(1-s)*((1-r)*this._v00+r*this._v01)+s*((1-r)*this._v10+r*this._v11);return i.offset+i.scale*a}}class Zh{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,s=new L((e[3].lon-e[0].lon)/i,(e[3].lat-e[0].lat)/i),r=new L((e[2].lon-e[1].lon)/i,(e[2].lat-e[1].lat)/i),n=new L((e[1].lon-e[0].lon)/i,(e[1].lat-e[0].lat)/i),o=new L((e[2].lon-e[3].lon)/i,(e[2].lat-e[3].lat)/i);const a=(i+1)*(i+1)*2,l=a/2;let h=new Float32Array(a),c=new Float32Array(a),d=new Array(l),_=0,u=0,f=0,g=new Float32Array(2);for(let t=0;t<=i;t++){let a=new L(e[0].lon+t*s.lon,e[0].lat+t*s.lat),l=new L(e[1].lon+t*r.lon,e[1].lat+t*r.lat);for(let t=0;t<=i;t++){let i=ko(a,l,new L(e[0].lon+t*n.lon,e[0].lat+t*n.lat),new L(e[3].lon+t*o.lon,e[3].lat+t*o.lat));ae(i.lon,g),h[_++]=g[0],c[u++]=g[1],ae(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();ae(t.lon,g),h[2*e]=g[0],c[2*e]=g[1],ae(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 Rt(e,{width:2,height:2,useDepth:!1}),this._framebuffer.init(),this._framebufferMercProj=new Rt(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 X("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 Kh=["loadend","layerloadend"];class Sa{constructor(e=24){this.MAX_REQUESTS=e,this.events=lt(Kh),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.quadTreeStrategy&&t.quadTreeStrategy._terrainCompletedActivated)?(t.events.dispatch(t.events.loadend,t),this.events.dispatch(this.events.layerloadend,t),e.__requestCounterFrame__=0):e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,t)}))}_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 Qh{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 dn(1024),this._lock=new zr}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 X("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 X("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 Rt(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 s=new Float32Array((t+1)*(t+1)*2);for(let e=0;e<=t;e++)for(let r=0;r<=t;r++){let n=2*(e*(t+1)+r);s[n]=r/i-1,s[n+1]=e/i-1}this._verticesBufferArray[t]=this._handler.createArrayBuffer(s,2,s.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,s=Math.sqrt(i)-1;let r=this._verticesBufferArray[s];if(r){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let n=e.normalMapTexturePtr;const o=this._handler,a=o.gl;let l=o.createArrayBuffer(t,3,i,a.DYNAMIC_DRAW);const h=this._framebuffer;let c=o.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(this._normalMapVerticesTexture),c.activate(),a.bindBuffer(a.ARRAY_BUFFER,r),a.vertexAttribPointer(d.a_position,r.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,l),a.vertexAttribPointer(d.a_normal,l.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[s]),a.drawElements(a.TRIANGLE_STRIP,this._indexBufferArray[s].numItems,a.UNSIGNED_INT,0),a.deleteBuffer(l),h.bindOutputTexture(n),c=o.programs.normalMapBlur,c.activate(),a.bindBuffer(a.ARRAY_BUFFER,this._positionBuffer),a.vertexAttribPointer(c._program.attributes.a_position,this._positionBuffer.itemSize,a.FLOAT,!1,0,0),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,this._normalMapVerticesTexture),a.uniform1i(c._program.uniforms.s_texture,0),a.drawArrays(a.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,s=Math.sqrt(i)-1;let r=this._verticesBufferArray[s];if(r){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let n=e.normalMapTexturePtr;const o=this._handler,a=o.gl;let l=o.createArrayBuffer(t,3,i,a.DYNAMIC_DRAW);const h=this._framebuffer,c=o.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(n),c.activate(),a.bindBuffer(a.ARRAY_BUFFER,r),a.vertexAttribPointer(d.a_position,r.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,l),a.vertexAttribPointer(d.a_normal,l.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[s]),a.drawElements(a.TRIANGLE_STRIP,this._indexBufferArray[s].numItems,a.UNSIGNED_INT,0),a.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)}}const _n=new hn({code:"equi",units:Ea}),Ra='(function(){"use strict";let l=null,K=null,O=null,Q=null,S=null,T=null,U=null;function P(a,t){t<0?(t=-t,a+=l.width/2):t>=l.height&&(t=2*(l.height-1)-t,a+=l.width/2),a<0?a+=l.width:a>=l.width&&(a-=l.width);var n=2*(t*l.width+a)+l.i;return l.rawfile[n]<<8|l.rawfile[n+1]}const sa=.5*Math.PI,W=2003750834e-2,ia=Math.PI/W,ua=180/W,X=180/Math.PI,Ma=X*sa,Y=Math.PI/180,da=2*X;let k=0,Z=0,_=null;const B=function(a,t,n){this.x=a,this.y=t,this.z=n};var $=function(a,t,n,o){let f=function(c,C){if(!l)return 0;c<0&&(c+=360);var w=(90-C)*l.rlatres,M=c*l.rlonres,u=Math.floor(w),d=Math.floor(M);M-=d,w-=u,u===l.height-1&&u--,K===d&&O===u||(K=d,O=u,Q=P(d,u),S=P(d+1,u),T=P(d,u+1),U=P(d+1,u+1));let L=null;return L=(1-w)*((1-M)*Q+M*S)+w*((1-M)*T+M*U),l.offset+l.scale*L}(a,t)*n,h=Y*t,r=Y*a,m=Math.sin(h),x=Z/Math.sqrt(1-k*m*m),H=(x+f)*Math.cos(h);o.x=H*Math.cos(r),o.y=H*Math.sin(r),o.z=(x*(1-k)+f)*m},ma=function(a,t,n,o){$(a*ua,da*Math.atan(Math.exp(t*ia))-Ma,n,o)},e=new B(0,0,0),p=new B(0,0,0),y=new B(0,0,0),pa=function(a,t,n){let o=a.x,f=a.y,h=a.z;var r;o>=0?(r=65536*Math.floor(o/65536),t.x=Math.fround(r),n.x=Math.fround(o-r)):(r=65536*Math.floor(-o/65536),t.x=Math.fround(-r),n.x=Math.fround(o+r)),f>=0?(r=65536*Math.floor(f/65536),t.y=Math.fround(r),n.y=Math.fround(f-r)):(r=65536*Math.floor(-f/65536),t.y=Math.fround(-r),n.y=Math.fround(f+r)),h>=0?(r=65536*Math.floor(h/65536),t.z=Math.fround(r),n.z=Math.fround(h-r)):(r=65536*Math.floor(-h/65536),t.z=Math.fround(-r),n.z=Math.fround(h+r))};self.onmessage=function(a){if(a.data.model)l=a.data.model,l.rawfile=a.data.rawfile;else if(a.data.params){let t=549755748352,n=-549755748352,o=549755748352,f=-549755748352,h=549755748352,r=-549755748352;k=a.data.params[8],Z=a.data.params[9];let m=a.data.params[2],x=a.data.params[3],H=a.data.params[10],c=a.data.params[11],C=a.data.params[12],w=a.data.params[13];_=a.data.params[1]===0?ma:$;let M=Math.max(x,m),u=(a.data.params[6]-a.data.params[4])/M,d=(a.data.params[7]-a.data.params[5])/M,L=a.data.params[4],ya=a.data.params[7],aa=Math.max(x/m,1),N=M+1;const z=N*N,R=(m+1)*(m+1)*3;let b=new Float32Array(R),A=new Float64Array(R),F=new Float32Array(R),g=new Float32Array(R),V=new Float32Array(3*z),q=new Float64Array(3*z),v=new Float32Array(3*z),I=new Float32Array(3*z),s=0,i=0;for(let j=0;j<z;j++){let la=j%N,na=~~(j/N);_(L+la*u,ya-na*d,w,e);let D=e.x*H,E=e.y*c,G=e.z*C,J=1/Math.sqrt(D*D+E*E+G*G),oa=D*J,fa=E*J,ha=G*J;pa(e,p,y),q[i]=e.x,v[i]=p.x,I[i]=y.x,V[i++]=oa,q[i]=e.y,v[i]=p.y,I[i]=y.y,V[i++]=fa,q[i]=e.z,v[i]=p.z,I[i]=y.z,V[i++]=ha,na%aa==0&&la%aa==0&&(A[s]=e.x,F[s]=p.x,g[s]=y.x,b[s++]=oa,A[s]=e.y,F[s]=p.y,g[s]=y.y,b[s++]=fa,A[s]=e.z,F[s]=p.z,g[s]=y.z,b[s++]=ha,e.x<t&&(t=e.x),e.x>n&&(n=e.x),e.y<o&&(o=e.y),e.y>f&&(f=e.y),e.z<h&&(h=e.z),e.z>r&&(r=e.z))}let ta=.5*(n-t),ra=.5*(f-o),ea=.5*(r-h),wa=Math.sqrt(ta*ta+ra*ra+ea*ea);self.postMessage({id:a.data.params[0],plainVertices:A,plainVerticesHigh:F,plainVerticesLow:g,plainNormals:b,normalMapNormals:V,normalMapVertices:q,normalMapVerticesHigh:v,normalMapVerticesLow:I,plainRadius:wa},[A.buffer,F.buffer,g.buffer,b.buffer,V.buffer,q.buffer,v.buffer,I.buffer])}}})();\n//# sourceMappingURL=PlainSegmentWorker.worker-CT1cj8jj.js.map\n',co=typeof self<"u"&&self.Blob&&new Blob([Ra],{type:"text/javascript;charset=utf-8"});function Jh(e){let t;try{if(t=co&&(self.URL||self.webkitURL).createObjectURL(co),!t)throw"";const i=new Worker(t,{name:null==e?void 0:e.name});return i.addEventListener("error",(()=>{(self.URL||self.webkitURL).revokeObjectURL(t)})),i}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Ra),{name:null==e?void 0:e.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}class tc extends en{constructor(e=2){super(e,Jh)}_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 s=new Uint8Array(t.rawfile.length);s.set(t.rawfile),e.postMessage({model:i,rawfile:s},[s.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=e._projection.id===zs.id||e._projection.id===_n.id?1:0,s=new Float64Array([this._sourceId,i,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:s},[s.buffer])}else this._pendingQueue.push(e);else this.check()}}const Ma='(function(){"use strict";function H(r,e){return function(z,b){let v=0,N=z.length-1;for(;v<=N;){let n=Math.floor(.5*(v+N));if(Math.abs(z[n]-b)<.001)return n;z[n]<b?v=n+1:N=n-1}return-1}(r,e)!==-1}var y=function(r,e,z){this.x=r,this.y=e,this.z=z},Y=function(r,e,z){let b=r.x,v=r.y,N=r.z;var n;b>=0?(n=65536*Math.floor(b/65536),e.x=Math.fround(n),z.x=Math.fround(b-n)):(n=65536*Math.floor(-b/65536),e.x=Math.fround(-n),z.x=Math.fround(b+n)),v>=0?(n=65536*Math.floor(v/65536),e.y=Math.fround(n),z.y=Math.fround(v-n)):(n=65536*Math.floor(-v/65536),e.y=Math.fround(-n),z.y=Math.fround(v+n)),N>=0?(n=65536*Math.floor(N/65536),e.z=Math.fround(n),z.z=Math.fround(N-n)):(n=65536*Math.floor(-N/65536),e.z=Math.fround(-n),z.z=Math.fround(N+n))};y.prototype.sub=function(r){return new y(this.x-r.x,this.y-r.y,this.z-r.z)},y.prototype.add=function(r){return new y(this.x+r.x,this.y+r.y,this.z+r.z)},y.prototype.cross=function(r){return new y(this.y*r.z-this.z*r.y,this.z*r.x-this.x*r.z,this.x*r.y-this.y*r.x)},y.prototype.normalize=function(r){var e=this.x,z=this.y,b=this.z,v=1/Math.sqrt(e*e+z*z+b*b);return this.x=e*v,this.y=z*v,this.z=b*v,this},y.prototype.distance=function(r){return this.sub(r).length()},y.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)};var x=new y(0,0,0),i=new y(0,0,0),t=new y(0,0,0);self.onmessage=function(r){var e=r.data.elevations,z=r.data.this_plainVertices,b=r.data.this_plainNormals,v=r.data.this_normalMapVertices,N=r.data.this_normalMapNormals,n=r.data.heightFactor,Dr=r.data.gridSize,D=r.data.noDataValues,Hr=r.data.id,Q=549755748352,W=-549755748352,T=549755748352,$=-549755748352,Z=549755748352,X=-549755748352;const J=Math.sqrt(e.length)-1,K=J+1,R=K*K,C=Dr,vr=J/C,L=C+1,tr=n;var a,d,p,m,yr,sr,S=0,xr=0,U=L*L*3,h=new Float64Array(U),j=new Float32Array(U),k=new Float32Array(U),lr=new Uint8Array(L*L),u=v,g=N;if(J>=C){a=new Float32Array(3*R),d=new Float64Array(3*R),p=new Float32Array(3*R),m=new Float32Array(3*R);for(let f=0;f<R;f++){var Ar=f%K,Fr=~~(f/K),ur=f,o=3*ur,rr=e[ur];H(D,rr)&&(rr=0);var Mr=tr*rr,s=new y(u[o]+Mr*g[o],u[o+1]+Mr*g[o+1],u[o+2]+Mr*g[o+2]);if(Y(s,i,t),d[o]=s.x,d[o+1]=s.y,d[o+2]=s.z,p[o]=i.x,p[o+1]=i.y,p[o+2]=i.z,m[o]=t.x,m[o+1]=t.y,m[o+2]=t.z,Fr%vr==0&&Ar%vr==0){let A=new y(u[o],u[o+1],u[o+2]),V=new y(u[o+3],u[o+4],u[o+5]),F=e[ur+1];H(D,F)&&(F=0);let q=!1;if(D.length===0){let _=A.distance(V);q=Math.abs(rr-F)/_>10||rr<-5e3}q?lr[xr]=1:(lr[xr]=0,s.x<Q&&(Q=s.x),s.x>W&&(W=s.x),s.y<T&&(T=s.y),s.y>$&&($=s.y),s.z<Z&&(Z=s.z),s.z>X&&(X=s.z)),j[S]=i.x,k[S]=t.x,h[S++]=s.x,j[S]=i.y,k[S]=t.y,h[S++]=s.y,j[S]=i.z,k[S]=t.z,h[S++]=s.z,xr++}if(Fr!==J&&Ar!==J){var gr=f+1,M=3*gr,B=e[gr];H(D,B)&&(B=0);var cr=tr*B,ar=new y(u[M]+cr*g[M],u[M+1]+cr*g[M+1],u[M+2]+cr*g[M+2]);Y(ar,i,t),d[M]=ar.x,d[M+1]=ar.y,d[M+2]=ar.z,p[M]=i.x,p[M+1]=i.y,p[M+2]=i.z,m[M]=t.x,m[M+1]=t.y,m[M+2]=t.z;var Vr=f+K,c=3*Vr;H(D,B=e[Vr])&&(B=0);var wr=tr*B,nr=new y(u[c]+wr*g[c],u[c+1]+wr*g[c+1],u[c+2]+wr*g[c+2]);Y(nr,i,t),d[c]=nr.x,d[c+1]=nr.y,d[c+2]=nr.z,p[c]=i.x,p[c+1]=i.y,p[c+2]=i.z,m[c]=t.x,m[c+1]=t.y,m[c+2]=t.z;var qr=f+K+1,w=3*qr;H(D,B=e[qr])&&(B=0);var dr=tr*B,er=new y(u[w]+dr*g[w],u[w+1]+dr*g[w+1],u[w+2]+dr*g[w+2]);Y(er,i,t),d[w]=er.x,d[w+1]=er.y,d[w+2]=er.z,p[w]=i.x,p[w+1]=i.y,p[w+2]=i.z,m[w]=t.x,m[w+1]=t.y,m[w+2]=t.z;var Lr=ar.sub(s),Sr=nr.sub(s),Nr=er.sub(s),hr=Sr.cross(Nr).normalize(),zr=Nr.cross(Lr).normalize(),O=zr.add(hr).normalize();a[o]+=O.x,a[o+1]+=O.y,a[o+2]+=O.z,a[M]+=zr.x,a[M+1]+=zr.y,a[M+2]+=zr.z,a[c]+=hr.x,a[c+1]+=hr.y,a[c+2]+=hr.z,a[w]+=O.x,a[w+1]+=O.y,a[w+2]+=O.z}}}else{a=new Float32Array(U),d=new Float64Array(U),p=new Float32Array(U),m=new Float32Array(U),a=new Float32Array(U);var E=C/J,_r=U/3,pr=J+1;for(let f=0;f<_r;f++){let A=Math.floor(f/L),V=f%L,F=A%E,q=V%E,_=Math.floor(A/E)*pr+Math.floor(V/E);V===C&&(_-=1,q=E),A===C&&(_-=pr,F=E);let mr=_+1,fr=_+pr,br=fr+1,or=e[_],ir=e[mr],P=e[fr],G=e[br];H(D,or)&&(or=0),H(D,ir)&&(ir=0),H(D,P)&&(P=0),H(D,G)&&(G=0);let I=or*(1-(yr=q/E))*(1-(sr=F/E))+ir*yr*(1-sr)+P*(1-yr)*sr+G*yr*sr,l=3*f;x.x=z[l]+I*b[l],x.y=z[l+1]+I*b[l+1],x.z=z[l+2]+I*b[l+2],Y(x,i,t),h[l]=x.x,h[l+1]=x.y,h[l+2]=x.z,j[l]=i.x,j[l+1]=i.y,j[l+2]=i.z,k[l]=t.x,k[l+1]=t.y,k[l+2]=t.z,x.x<Q&&(Q=x.x),x.x>W&&(W=x.x),x.y<T&&(T=x.y),x.y>$&&($=x.y),x.z<Z&&(Z=x.z),x.z>X&&(X=x.z)}d.set(h),p.set(j),m.set(k);for(let f=0;f<_r;f++)if(~~(f/L)!==C&&f%L!==C){let A=3*f,V=A+3,F=A+3*L,q=F+3,_=new y(h[A],h[A+1],h[A+2]),mr=new y(h[V],h[V+1],h[V+2]),fr=new y(h[F],h[F+1],h[F+2]),br=new y(h[q],h[q+1],h[q+2]),or=mr.sub(_).normalize(),ir=fr.sub(_).normalize(),P=br.sub(_).normalize(),G=ir.cross(P).normalize(),I=P.cross(or).normalize(),l=I.add(G).normalize();a[A]+=l.x,a[A+1]+=l.y,a[A+2]+=l.z,a[V]+=I.x,a[V+1]+=I.y,a[V+2]+=I.z,a[F]+=G.x,a[F+1]+=G.y,a[F+2]+=G.z,a[q]+=l.x,a[q+1]+=l.y,a[q+2]+=l.z}}self.postMessage({id:Hr,normalMapNormals:a,normalMapVertices:d,normalMapVerticesHigh:p,normalMapVerticesLow:m,terrainVertices:h,terrainVerticesHigh:j,terrainVerticesLow:k,noDataVertices:lr,bounds:[Q,T,Z,W,$,X]},[a.buffer,d.buffer,p.buffer,m.buffer,h.buffer,j.buffer,k.buffer,lr.buffer])}})();\n//# sourceMappingURL=TerrainWorker.worker-DmikdfB2.js.map\n',uo=typeof self<"u"&&self.Blob&&new Blob([Ma],{type:"text/javascript;charset=utf-8"});function ec(e){let t;try{if(t=uo&&(self.URL||self.webkitURL).createObjectURL(uo),!t)throw"";const i=new Worker(t,{name:null==e?void 0:e.name});return i.addEventListener("error",(()=>{(self.URL||self.webkitURL).revokeObjectURL(t)})),i}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Ma),{name:null==e?void 0:e.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}class ic extends en{constructor(e=2){super(e,ec)}_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()}}let Ne=new Float32Array(2);class sc{constructor(e,t=256,i=256){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 X("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 X("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 Rt(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,s=e.programs.vectorTilePolygonRasterization,r=this._width,n=this._height,o=r,a=n,l=o<<1,h=a<<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?(o=l,a=h):(o=r,a=n);let f=g._updateTexture||e.createEmptyTexture_l(o,a),p=u?g._updatePickingMask||e.createEmptyTexture_n(o,a):null;g.applyTexture(f,p),_.setSize(o,a),_.bindOutputTexture(f),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);let m=g.segment.getExtentMerc();ae(m.southWest.lon,Ne),c[0]=Ne[0],d[0]=Ne[1],ae(m.southWest.lat,Ne),c[1]=Ne[0],d[1]=Ne[1],c[2]=2/m.getWidth(),c[3]=2/m.getHeight(),s.activate();let v=s._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,[o,a]),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 Ri extends de{constructor(e={}){super(e.name),this._minDistanceBeforeMemClear=0,this._renderingFadingNodes=(e,t,i,s,r,n,o,a)=>{let l=0===n,h=this.terrain.equalizeVertices;for(let c=0,d=s._fadingNodes.length;c<d;c++){let d=s._fadingNodes[c].segment;e._fadingNodes.has(s._fadingNodes[0].__id)&&!t.has(d.node.__id)&&(t.set(d.node.__id,!0),d._transitionOpacity<1?o.push(d):l?(h&&d.equalize(),d.readyToEngage&&d.engage(),d.screenRendering(i,r,n),a.push(d)):d.screenRendering(i,r,n,this.transparentTexture,!0))}},this._renderingFadingNodesNoDepth=(e,t,i,s,r,n,o)=>{let a=0===n,l=this.terrain.equalizeVertices,h=i.gl;h.disable(h.DEPTH_TEST);for(let h=0,c=s._fadingNodes.length;h<c;h++){let c=s._fadingNodes[h].segment;e._fadingNodes.has(s._fadingNodes[0].__id)&&!t.has(c.node.__id)&&(t.set(c.node.__id,!0),a?(l&&c.equalize(),c.readyToEngage&&c.engage(),c.screenRendering(i,r,n),o.push(c)):c.screenRendering(i,r,n,this.transparentTexture,!0))}h.enable(h.DEPTH_TEST)},this._createdNodesCount=0,this.transitionTime=580,this.ellipsoid=e.ellipsoid||So,this._atmosphere=new Uh(e.atmosphereParameters),this.lightEnabled=!0,this._planetRadius2=(this.ellipsoid.getPolarSize()-1e4)*(this.ellipsoid.getPolarSize()-1e4),this._layers=[],this._updateLayers=!1,this.visibleTileLayers=[],this.visibleVectorLayers=[],this._visibleVectorLayersByDepthOrder=[],this._visibleTileLayerSlices=[],this._visibleEntityCollections=[[]],this.baseLayer=null,this.terrain=null,this.camera=new wa(this,{frustums:e.frustums,eye:new v(25e6,0,0),look:v.ZERO,up:v.NORTH,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude}),this.mousePositionOnEarth=new v,this.emptyTexture=null,this.transparentTexture=null,this.defaultTexture=null,this._initialViewExtent=null,this.layerLock=new zr,this.terrainLock=new zr,this._heightFactor=1,this._indexesCache=[],this._indexesCacheToRemove=[],this._indexesCacheToRemoveCounter=0,this._textureCoordsBufferCache=[];const t={planet:this,maxEqualZoomAltitude:e.maxEqualZoomAltitude,minEqualZoomAltitude:e.minEqualZoomAltitude,minEqualZoomCameraSlope:e.minEqualZoomCameraSlope,transitionOpacityEnabled:e.transitionOpacityEnabled};this.quadTreeStrategyPrototype=e.quadTreeStrategyPrototype||La,this.quadTreeStrategy=new this.quadTreeStrategyPrototype(t),this._nightTexture=null,this._specularTexture=null;let i=jt(e.ambient,new v(.2,.2,.3)),s=jt(e.diffuse,new v(1,1,1)),r=jt(e.specular,new v(63e-5,55e-5,32e-5)),n=e.shininess||18;this._ambient=new Float32Array([i.x,i.y,i.z]),this._diffuse=new Float32Array([s.x,s.y,s.z]),this._specular=new Float32Array([r.x,r.y,r.z,n]),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._maxNodes=e.maxNodesCount||200,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 Zh(this),this._vectorTileCreator=new sc(this,e.vectorTileSize,e.vectorTileSize),this._normalMapCreator=new Qh(this),this._terrainWorker=new ic(3),this._plainSegmentWorker=new tc(3),this._tileLoader=new Sa(e.maxLoadingRequests||12),this._memKey=new Me,this.events=lt(rc),this._distBeforeMemClear=0,this._prevCamEye=new v,this._initialized=!1,this._collectRenderNodesIsActive=!0,this.nightTextureCoefficient=2,this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphereEnabled=e.atmosphereEnabled||!1,this._atmosphereMaxMinOpacity=new Float32Array([.95,.28]),this.solidTextureOne=null,this.solidTextureTwo=null,this._nightTextureSrc=e.nightTextureSrc||null,this._specularTextureSrc=e.specularTextureSrc||null,this._transparentBackground=e.transparentBackground||!1}get terrainReady(){return this.quadTreeStrategy.terrainReady}get maxGridSize(){return this._maxGridSize}getNorthFrameRotation(e){return this.getFrameRotation(e)}getFrameRotation(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=jt(e);this._diffuse=new Float32Array(t.toArray())}set ambient(e){let t=jt(e);this._ambient=new Float32Array(t.toArray())}set specular(e){let t=jt(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]}get sun(){if(this.renderer&&this.renderer.controls.sun)return this.renderer.controls.sun}get sunPos(){return this.sun.sunlight.getPosition()}addControl(e){e.planet=this,e.addTo(this.renderer)}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._heightFactor!==e&&(this._heightFactor=e,this.quadTreeStrategy.destroyBranches(),this.quadTreeStrategy.clearRenderedNodes())}getHeightFactor(){return this._heightFactor}setTerrain(e){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)}))}initAtmosphereShader(e){if(this.renderer&&this.renderer.handler&&this._atmosphereEnabled){let t=this.renderer.handler;t.isWebGl2()?(t.removeProgram("drawnode_screen_wl"),t.addProgram(lo(e))):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(lo(this._atmosphere.parameters)):e.addProgram(ao()),this._transparentBackground||this.renderer.controls.SimpleSkyBackground&&this.renderer.controls.SimpleSkyBackground.deactivate()):(this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphere.deactivate(),this._transparentBackground||(this.renderer.controls.SimpleSkyBackground?this.renderer.controls.SimpleSkyBackground.activate():this.addControl(new ga)),e.isWebGl2()?e.addProgram(new X("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",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\nprecision highp float;in vec3 aVertexPositionHigh;in vec3 aVertexPositionLow;in vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec4 uGlobalTextureCoord;uniform vec3 uNormalMapBias;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;out vec4 vTextureCoord;out vec3 v_vertex;out vec3 cameraPosition;out vec2 vGlobalTextureCoord;out float v_height;void main(void){vec3 aVertexPosition=aVertexPositionHigh+aVertexPositionLow;vec3 nh=height*normalize(aVertexPosition);vTextureCoord.xy=aTextureCoord;vGlobalTextureCoord=uGlobalTextureCoord.xy+(uGlobalTextureCoord.zw-uGlobalTextureCoord.xy)*aTextureCoord;vTextureCoord.zw=uNormalMapBias.z*(aTextureCoord+uNormalMapBias.xy);cameraPosition=eyePositionHigh+eyePositionLow;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);v_height=height;v_vertex=aVertexPosition+nh;gl_Position=projectionMatrix*viewMatrixRTE*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"#version 300 es\nprecision highp float;float getLerpValue(in float min,in float max,in float between){return(clamp(between,min,max)-min)/(max-min);}vec3 aces(vec3 color){float a=2.51;float b=0.03;float c=2.43;float d=0.59;float e=0.14;return clamp((color*(a*color+b))/(color*(c*color+d)+e),0.0,1.0);}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t1,inout float t2){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<-1e-6){return false;}d=max(d,0.0);t1=-b-sqrt(d);t2=-b+sqrt(d);if(t2<0.0){return false;}return true;}bool intersectSphere(vec3 rayOrigin,vec3 rayDirection,float radius,inout float t){float b=dot(rayDirection,rayOrigin);float c=dot(rayOrigin,rayOrigin)-radius*radius;float d=b*b-c;if(d<0.0){return false;}t=-b-sqrt(d);return true;}float intersectSphere(vec3 ro,vec3 rd,vec4 sph){vec3 oc=ro-sph.xyz;float b=dot(oc,rd);float c=dot(oc,oc)-sph.w*sph.w;float h=b*b-c;if(h<0.0)return-1.0;h=sqrt(h);return-b-h;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}t=(-b-sqrt(h))/a;return true;}bool intersectEllipsoid(in vec3 ro,in vec3 rd,in vec3 ra,inout float t1,inout float t2){vec3 ocn=ro/ra;vec3 rdn=rd/ra;float a=dot(rdn,rdn);float b=dot(ocn,rdn);float c=dot(ocn,ocn);float h=b*b-a*(c-1.0);if(h<0.0){return false;}h=sqrt(h);t1=(-b-h)/a;t2=(-b+h)/a;return true;}vec3 normalEllipsoid(in vec3 pos,in vec3 ra){return normalize(pos/(ra*ra));}\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);uniform vec4 specular;uniform vec3 diffuse;uniform vec3 ambient;uniform sampler2D uNormalMap;uniform sampler2D nightTexture;uniform sampler2D specularTexture;uniform sampler2D defaultTexture;uniform sampler2D samplerArr[SLICE_SIZE];uniform vec4 tileOffsetArr[SLICE_SIZE];uniform vec3 lightPosition;uniform float layerOpacityArr[SLICE_SIZE];uniform int samplerCount;uniform float nightTextureCoefficient;uniform float transitionOpacity;uniform float camHeight;in vec4 vTextureCoord;in vec3 v_vertex;in vec3 cameraPosition;in vec2 vGlobalTextureCoord;in float v_height;vec3 sunPos;layout(location=0)out vec4 diffuseColor;void main(void){sunPos=lightPosition;vec3 texNormal=texture(uNormalMap,vTextureCoord.zw).rgb;vec3 normal=normalize((texNormal-0.5)*2.0);float minH=1200000.0;float maxH=minH*3.0;float nightCoef=getLerpValue(minH,maxH,camHeight)*nightTextureCoefficient;vec3 lightDir=normalize(sunPos);vec3 viewDir=normalize(cameraPosition-v_vertex);float overGround=1.0-step(0.1,v_height);float shininess=texture(specularTexture,vGlobalTextureCoord.st).r*255.0*overGround;vec3 reflectionDirection=reflect(-lightDir,normal);float reflection=max(dot(reflectionDirection,viewDir),0.0);vec3 spec=specular.rgb*pow(reflection,specular.w)*shininess;float diffuseLightWeighting=max(dot(normal,lightDir),0.0);vec4 nightImageColor=texture(nightTexture,vGlobalTextureCoord.st);vec3 night=nightStep*(.18-diffuseLightWeighting*3.0)*nightImageColor.rgb*nightCoef;night*=overGround*step(0.0,night);vec4 lightWeighting=vec4(ambient+diffuse*diffuseLightWeighting+night,1.0);diffuseColor=texture(defaultTexture,vTextureCoord.xy);if(samplerCount==0){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}vec4 src;blend(diffuseColor,samplerArr[0],tileOffsetArr[0],layerOpacityArr[0]);if(samplerCount==1){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[1],tileOffsetArr[1],layerOpacityArr[1]);if(samplerCount==2){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[2],tileOffsetArr[2],layerOpacityArr[2]);if(samplerCount==3){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[3],tileOffsetArr[3],layerOpacityArr[3]);if(samplerCount==4){diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;return;}blend(diffuseColor,samplerArr[4],tileOffsetArr[4],layerOpacityArr[4]);diffuseColor=diffuseColor*lightWeighting+vec4(spec,0.0);diffuseColor*=transitionOpacity;}"})):e.addProgram(ao()))}_initializeShaders(){if(!this.renderer)throw new Error("Renderer is not initialized");let e=this.renderer,t=e.handler;t.addProgram(new X("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;attribute vec3 aVertexPositionHigh;attribute vec3 aVertexPositionLow;attribute vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;varying vec2 vTextureCoord;void main(void){vTextureCoord=aTextureCoord;vec3 nh=height*normalize(aVertexPositionHigh+aVertexPositionLow);mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);mat4 m=projectionMatrix*viewMatrixRTE;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;gl_Position=m*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"precision highp float;\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);uniform vec4 tileOffsetArr[SLICE_SIZE];uniform float layerOpacityArr[SLICE_SIZE];uniform sampler2D defaultTexture;uniform sampler2D samplerArr[SLICE_SIZE];uniform int samplerCount;varying vec2 vTextureCoord;void main(void){gl_FragColor=texture2D(defaultTexture,vTextureCoord);if(samplerCount==0)return;vec4 src;blend(gl_FragColor,samplerArr[0],tileOffsetArr[0],layerOpacityArr[0]);if(samplerCount==1)return;blend(gl_FragColor,samplerArr[1],tileOffsetArr[1],layerOpacityArr[1]);if(samplerCount==2)return;blend(gl_FragColor,samplerArr[2],tileOffsetArr[2],layerOpacityArr[2]);if(samplerCount==3)return;blend(gl_FragColor,samplerArr[3],tileOffsetArr[3],layerOpacityArr[3]);if(samplerCount==4)return;blend(gl_FragColor,samplerArr[4],tileOffsetArr[4],layerOpacityArr[4]);}"})),t.addProgram(new X("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;attribute vec3 aVertexPositionHigh;attribute vec3 aVertexPositionLow;attribute vec2 aTextureCoord;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;varying vec2 vTextureCoord;void main(void){vTextureCoord=aTextureCoord;mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);mat4 m=projectionMatrix*viewMatrixRTE;vec3 nh=height*normalize(aVertexPositionHigh+aVertexPositionLow);vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;gl_Position=m*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"precision highp float;\n#ifdef WEBGL2\n#define TEXTURE_FUNC texture\n#else\n#define TEXTURE_FUNC texture2D\n#endif\n#define SLICE_SIZE 5\n#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = TEXTURE_FUNC(SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;\n#define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = TEXTURE_FUNC(SAMPLER, tc); p = TEXTURE_FUNC(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0: 1.0) * COLOR.a);\nconst vec3 nightStep=10.0*vec3(0.58,0.48,0.25);uniform vec4 tileOffsetArr[SLICE_SIZE];uniform vec4 pickingColorArr[SLICE_SIZE];uniform sampler2D samplerArr[SLICE_SIZE];uniform sampler2D pickingMaskArr[SLICE_SIZE];uniform int samplerCount;varying vec2 vTextureCoord;void main(void){gl_FragColor=vec4(0.0);if(samplerCount==0)return;vec2 tc;vec4 t;vec4 p;blendPicking(gl_FragColor,tileOffsetArr[0],samplerArr[0],pickingMaskArr[0],pickingColorArr[0],1.0);if(samplerCount==1)return;blendPicking(gl_FragColor,tileOffsetArr[1],samplerArr[1],pickingMaskArr[1],pickingColorArr[1],1.0);if(samplerCount==2)return;blendPicking(gl_FragColor,tileOffsetArr[2],samplerArr[2],pickingMaskArr[2],pickingColorArr[2],1.0);if(samplerCount==3)return;blendPicking(gl_FragColor,tileOffsetArr[3],samplerArr[3],pickingMaskArr[3],pickingColorArr[3],1.0);if(samplerCount==4)return;blendPicking(gl_FragColor,tileOffsetArr[4],samplerArr[4],pickingMaskArr[4],pickingColorArr[4],1.0);}"})),t.addProgram(new X("drawnode_depth",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3",frustumPickingColor:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"#version 300 es\nprecision highp float;in vec3 aVertexPositionHigh;in vec3 aVertexPositionLow;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform vec3 eyePositionHigh;uniform vec3 eyePositionLow;uniform float height;void main(void){mat4 viewMatrixRTE=viewMatrix;viewMatrixRTE[3]=vec4(0.0,0.0,0.0,1.0);mat4 m=projectionMatrix*viewMatrixRTE;vec3 nh=height*normalize(aVertexPositionHigh+aVertexPositionLow);vec3 eyePosition=eyePositionHigh+eyePositionLow;vec3 vertexPosition=aVertexPositionHigh+aVertexPositionLow;vec3 highDiff=aVertexPositionHigh-eyePositionHigh;vec3 lowDiff=aVertexPositionLow-eyePositionLow+nh;gl_Position=m*vec4(highDiff*step(1.0,length(highDiff))+lowDiff,1.0);}",fragmentShader:"#version 300 es\nprecision highp float;uniform float frustumPickingColor;layout(location=0)out vec4 frustumColor;layout(location=1)out vec4 depthColor;void main(void){frustumColor=vec4(frustumPickingColor,frustumPickingColor,frustumPickingColor,1.0);depthColor=vec4(gl_FragCoord.z,gl_FragCoord.z,gl_FragCoord.z,1.0);}"})),e.addPickingCallback(this,this._renderColorPickingFramebufferPASS),e.addDepthCallback(this,(()=>{this.renderDepthFramebuffer(this.camera,this.quadTreeStrategy)}))}_onLayerLoadend(e){this.events.dispatch(this.events.layerloadend,e)}init(){this._tileLoader.events.on("layerloadend",this._onLayerLoadend,this),$i().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 s=0;s<=e;s++){!this._indexesCache[i][s]&&(this._indexesCache[i][s]=new Array(e));for(let r=0;r<=e;r++){!this._indexesCache[i][s][r]&&(this._indexesCache[i][s][r]=new Array(e));for(let n=0;n<=e;n++){!this._indexesCache[i][s][r][n]&&(this._indexesCache[i][s][r][n]=new Array(e));for(let o=0;o<=e;o++){let e={buffer:null};if(i>=1&&i===s&&i===r&&i===n&&i===o){let t=$i().createSegmentIndexes(i,[s,r,n,o]);e.buffer=this.renderer.handler.createElementArrayBuffer(t,1)}else this._indexesCacheToRemove[t++]=e;this._indexesCache[i][s][r][n][o]=e}}}}}this.renderer.events.on("drawtransparent",(()=>{this._renderScreenNodesWithHeightPASS()})),this._textureCoordsBufferCache=[];let i=$i().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)));if(this.renderer.handler.createDefaultTexture(null,(e=>{this.solidTextureOne=e,this.solidTextureTwo=e})),this.transparentTexture=this.renderer.handler.transparentTexture,this.drawMode=this.renderer.handler.gl.TRIANGLE_STRIP,this._initializeShaders(),this._initializeAtmosphere(),this._updateVisibleLayers(),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.quadTreeStrategy.init(this.camera),this.initLayers(),this._initialized=!0,this._initialViewExtent&&this.viewExtent(this._initialViewExtent),this.renderer.activeCamera=this.camera,this.camera.bindFrustumsPickingColors(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,s=e.length;i<s;i++){let s=e[i];t.deleteBuffer(s.buffer),s.buffer=null}}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._updateLayers=!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(){this.visibleVectorLayers.sort(((e,t)=>e.getZIndex()-t.getZIndex()||e.getHeight()-t.getHeight()));let e={0:[]};for(const t of this.visibleVectorLayers)e[t.depthOrder]||(e[t.depthOrder]=[]),e[t.depthOrder].push(t);if(this._visibleVectorLayersByDepthOrder.length=0,this._visibleVectorLayersByDepthOrder=[],this._visibleVectorLayersByDepthOrder=Object.keys(e).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[Number(t)])),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,s=this.visibleTileLayers.length;i<s;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])}}_renderScreenNodesPASSNoAtmos(){let e=this.camera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodes(this.quadTreeStrategy,t,e,this.quadTreeStrategy._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesPASSAtmos(){let e=this.camera,t=this._setUniformsAtmos(e);this._renderingScreenNodes(this.quadTreeStrategy,t,e,this.quadTreeStrategy._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSNoAtmos(){let e=this.camera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodesWithHeight(this.quadTreeStrategy,t,e,this.quadTreeStrategy._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSAtmos(){let e=this.camera,t=this._setUniformsAtmos(e);this._renderingScreenNodesWithHeight(this.quadTreeStrategy,t,e,this.quadTreeStrategy._renderedNodesInFrustum[e.currentFrustumIndex])}_globalPreDraw(){let e=this.camera;this._distBeforeMemClear+=this._prevCamEye.distance(e.eye),this._prevCamEye.copy(e.eye),this._createdNodesCount>this._maxNodes&&this._distBeforeMemClear>this._minDistanceBeforeMemClear&&(this.terrain.clearCache(),this.memClear()),this._indexesCacheToRemoveCounter>600&&this._clearIndexesCache()}preFrame(){this._updateLayers&&(this._updateLayers=!1,this._updateVisibleLayers()),this.camera.isFirstPass&&(this.camera.update(),this._collectRenderNodesIsActive&&this.quadTreeStrategy.collectRenderNodes(this.camera),this._normalMapCreator.frame(),this._geoImageCreator.frame(),this._vectorTileCreator.frame(),this.camera.checkTerrainCollision(),this.camera.update(),this.events.dispatch(this.events.draw,this),this._collectVectorLayerCollections());for(let e=0;e<this._visibleEntityCollections.length;e++)this.drawEntityCollections(this._visibleEntityCollections[e],e)}frame(){this._renderScreenNodesPASS()}lockQuadTree(){this._collectRenderNodesIsActive=!1,this.camera.setTerrainCollisionActivity(!1)}unlockQuadTree(){this._collectRenderNodesIsActive=!0,this.camera.setTerrainCollisionActivity(!0)}_setUniformsNoAtmos(e){let t,i,s=this.renderer,r=s.handler,n=r.gl;return n.enable(n.CULL_FACE),s.enableBlendOneSrcAlpha(),this.lightEnabled?(r.programs.drawnode_screen_wl.activate(),t=r.programs.drawnode_screen_wl._program,i=t.uniforms,n.uniform3fv(i.lightPosition,this._lightPosition),n.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),n.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(n.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),n.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),n.uniform4fv(i.specular,this.baseLayer._specular||this._specular),n.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(n.uniform3fv(i.diffuse,this._diffuse),n.uniform3fv(i.ambient,this._ambient),n.uniform4fv(i.specular,this._specular),n.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE),n.bindTexture(n.TEXTURE_2D,this._nightTexture||this.transparentTexture),n.uniform1i(i.nightTexture,this.SLICE_SIZE),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE+1),n.bindTexture(n.TEXTURE_2D,this._specularTexture||this.transparentTexture),n.uniform1i(i.specularTexture,this.SLICE_SIZE+1),n.uniform1f(i.camHeight,e.getHeight())):(r.programs.drawnode_screen_nl.activate(),t=r.programs.drawnode_screen_nl._program,i=t.uniforms,n.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),n.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),n.uniform3fv(i.eyePositionHigh,e.eyeHigh),n.uniform3fv(i.eyePositionLow,e.eyeLow),t}_setUniformsAtmos(e){let t,i,s=this.renderer,r=s.handler,n=r.gl;return n.enable(n.CULL_FACE),s.enableBlendOneSrcAlpha(),this.lightEnabled?(r.programs.drawnode_screen_wl.activate(),t=r.programs.drawnode_screen_wl._program,i=t.uniforms,n.uniform3fv(i.lightPosition,this._lightPosition),n.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),n.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(n.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),n.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),n.uniform4fv(i.specular,this.baseLayer._specular||this._specular),n.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(n.uniform3fv(i.diffuse,this._diffuse),n.uniform3fv(i.ambient,this._ambient),n.uniform4fv(i.specular,this._specular),n.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),n.uniform2fv(i.maxMinOpacity,this._atmosphereMaxMinOpacity),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE),n.bindTexture(n.TEXTURE_2D,this._nightTexture||this.transparentTexture),n.uniform1i(i.nightTexture,this.SLICE_SIZE),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE+1),n.bindTexture(n.TEXTURE_2D,this._specularTexture||this.transparentTexture),n.uniform1i(i.specularTexture,this.SLICE_SIZE+1),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE+4),n.bindTexture(n.TEXTURE_2D,s.controls.Atmosphere._transmittanceBuffer.textures[0]),n.uniform1i(i.transmittanceTexture,this.SLICE_SIZE+4),n.activeTexture(n.TEXTURE0+this.SLICE_SIZE+5),n.bindTexture(n.TEXTURE_2D,s.controls.Atmosphere._scatteringBuffer.textures[0]),n.uniform1i(i.scatteringTexture,this.SLICE_SIZE+5),n.uniform1f(i.camHeight,e.getHeight())):(r.programs.drawnode_screen_nl.activate(),t=r.programs.drawnode_screen_nl._program,i=t.uniforms,n.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),n.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),n.uniform3fv(i.eyePositionHigh,e.eyeHigh),n.uniform3fv(i.eyePositionLow,e.eyeLow),t}static __refreshLayersFadingOpacity__(e,t,i){for(let s=e.length-1;s>=0;--s){let r=e[s];r._fading&&r._refreshFadingOpacity(t,i)&&e.splice(s,1)}}_renderingScreenNodes(e,t,i,s){let r=this._visibleTileLayerSlices;r.length&&i.isFirstPass&&Ri.__refreshLayersFadingOpacity__(r[0],e.minCurrZoom,e.maxCurrZoom);let n=new Map,o=[],a=this.terrain.equalizeVertices,l=s.length;if(e._fadingOpaqueSegments=[],i.slope>.8||!this.terrain||this.terrain.isEmpty)for(;l--;){let i=s[l],o=i.segment;this._renderingFadingNodesNoDepth(e,n,t,i,r[0],0,e._fadingOpaqueSegments),a&&o.equalize(),o.readyToEngage&&o.engage(),o.screenRendering(t,r[0],0)}else{for(;l--;){let i=s[l],h=i.segment;this._renderingFadingNodes(e,n,t,i,r[0],0,o,e._fadingOpaqueSegments),h._transitionOpacity<1?o.push(h):(a&&h.equalize(),h.readyToEngage&&h.engage(),h.screenRendering(t,r[0],0))}for(let e=0;e<o.length;e++){let i=o[e];a&&i.equalize(),i.readyToEngage&&i.engage(),i.screenRendering(t,r[0],0)}}}_renderingScreenNodesWithHeight(e,t,i,s){let r=this.renderer.handler.gl;r.enable(r.POLYGON_OFFSET_FILL),r.disable(r.CULL_FACE);let n=new Map,o=[],a=this._visibleTileLayerSlices;for(let l=1,h=a.length;l<h;l++){i.isFirstPass&&Ri.__refreshLayersFadingOpacity__(a[l],e.minCurrZoom,e.maxCurrZoom),r.polygonOffset(0,-l);let h=s.length;for(;h--;){let i=s[h];this._renderingFadingNodes(e,n,t,i,a[l],l,o),i.segment._transitionOpacity<1?i.segment.initSlice(l):i.segment.screenRendering(t,a[l],l,this.transparentTexture,!0)}}r.disable(r.POLYGON_OFFSET_FILL),r.enable(r.CULL_FACE)}_renderColorPickingFramebufferPASS(){let e,t=this.renderer,i=t.handler,s=i.gl;i.programs.drawnode_colorPicking.activate(),e=i.programs.drawnode_colorPicking._program;let r=e.uniforms,n=t.activeCamera;s.enable(s.CULL_FACE),s.uniformMatrix4fv(r.viewMatrix,!1,n.getViewMatrix()),s.uniformMatrix4fv(r.projectionMatrix,!1,n.getProjectionMatrix()),s.uniform3fv(r.eyePositionHigh,n.eyeHigh),s.uniform3fv(r.eyePositionLow,n.eyeLow);let o=this.quadTreeStrategy._renderedNodesInFrustum[n.getCurrentFrustum()],a=this._visibleTileLayerSlices,l=o.length;for(;l--;)o[l].segment._transitionOpacity>=1&&o[l].segment.colorPickingRendering(e,a[0],0);for(let t=0;t<this.quadTreeStrategy._fadingOpaqueSegments.length;++t)this.quadTreeStrategy._fadingOpaqueSegments[t].colorPickingRendering(e,a[0],0);s.enable(s.POLYGON_OFFSET_FILL);for(let t=1,i=a.length;t<i;t++)for(l=o.length,s.polygonOffset(0,-t);l--;)o[l].segment.colorPickingRendering(e,a[t],t,this.transparentTexture,!0);s.disable(s.POLYGON_OFFSET_FILL)}renderDepthFramebuffer(e,t){let i,s=this.renderer.handler,r=s.gl;s.programs.drawnode_depth.activate(),i=s.programs.drawnode_depth._program;let n=i.uniforms;r.disable(r.BLEND),r.disable(r.POLYGON_OFFSET_FILL),r.uniformMatrix4fv(n.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.eyeHigh),r.uniform3fv(n.eyePositionLow,e.eyeLow),r.uniform1f(n.frustumPickingColor,e.frustumColorIndex);let o=t._renderedNodesInFrustum[e.getCurrentFrustum()],a=this._visibleTileLayerSlices,l=o.length;for(;l--;)o[l].segment._transitionOpacity>=1&&o[l].segment.depthRendering(i,a[0]);for(let e=0;e<t._fadingOpaqueSegments.length;++e)t._fadingOpaqueSegments[e].depthRendering(i,a[0]);r.enable(r.BLEND)}_collectVectorLayerCollections(){let e=this._visibleVectorLayersByDepthOrder.length;this._visibleEntityCollections.length=0,this._visibleEntityCollections=new Array(e);for(let e=0;e<this._visibleEntityCollections.length;e++)this._visibleEntityCollections[e]=[];for(;e--;){let t=this._visibleVectorLayersByDepthOrder[e],i=t.length;for(;i--;){let s=t[i];s._fading&&s._refreshFadingOpacity(this.quadTreeStrategy.minCurrZoom,this.quadTreeStrategy.maxCurrZoom)&&(t.splice(i,1),0===t.length&&this._visibleVectorLayersByDepthOrder.splice(e,1)),s.collectVisibleCollections(this._visibleEntityCollections[e]),s.update()}}}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.project3v(e)}getPixelFromLonLat(e){let t=this.ellipsoid.lonLatToCartesian(e);if(t)return this.renderer.activeCamera.project3v(t)}getDistanceFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return t.distance(this.renderer.activeCamera.eye)}getDistanceFromPixel(e){return this.renderer.getDistanceFromPixel(e)||this.getDistanceFromPixelEllipsoid(e)||0}viewExtent(e){this.camera?this.camera.viewExtent(e):this._initialViewExtent=e}viewExtentArr(e){this.viewExtent(new U(new L(e[0],e[1]),new L(e[2],e[3])))}getExtent(){if(this.renderer){let e=this.renderer.handler.getWidth(),t=this.renderer.handler.getHeight(),i=[this.getLonLatFromPixelTerrain(new H(0,0)),this.getLonLatFromPixelTerrain(new H(e,0)),this.getLonLatFromPixelTerrain(new H(e,t)),this.getLonLatFromPixelTerrain(new H(0,t))];if(i[0]&&i[1]&&i[2]&&i[3]){let e=i[0].lon,t=i[2].lat,s=i[1].lon,r=i[0].lat;for(let n=0;n<i.length;n++)i[n].lon>s&&(s=i[n].lon),i[n].lat>r&&(r=i[n].lat),i[n].lon<e&&(e=i[n].lon),i[n].lat<t&&(t=i[n].lat);return new U(new L(e,t),new L(s,r))}}return this.quadTreeStrategy._viewExtent}getViewExtent(){return this.quadTreeStrategy._viewExtent}viewLonLat(e,t,i){this.camera.setLonLat(e,t,i)}flyExtent(e,t,i={}){this.camera.flyExtent(e,t,i)}flyCartesian(e,t){this.camera.flyCartesian(e,t)}flyLonLat(e,t={}){this.camera.flyLonLat(e,t)}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 _t&&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.quadTreeStrategy._renderedNodes,s=i.length;for(;s--;)if(i[s].segment.isEntityInside(e))return i[s].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.quadTreeStrategy.clearRenderedNodes()}destroy(){var e;this._terrainWorker.destroy(),this._plainSegmentWorker.destroy(),null==(e=this.renderer)||e.destroy(),this.onremove(),super.destroy()}}const rc=["draw","layeradd","baselayerchange","layerremove","layervisibilitychange","rendercompleted","terraincompleted","layerloadend"];class fn extends de{constructor(e){super("skybox"),this.params=e,this.vertexPositionBuffer=null,this.texture=null}static createDefault(e){return new fn({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 X("skybox",{uniforms:{projectionViewMatrix:{type:ht.MAT4},uSampler:{type:ht.SAMPLERCUBE},pos:{type:ht.VEC3}},attributes:{aVertexPosition:{type:ht.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 }"})),this.texture=this.renderer.handler.loadCubeMapTexture(this.params),this._createBuffers(),this.drawMode=this.renderer.handler.gl.TRIANGLES}preFrame(){let e=this.renderer.handler,t=e.gl,i=this.renderer.activeCamera;t.disable(t.DEPTH_TEST),e.programs.skybox.activate();let s=e.programs.skybox._program,r=s.uniforms;if(i.isOrthographic){const e=i.frustum.near,s=i.frustum.far,n=i.getAspectRatio(),o=e*Math.tan(i.viewAngle*Qt),a=o*n,l=(new tt).setPerspective(-a,a,-o,o,e,s),h=(new tt).set(i.getViewMatrix());t.uniformMatrix4fv(r.projectionViewMatrix,!1,l.mul(h)._m)}else 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 n=this.vertexPositionBuffer;t.bindBuffer(t.ARRAY_BUFFER,n),t.vertexAttribPointer(s.attributes.aVertexPosition,n.itemSize,t.FLOAT,!1,0,0),t.drawArrays(this.drawMode,0,n.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)}}const Hc=Object.freeze(Object.defineProperty({__proto__:null,Axes:class extends de{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 X("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:Ri,RenderNode:de,SkyBox:fn},Symbol.toStringTag,{value:"Module"})),Bs=class e{constructor(t={}){this.__id=e.__counter__++,this.equalizeVertices=t.equalizeVertices||!1,this.equalizeNormals=!1,this.isEmpty=!0,this.name=t.name||"empty",this.minZoom=t.minZoom||2,this.maxZoom=t.maxZoom||19,this.maxNativeZoom=t.maxNativeZoom||this.maxZoom,this.gridSizeByZoom=t.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=t.geoid||new Pa({src:t.geoidSrc||null}),this._isReady=!1}setUrlRewriteCallback(e){}get isIdle(){return!0}isEqual(e){return e.__id===this.__id}static checkNoDataValue(e,t){return-1!==Xr(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){}};Bs.__counter__=0;let Mi=Bs;class gn extends Mi{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=lt(nc,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=$r(t.extent,new U(new L(-180,-90),new L(180,90))),this._dataType="arrayBuffer",this._maxNodeZoom=this.gridSizeByZoom.length-1,this._elevationCache={},this._fetchCache={},this._cache=t.cache||"default",this._loader=new Sa,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,s){if(!e||e.lat>ct||e.lat<Ot)return t(0),!0;s=null==s||s;const[r,n,o,a]=this._planet.quadTreeStrategy.getTileXY(e,i||this.maxZoom);let l=zt.getTileIndex(r,n,o,a),h=this.getElevationCache(l),c=Ji(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._urlRewriteCallback&&this._urlRewriteCallback(r,n,o,a)||this.buildURL(r,n,o,a),type:this._dataType,options:{cache:this._cache}}),this._fetchCache[l]=i),i.then((i=>{let h=Ze(r,n,o);if("ready"===i.status){let e={heights:this._createHeights(i.data,null,a,r,n,o,h),extent:h};this.setElevationCache(l,e),t(this._getGroundHeightMerc(c,e))}else if("error"===i.status){if(s&&o>this.maxNativeZoom)return s=!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(),s=Math.sqrt(t.heights.length),r=i/(s-1),n=s-Math.ceil((e.lat-t.extent.southWest.lat)/r)-1,o=Math.floor((e.lon-t.extent.southWest.lon)/r),a=(n+1)*s+o,l=a+1,h=n*s+o,c=h+1,d=t.heights[a],_=t.heights[l],u=t.heights[h],f=t.heights[c],g=new v(t.extent.southWest.lon+r*o,d,t.extent.northEast.lat-r*n-r),p=new v(g.x+r,_,g.z),m=new v(g.x,u,g.z+r),y=new v(g.x+r,f,g.z+r),x=new v(e.lon,1e5,e.lat),b=new V(x,new v(0,-1,0)),w=new v,T=b.hitTriangleRes(g,p,m,w);return T===V.INSIDE?w.y:(T=b.hitTriangleRes(p,y,m,w),T===V.INSIDE?w.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,options:{cache:this._cache},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,s){return Dt(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,s,r,n,o,a){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 nc=["load","loadend"];class Ds extends zt{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(oc),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,this._cache=t.cache||"default"}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:{cache:this._cache}},(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 Dt(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,s=i.node,r=!1,n=this.__id,o=e;for(;s.parentNode;)if(s=s.parentNode,o=s.segment.materials[n],o&&o.textureExists){r=!0;break}if(i.passReady){let r=e.layer.maxNativeZoom;if(s.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 s=t.segment.materials[e.layer.__id];s?!s.isLoading&&!s.isReady&&this.loadMaterial(s,!0):(s=t.segment.materials[e.layer.__id]=e.layer.createMaterial(t.segment),this.loadMaterial(s,!0))}}if(r){e.appliedNode=s,e.appliedNodeId=s.nodeId,e.texture=o.texture;let t=1/(2<<i.tileZoom-s.segment.tileZoom-1);e.texOffset[0]=i.tileX*t-s.segment.tileX,e.texOffset[1]=i.tileY*t-s.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;90===e.northEast.lat&&(t.northEast.lat=20087508.34),180===e.northEast.lon&&(t.northEast.lon=20087508.34),-90===e.southWest.lat&&(t.southWest.lat=-20087508.34),-180===e.southWest.lon&&(t.southWest.lon=-20087508.34)}}const oc=["load","loadend"];class me extends Ds{constructor(e,t){super(e,t),this._extra=new URLSearchParams(t.extra).toString(),t.extent||this.setExtent(new U(new L(-180,-90),new L(180,90))),this.layers=t.layers,this.imageWidth=t.imageWidth||256,this.imageHeight=t.imageHeight||256,this._getBbox=me.get_bbox_v1_1_1,this._version="",this.setVersion(t.version)}static createRequestUrl(e,t,i="image/png",s="1.1.1",r="GetMap",n,o,a=256,l=256,h){return`${e}?LAYERS=${t}&FORMAT=${i}&SERVICE=WMS&VERSION=${s}&REQUEST=${r}&SRS=${n}&BBOX=${o}&WIDTH=${a}&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,t){return"epsg:4326"===t?`${e.getSouth()},${e.getWest()},${e.getNorth()},${e.getEast()}`:`${e.getWest()},${e.getSouth()},${e.getEast()},${e.getNorth()}`}_checkSegment(e){return!0}get instanceName(){return"WMS"}_createUrl(e){return me.createRequestUrl(this.url,this.layers,"image/png",this._version,"GetMap",e._projection.code,this._getBbox(e.getExtent(),e._projection.code),this.imageWidth,this.imageHeight,this._extra)}setVersion(e){this._version=e||"1.1.1","1.1.1"===this._version?this._getBbox=me.get_bbox_v1_1_1:"1.3.0"===e&&(this._getBbox=me.get_bbox_v1_3_0)}_correctFullExtent(){const e=this._extent,t=this._extentMerc;90===e.northEast.lat&&(t.northEast.lat=20087508.34),180===e.northEast.lon&&(t.northEast.lon=20087508.34),-90===e.southWest.lat&&(t.southWest.lat=-20087508.34),-180===e.southWest.lon&&(t.southWest.lon=-20087508.34)}}class je extends gn{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:Ki(this._imageSize)?this._imageSize/2:$e(this._imageSize)/2,this._dataType="arrayBuffer"}isBlur(e){return e.tileZoom>=18}_createUrl(e){return me.createRequestUrl(this.url,this._layers,this._format,"1.1.1","GetMap",e._projection.code,me.get_bbox_v1_1_1(e.getExtent()),this._imageSize,this._imageSize)}_createHeights(e,t,i,s,r,n,o,a){let l=new Int16Array(e);if(!Ki(this._imageSize)){let e=new Float32Array(l.length);return function(e,t){for(let i=0,s=t.length;i<s;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,s){let r=Math.sqrt(i.length)-1,n=r+1,o=Math.sqrt(e.length),a=o/r,l=0,h=0;for(let c=0,d=0,_=e.length;c<_;c++){let _=e[c],u=je.checkNoDataValue(t,_),f=!1,g=!1,p=Math.floor(c/o),m=c%o,v=Math.floor(m/r),y=Math.floor(p/r),x=s[y][v],b=p%r,w=m%r,T=(b+y)*n+w+v;if(x[T]=_,(p+y)%a==0&&(m+v)%a==0&&(i[d++]=_),(m+1)%r==0&&m!==o-1){l=e[c],f=je.checkNoDataValue(t,l);let o=_;u||f||(o=.5*(_+l)),T=(b+y)*n+w+1,x[T]=o,(p+y)%a==0&&(i[d++]=o);let h=(b+y)*n+(w+1)%r;s[y][v+1][h]=o}if((p+1)%r==0&&p!==o-1){h=e[c+o],g=je.checkNoDataValue(t,h);let l=_;u||g||(l=.5*(_+h)),T=(b+1)*n+w+v,x[T]=l,(m+v)%a==0&&(i[d++]=l);let f=(b+1)%r*n+w+v;s[y+1][v][f]=l}if((m+1)%r==0&&m!==o-1&&(p+1)%r==0&&p!==o-1){let a=e[c+o+1],p=je.checkNoDataValue(t,a),m=_;u||f||g||p||(m=.25*(_+l+h+a)),T=(b+1)*n+(w+1),x[T]=m,i[d++]=m;let C=(b+1)*n;s[y][v+1][C]=m;let E=r;s[y+1][v][E]=m;let A=0;s[y+1][v+1][A]=m}}}(l,this.noDataValues,d,c);let _=zt.getTileIndex(s,r,n,i);this.setElevationCache(_,{heights:d,extent:o});let u=this._imageSize/this.plainGridSize;for(let e=0;e<u;e++)for(let t=0;t<u;t++){let o=2*s+t,a=2*r+e,l=n+1,h=zt.getTileIndex(o,a,l,i);this.setElevationCache(h,{heights:c[e][t],extent:Ze(o,a,l)})}return d}}class St extends gn{constructor(e,t={}){super(e||"RgbTerrain",{equalizeVertices:null==t.equalizeVertices||t.equalizeVertices,maxZoom:t.maxZoom||17,noDataValues:t.noDataValues||[null!=t.minHeight?t.minHeight:-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={},this._minHeight=t.minHeight||-1e4,this._resolution=t.resolution||.1}static checkNoDataValue(e,t){return t>5e4||-1!==Xr(e,t)}rgb2Height(e,t,i){return 255===e?this._minHeight:this._minHeight+this._resolution*(256*e*256+256*t+i)}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,s,r,n,o,a){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(!Ki(this._imageSize)&&h===this._imageSize){let e=new Float32Array(h*h);return this.extractElevationTilesRgbNonPowerOfTwo(l,e,this._heightFactor),e}if(this._imageSize===this.plainGridSize){let e=(this.plainGridSize+1)*(this.plainGridSize+1),i=new Float32Array(e),[s,r,n]=t?rr(t.tileX,t.tileY,t.tileZoom,c,d,_):[0,0,0];return this.extractElevationSimple(l,this.noDataValues,u,s,r,n,f,i,this._heightFactor,this._imageSize),i}let g=(this.plainGridSize+1)*(this.plainGridSize+1),p=h/this.plainGridSize,m=new Float32Array(g),v=new Array(p);for(let e=0;e<p;e++){v[e]=[];for(let t=0;t<p;t++)v[e][t]=new Float32Array(g)}if(a)this.extractElevationTilesRgbNoChildren(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,f,m);else{this.extractElevationTilesRgb(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,f,m,v);for(let e=0;e<p;e++)for(let t=0;t<p;t++){let[o,a,l]=[2*s+t,2*r+e,n+1],h=zt.getTileIndex(o,a,l,i);this.setElevationCache(h,{heights:v[e][t],extent:Ze(o,a,l)})}}let y=zt.getTileIndex(s,r,n,i);return this.setElevationCache(y,{heights:m,extent:o}),m}getHeightAsync(e,t,i){if(0===(i=i??this.maxZoom))return t(0),!0;const s=this._planet.quadTreeStrategy,[r,n,o,a]=s.getTileXY(e,i),[l,h]=s.getLonLatTileOffset(e,r,n,o,this._imageSize),c=4*(l*this._imageSize+h),d=zt.getTileIndex(r,n,o,a);if(this._imageDataCache[d]){let s=this._imageDataCache[d],r=this._heightFactor*this.rgb2Height(s[c],s[c+1],s[c+2]);return St.checkNoDataValue(this.noDataValues,r)?this.getHeightAsync(e,t,i-1):(t(this._heightFactor*this.rgb2Height(s[c],s[c+1],s[c+2])),!0)}let _=this._fetchCache[d];return _||(_=this._loader.fetch({src:this._urlRewriteCallback&&this._urlRewriteCallback(r,n,o,a)||this.buildURL(r,n,o,a),type:this._dataType,options:{cache:this._cache}}),this._fetchCache[d]=_),_.then((s=>{if("ready"===s.status){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(s.data,0,0);let r=this._ctx.getImageData(0,0,256,256).data;this._imageDataCache[d]=r;let n=this._heightFactor*this.rgb2Height(r[c],r[c+1],r[c+2]);if(St.checkNoDataValue(this.noDataValues,n))return this.getHeightAsync(e,t,i-1);t(this._heightFactor*this.rgb2Height(r[c],r[c+1],r[c+2]))}else{if("error"===s.status)return this.getHeightAsync(e,t,i-1);this._fetchCache[d]=null,delete this._fetchCache[d]}})),!1}extractElevationSimple(e,t,i=null,s,r,n,o,a,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*this.rgb2Height(e[u],e[u+1],e[u+2]);(St.checkNoDataValue(t,f)||0===f)&&i&&(f=Xt(n,s,r,i,_,d,o)),a[_*(h+1)+d]=f}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(c*h+d),u=l*this.rgb2Height(e[_],e[_+1],e[_+2]);(St.checkNoDataValue(t,u)||0===u)&&i&&(u=Xt(n,s,r,i,c,d,o)),a[c*(h+1)+h]=u}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(d*h+c),u=l*this.rgb2Height(e[_],e[_+1],e[_+2]);(St.checkNoDataValue(t,u)||0===u)&&i&&(u=Xt(n,s,r,i,d,c,o)),a[h*(h+1)+c]=u}let c=l*this.rgb2Height(e[e.length-4],e[e.length-3],e[e.length-2]);(St.checkNoDataValue(t,c)||0===c)&&i&&(c=Xt(n,s,r,i,h-1,h-1,o)),a[a.length-1]=c}extractElevationTilesRgbNonPowerOfTwo(e,t,i=1){for(let s=0,r=t.length;s<r;s++){let r=4*s;t[s]=i*this.rgb2Height(e[r],e[r+1],e[r+2])}}extractElevationTilesRgb(e,t,i,s=null,r,n,o,a,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]=rr(a,l,h,r,n,o);for(let r=0,n=0,o=e.length/4;r<o;r++){let o=4*r,a=t*this.rgb2Height(e[o],e[o+1],e[o+2]),l=St.checkNoDataValue(i,a),h=!1,T=!1,C=Math.floor(r/g),E=r%g;(l||0===a)&&s&&(a=Xt(w,x,b,s,Math.floor(C/p),Math.floor(E/p),c));let A=Math.floor(E/u),L=Math.floor(C/u),P=_[L][A],S=C%u,R=E%u,M=(S+L)*f+R+A;if(P[M]=a,(C+L)%p==0&&(E+A)%p==0&&(d[n++]=a),(E+1)%u==0&&E!==g-1){m=t*this.rgb2Height(e[o+4],e[o+5],e[o+6]),h=St.checkNoDataValue(i,m),(h||0===m)&&s&&(m=Xt(w,x,b,s,Math.floor(C/p),Math.floor((E+1)/p),c));let r=a;l||h||(r=.5*(a+m)),M=(S+L)*f+R+1,P[M]=r,(C+L)%p==0&&(d[n++]=r);let g=(S+L)*f+(R+1)%u;_[L][A+1][g]=r}if((C+1)%u==0&&C!==g-1){y=4*g,v=t*this.rgb2Height(e[o+y],e[o+y+1],e[o+y+2]),T=St.checkNoDataValue(i,v),(T||0===v)&&s&&(v=Xt(w,x,b,s,Math.floor((C+1)/p),Math.floor(E/p),c));let r=.5*(a+v);l||T||(r=.5*(a+v)),M=(S+1)*f+R+A,P[M]=r,(E+A)%p==0&&(d[n++]=r);let h=(S+1)%u*f+R+A;_[L+1][A][h]=r}if((E+1)%u==0&&E!==g-1&&(C+1)%u==0&&C!==g-1){let r=t*this.rgb2Height(e[o+y+4],e[o+y+5],e[o+y+6]),g=St.checkNoDataValue(i,r);(g||0===r)&&s&&(r=Xt(w,x,b,s,Math.floor((C+1)/p),Math.floor((E+1)/p),c));let B=a;l||h||T||g||(B=.25*(a+m+v+r)),M=(S+1)*f+(R+1),P[M]=B,d[n++]=B;let k=(S+1)*f;_[L][A+1][k]=B;let I=u;_[L+1][A][I]=B;let z=0;_[L+1][A+1][z]=B}}}extractElevationTilesRgbNoChildren(e,t,i,s=null,r,n,o,a,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]=rr(a,l,h,r,n,o);for(let r=0,n=0,o=e.length/4;r<o;r++){let o=4*r,a=t*this.rgb2Height(e[o],e[o+1],e[o+2]),l=St.checkNoDataValue(i,a),h=!1,w=!1,T=Math.floor(r/f),C=r%f;(l||0===a)&&s&&(a=Xt(b,y,x,s,Math.floor(n/u),n%u,c));let E=Math.floor(C/_),A=Math.floor(T/_);if((T+A)%g==0&&(C+E)%g==0&&(d[n++]=a),(C+1)%_==0&&C!==f-1){p=t*this.rgb2Height(e[o+4],e[o+5],e[o+6]),h=St.checkNoDataValue(i,p),(h||0===p)&&s&&(p=Xt(b,y,x,s,Math.floor(n/u),n%u,c));let r=a;l||h||(r=.5*(a+p)),(T+A)%g==0&&(d[n++]=r)}if((T+1)%_==0&&T!==f-1){v=4*f,m=t*this.rgb2Height(e[o+v],e[o+v+1],e[o+v+2]),w=St.checkNoDataValue(i,m),(w||0===m)&&s&&(m=Xt(b,y,x,s,Math.floor(n/u),n%u,c));let r=.5*(a+m);l||w||(r=.5*(a+m)),(C+E)%g==0&&(d[n++]=r)}if((C+1)%_==0&&C!==f-1&&(T+1)%_==0&&T!==f-1){let r=t*this.rgb2Height(e[o+v+4],e[o+v+5],e[o+v+6]),_=St.checkNoDataValue(i,r);(_||0===r)&&s&&(r=Xt(b,y,x,s,Math.floor(n/u),n%u,c));let f=a;l||h||w||_||(f=.25*(a+p+m+r)),d[n++]=f}}}}function rr(e,t,i,s,r,n){let o=2<<i-n-1;return[e-o*s,t-o*r,1/o]}function Xt(e,t,i,s,r,n,o){let a=Math.sqrt(s.length),l=s[Math.floor(i*e*a+r*e)*a+Math.floor(t*e*a+n*e)];return o&&l>0?0:l}const ac={[Le]:"north",[Pe]:"south"},lc=(e,t,i,s)=>{let r=ac[s];if(r)return`https://terrain.openglobus.org/poles/${r}/${i}/${e}/${t}.png`};class hc extends St{constructor(e,t){super(e||"GlobusEarthRgb",{maxNativeZoom:6,maxZoom:17,url:"https://{s}.terrain.openglobus.org/all/{z}/{x}/{y}.png",urlRewrite:lc,...t})}isReadyToLoad(e){return this._extent.overlaps(e.getExtentLonLat())}}const Vc=Object.freeze(Object.defineProperty({__proto__:null,BilTerrain:je,EmptyTerrain:Mi,GlobusRgbTerrain:hc,GlobusTerrain:gn,RgbTerrain:St},Symbol.toStringTag,{value:"Module"}));class cc extends Ai{constructor(e,t={}){super(e,t),this._sourceTexture=t.texture||null,t.texture&&(this._sourceReady=!0,this._sourceCreated=!0),this._frameWidth=null!=t.frameWidth?$e(t.frameWidth):256,this._frameHeight=null!=t.frameHeight?$e(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 dc extends Ai{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 uc extends _t{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),s=parseInt(e.slice(4,6),16);return`rgba(${parseInt(e.slice(6,8),16)},${s},${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")),s=i&&i.length>0?i[0].innerHTML.trim():"",{iconHeading:r,iconURL:n,iconColor:o,lineWidth:a,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,s,r]=i;h.push(new L(e,s,r)),e<t.southWest.lon&&(t.southWest.lon=e),s<t.southWest.lat&&(t.southWest.lat=s),e>t.northEast.lon&&(t.northEast.lon=e),s>t.northEast.lat&&(t.northEast.lat=s)}}if(1===h.length){const e=.01745329*r;return new G({name:s,lonlat:h[0],billboard:{src:n,size:[24,24],color:o,rotation:e},properties:{color:o,heading:r}})}return new G({name:s,polyline:{pathLonLat:[h],thickness:a,color:l,isClosed:!1},properties:{name:s}})}_extractStyle(e){let t,i,s,r,n;const o=e.getElementsByTagName("Style")[0];if(o){let e=o.getElementsByTagName("IconStyle")[0];if(e){let r=e.getElementsByTagName("color")[0];r&&(t=this._AGBRtoRGBA(r.innerHTML.trim()));let n=e.getElementsByTagName("heading")[0];if(n){const e=parseFloat(n.innerHTML.trim());e>=0&&e<=360&&(i=e%360)}let o=e.getElementsByTagName("Icon")[0];if(o){let e=o.getElementsByTagName("href")[0];e&&(s=e.innerHTML.trim())}}let a=o.getElementsByTagName("LineStyle")[0];if(a){let e=a.getElementsByTagName("color")[0];e&&(r=this._AGBRtoRGBA(e.innerHTML.trim()));let t=a.getElementsByTagName("width")[0];void 0!==t&&(n=parseFloat(t.innerHTML.trim()))}}return t||(t="#FFFFFF"),i||(i=0),s||(s="https://openglobus.org/examples/billboards/carrot.png"),r||(r="#FFFFFF"),n||(n=1),{iconHeading:i,iconURL:s,iconColor:t,lineWidth:n,lineColor:r}}_parseKML(e,t,i){if(i||(i=[]),"kml"!==e.documentElement.nodeName)return i;for(const s of e.getElementsByTagName("Placemark")){const e=this._kmlPlacemarkToEntity(s,t);e&&i.push(e)}return i}_convertKMLintoEntities(e){const t=new U(new L(180,90),new L(-180,-90));return{entities:this._parseKML(e,t),extent:t}}_convertCoordonatesIntoEntities(e,t,i){const s=new U(new L(180,90),new L(-180,-90)),r=e=>{const t=e[0],i=e[1];t<s.southWest.lon&&(s.southWest.lon=t),i<s.southWest.lat&&(s.southWest.lat=i),t>s.northEast.lon&&(s.northEast.lon=t),i>s.northEast.lat&&(s.northEast.lat=i)},n=[];return e.forEach((e=>e.forEach((e=>n.push(e))))),{entities:n.map((e=>{if(1===e.length){const t=e[0],s=new G({lonlat:t,billboard:i});return r(t),s}if(e.length>1){const i=e.map((e=>(r(e),new L(e[0],e[1],e[2]))));return new G({polyline:{pathLonLat:[i],thickness:3,color:t,isClosed:!1}})}})),extent:s}}_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 s=(await Promise.all(e.map(this._getXmlContent))).map(this._extractCoordonatesFromKml),{entities:r,extent:n}=this._convertCoordonatesIntoEntities(s,t||this._color,i||this._billboard);return this._extent=this._expandExtents(this._extent,n),r.forEach(this.add.bind(this)),{entities:r,extent:n}}setColor(e){this._color=e,this._billboard.color=e}_getKmlFromUrl(e){return new Promise(((t,i)=>{const s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="document",s.overrideMimeType("text/xml"),s.onload=()=>{s.readyState===s.DONE&&200===s.status?t(s.responseXML):i(new Error("no valid kml file"))},s.send()}))}async addKmlFromUrl(e,t,i){const s=await this._getKmlFromUrl(e),{entities:r,extent:n}=this._convertKMLintoEntities(s);return this._extent=this._expandExtents(this._extent,n),r.forEach(this.add.bind(this)),{entities:r,extent:n}}}class _c extends Ds{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 fc(e,t,i){var s="";for(let o=i;o>0;o--){var r=0,n=1<<o-1;e&n&&r++,t&n&&(r+=2),s+=r.toString()}return s}class gc extends Ds{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,textureFilter:"LINEAR",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)=>Dt(t,{s:this._getSubdomain(),quad:fc(e.tileX,e.tileY,e.tileZoom)}),specular:[63e-5,55e-5,32e-5],ambient:[.35,.35,.35],diffuse:[1.5,1.5,1.5],shininess:20,nightTextureCoefficient:2.7,...t})}}const Uc=Object.freeze(Object.defineProperty({__proto__:null,Bing:gc,CanvasTiles:ss,GeoImage:Ca,GeoTexture2d:cc,GeoVideo:dc,KML:uc,LAYER_EVENTS:Go,Layer:zt,Material:Uo,OpenStreetMap:_c,Vector:_t,WMS:me,XYZ:Ds},Symbol.toStringTag,{value:"Module"})),nr=function(e,t){return+(e.priority<t.priority)};class pc{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 s=this._getStamp(e,t,i._openglobus_id);i._openglobus_id&&this._stampCache[s]&&(delete this._stampCache[s],"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 s=Yr(i),r=this._getStamp(e,t,s);return!this._stampCache[r]&&(this._stampCache[r]=s,!0)}setActivity(e){this._active=e}releaseKeys(){this._currentlyPressedKeys={}}addEvent(e,t,i,s,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:s,priority:r}),this._unpressedKeysCallbacks[t].sort(nr);break;case"keypress":null==t?this._anykeyCallback={callback:i,sender:s||this}:(this._pressedKeysCallbacks[t]||(this._pressedKeysCallbacks[t]=[]),this._pressedKeysCallbacks[t].push({callback:i,sender:s,priority:r}),this._pressedKeysCallbacks[t].sort(nr));break;case"charkeypress":this._charkeysCallbacks[t]||(this._charkeysCallbacks[t]=[]),this._charkeysCallbacks[t].push({callback:i,sender:s,priority:r}),this._charkeysCallbacks[t].sort(nr)}}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!=W.KEY_ALT&&this._event.keyCode!=W.KEY_SHIFT||this._event.preventDefault()}handleKeyUp(){if(this._currentlyPressedKeys[this._event.keyCode]||this._event.keyCode===W.KEY_PRINTSCREEN)for(let e in this._unpressedKeysCallbacks)if(this._currentlyPressedKeys[e]||this._event.keyCode===W.KEY_PRINTSCREEN&&Number(e)===W.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 mc{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"mousewheel":this._htmlObject.addEventListener("wheel",(e=>{let s=e.deltaY||e.detail||e.wheelDelta||0;var r;null==e.wheelDelta&&(e.wheelDelta=-120*s),e.isTouchPad=0===(r=e).deltaMode&&Math.abs(r.deltaY)<50,i.call(t,e),e.preventDefault()}),!1);break;case"mousedown":this._htmlObject.addEventListener("mousedown",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-s.left,clientY:e.clientY-s.top})})),this._htmlObject.addEventListener("contextmenu",(function(e){return e.preventDefault(),!1}));break;case"mouseup":this._htmlObject.addEventListener("mouseup",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-s.left,clientY:e.clientY-s.top})}));break;case"mousemove":this._htmlObject.addEventListener("mousemove",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{clientX:e.clientX-s.left,clientY:e.clientY-s.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 vc{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"touchcancel":this._htmlObject.addEventListener("touchcancel",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,r)}));break;case"touchstart":this._htmlObject.addEventListener("touchstart",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,r)}));break;case"touchend":this._htmlObject.addEventListener("touchend",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,r)}));break;case"touchmove":this._htmlObject.addEventListener("touchmove",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),r=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,r)}))}}}let _e=new Uint8Array(4),ei=new Uint8Array(4),ii=new Uint8Array(4);class yc extends bi{constructor(e){super(xc),this.renderer=e,this._touchHandler=new vc(e.handler.canvas),this._mouseHandler=new mc(e.handler.canvas),this._keyboardHandler=new pc,this._active=!0,this.clickRadius=15,this.mouseState={clientX:0,clientY:0,pos:new H,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new v,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,isTouchPad:!1},this.touchState={touching:!1,moving:!1,touchEnd:!1,touchStart:!1,touchCancel:!1,doubleTouch:!1,doubleTouchDelay:550,doubleTouchRadius:10,clientX:0,clientY:0,pos:new H,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new v,sys:null,pickingObject:null,renderer:e},this._isMouseInside=!0,this._entityPickingEventsActive=!0,this._dblTchCoords=new H,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;return e.moving||e.justStopped||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,s,r){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.addEvent(e,t,i,s,r):super.on(e,t,i,s)}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.isTouchPad=e.isTouchPad||!1,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 s=t.clientX,r=t.clientY,n=this.clickRadius;if(Math.abs(this._lclickX-s)>=n&&Math.abs(this._lclickY-r)>=n&&(this._ldblClkBegins=0,this._lClkBegins=0),Math.abs(this._rclickX-s)>=n&&Math.abs(this._rclickY-r)>=n&&(this._rdblClkBegins=0,this._rClkBegins=0),Math.abs(this._mclickX-s)>=n&&Math.abs(this._mclickY-r)>=n&&(this._mdblClkBegins=0,this._mClkBegins=0),i.clientX===t.clientX&&i.clientY===t.clientY)return;i.clientX=t.clientX,i.clientY=t.clientY;let o=this.renderer.handler;i.pos.x=i.x=t.clientX*o.pixelRatio,i.pos.y=i.y=t.clientY*o.pixelRatio,i.nx=i.x/o.canvas.width,i.ny=i.y/o.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===W.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===W.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===W.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 s=window.performance.now();t.button===W.MB_LEFT?(i.leftButtonDown=!1,i.leftButtonUp=!0,Math.abs(this._lclickX-t.clientX)<this.clickRadius&&Math.abs(this._lclickY-t.clientY)<this.clickRadius&&s-this._lClkBegins<=i.clickDelay&&(this._ldblClkBegins?(window.performance.now()-this._ldblClkBegins<=i.doubleClickDelay&&(i.leftButtonDoubleClick=!0),this._ldblClkBegins=0):this._ldblClkBegins=window.performance.now(),i.leftButtonClick=!0,this._lClkBegins=0)):t.button===W.MB_RIGHT?(i.rightButtonDown=!1,i.rightButtonUp=!0,Math.abs(this._rclickX-t.clientX)<this.clickRadius&&Math.abs(this._rclickY-t.clientY)<this.clickRadius&&s-this._rClkBegins<=i.clickDelay&&(this._rdblClkBegins?(window.performance.now()-this._rdblClkBegins<=i.doubleClickDelay&&(i.rightButtonDoubleClick=!0),this._rdblClkBegins=0):this._rdblClkBegins=window.performance.now(),i.rightButtonClick=!0,this._rClkBegins=0)):t.button===W.MB_MIDDLE&&(i.middleButtonDown=!1,i.middleButtonUp=!0,Math.abs(this._mclickX-t.clientX)<this.clickRadius&&Math.abs(this._mclickY-t.clientY)<this.clickRadius&&s-this._mClkBegins<=i.clickDelay)&&(this._mdblClkBegins?(window.performance.now()-this._mdblClkBegins<=i.doubleClickDelay&&(i.middleButtonDoubleClick=!0),this._mdblClkBegins=0):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,t.touching=!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;t.sys=e,t.touchEnd=!0,0===e.touches.length&&(t.prev_x=t.x,t.prev_y=t.y,this._oneTouchStart)&&(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 s=t.x-t.prev_x,r=t.y-t.prev_y;(Math.abs(s)>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,s=_e,r=i.getPickingObjectArr(s);if(r){let i=r.rendererEvents;t.pickingObject=r,i&&i.dispatch(i.mouseleave,t),e.pickingObject=r,i&&i.dispatch(i.touchleave,e)}_e[0]=_e[1]=_e[2]=_e[3]=ii[0]=ii[1]=ii[2]=ii[3]=ei[0]=ei[1]=ei[2]=ei[3]=0}if(this._isMouseInside&&!(t.leftButtonHold||t.rightButtonHold||t.middleButtonHold)){let s=this.renderer,r=_e,n=ii,o=ei;e.x||e.y?s.readPickingColor(e.nx,1-e.ny,o):s.readPickingColor(t.nx,1-t.ny,o),n[0]=r[0],n[1]=r[1],n[2]=r[2],r[0]=o[0],r[1]=o[1],r[2]=o[2],t.pickingObject=null,e.pickingObject=null;let a=s.getPickingObjectArr(r);if(t.pickingObject=a,e.pickingObject=a,r[0]!==n[0]||r[1]!==n[1]||r[2]!==n[2])if((i=r)[0]||i[1]||i[2]){if((e=>!!(e[0]||e[1]||e[2]))(n)){let i=s.getPickingObjectArr(n);if(i){let s=i.rendererEvents;t.pickingObject=i,s&&s.dispatch(s.mouseleave,t),e.pickingObject=i,s&&s.dispatch(s.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)}}else{let i=s.getPickingObjectArr(n);if(i){let s=i.rendererEvents;t.pickingObject=i,s&&s.dispatch(s.mouseleave,t),e.pickingObject=i,s&&s.dispatch(s.touchleave,e)}}}var i}handleMouseEvents(){let e=this,t=this.mouseState,i=t.pickingObject,s=null;t.leftButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.lclick,t)),this.dispatch(e.lclick,t),t.leftButtonClick=!1),t.rightButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rclick,t)),this.dispatch(e.rclick,t),t.rightButtonClick=!1),t.middleButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mclick,t)),this.dispatch(e.mclick,t),t.middleButtonClick=!1),t.leftButtonDown&&(t.leftButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.lhold,t)),this.dispatch(e.lhold,t)):(t.leftButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.ldown,t)),this.dispatch(e.ldown,t))),t.rightButtonDown&&(t.rightButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.rhold,t)),this.dispatch(e.rhold,t)):(t.rightButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.rdown,t)),this.dispatch(e.rdown,t))),t.middleButtonDown&&(t.middleButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.mhold,t)),this.dispatch(e.mhold,t)):(t.middleButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.mdown,t)),this.dispatch(e.mdown,t))),t.leftButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.lup,t)),this.dispatch(e.lup,t),t.leftButtonUp=!1,t.leftButtonHold=!1),t.rightButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rup,t)),this.dispatch(e.rup,t),t.rightButtonUp=!1,t.rightButtonHold=!1),t.middleButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mup,t)),this.dispatch(e.mup,t),t.middleButtonUp=!1,t.middleButtonHold=!1),t.leftButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.ldblclick,t)),this.dispatch(e.ldblclick,t),t.leftButtonDoubleClick=!1),t.rightButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rdblclick,t)),this.dispatch(e.rdblclick,t),t.rightButtonDoubleClick=!1),t.middleButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mdblclick,t)),this.dispatch(e.mdblclick,t),t.middleButtonDoubleClick=!1),t.wheelDelta&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mousewheel,t)),this.dispatch(e.mousewheel,t)),t.moving&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.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,s=null;if(t.touchCancel&&(this.dispatch(e.touchcancel,t),t.touchCancel=!1),t.touchStart){let r=this.renderer;r.readPickingColor(t.nx,1-t.ny,_e);let n=r.getPickingObjectArr(_e);i=t.pickingObject=n,i&&(s=i.rendererEvents,s&&s.dispatch(s.touchstart,t)),this.dispatch(e.touchstart,t),t.touchStart=!1}t.doubleTouch&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.doubletouch,t)),this.dispatch(e.doubletouch,t),t.doubleTouch=!1),t.touchEnd&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.touchend,t)),this.dispatch(e.touchend,t),t.x=0,t.y=0,t.touchEnd=!1,t.touching=!1),t.moving&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.touchmove,t)),this.dispatch(e.touchmove,t),t.prev_x=t.x,t.prev_y=t.y)}}const xc=["projchanged","changerelativecenter","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 Ii{constructor(e=0,t=0,i=0,s=0){this.left=e,this.right=i,this.top=t,this.bottom=s}set(e=0,t=0,i=0,s=0){this.left=e,this.right=i,this.top=t,this.bottom=s}clone(){return new Ii(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 bc{constructor(){this.imagesCache={},this._counter=0,this._pendingsQueue=new dn,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 Vr{constructor(e=1024,t=1024){this.nodes=new Map,this.texture=null,this.canvas=new mi(e,t),this.clearCanvas(),this._handler=null,this._images=[],this._btree=null,this._imagesCacheManager=new bc,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(),s=this.canvas.getHeight(),r=t.image,n=t.rect,o=Math.round(.5*this.borderSize);this.canvas.drawImage(r,n.left+o,n.top+o,r.atlasWidth||0,r.atlasHeight||0);let a=t.texCoords;a[0]=(n.left+o)/i,a[1]=(n.top+o)/s,a[2]=(n.left+o)/i,a[3]=(n.bottom-o)/s,a[4]=(n.right-o)/i,a[5]=(n.bottom-o)/s,a[6]=(n.right-o)/i,a[7]=(n.bottom-o)/s,a[8]=(n.right-o)/i,a[9]=(n.top+o)/s,a[10]=(n.left+o)/i,a[11]=(n.top+o)/s,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 Bi(new Ii(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 Bi{constructor(e,t){this.childNodes=null,this.image=null,this.rect=e||new Ii,this.texCoords=t||[],this.atlas=null}insert(e){if(this.childNodes)return this.childNodes[0].insert(e)||this.childNodes[1].insert(e);{if(null!=this.image)return;let t=this.rect;const i=(e.atlasWidth||e.width)+this.atlas.borderSize,s=(e.atlasHeight||e.height)+this.atlas.borderSize;return i>t.getWidth()||s>t.getHeight()?void 0:t.fit(i,s)?(this.image=e,this):(this.childNodes=new Array(2),this.childNodes[0]=new Bi,this.childNodes[0].atlas=this.atlas,this.childNodes[1]=new Bi,this.childNodes[1].atlas=this.atlas,t.getWidth()-i>t.getHeight()-s?(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+s),this.childNodes[1].rect.set(t.left,t.top+s,t.right,t.bottom)),this.childNodes[0].insert(e))}}}class _o extends Vr{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 wc extends Bi{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 Tc{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 pi),this.atlasIndexesDeferred[t].promise}getFullIndex(e){return e.trim().toLowerCase()}_applyFontDataToAtlas(e,t,i=0){let s=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,n=e.height,o=e.gliphSize;this.sdfParamsArr[4*i]=r,this.sdfParamsArr[4*i+1]=n,this.sdfParamsArr[4*i+2]=o,this.sdfParamsArr[4*i+3]=e.distanceRange;let a={};for(let t=0;t<s.length;t++){let i=s[t],l=i.char;a[i.id]=l;let h=new Ii(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/n,c[2]=h.left/r,c[3]=h.bottom/n,c[4]=h.right/r,c[5]=h.bottom/n,c[6]=h.right/r,c[7]=h.bottom/n,c[8]=h.right/r,c[9]=h.top/n,c[10]=h.left/r,c[11]=h.top/n;let d=new wc(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/o,f.nHeight=d.metrics.height/o,f.nAdvance=d.metrics.xadvance/o,f.nXOffset=d.metrics.xoffset/o,f.nYOffset=1-d.metrics.yoffset/o,d.emptySize=1,e.nodes.set(_.charCodeAt(0),d)}e.kernings={};for(let i=0;i<t.kernings.length;i++){let s=t.kernings[i],r=s.first,n=s.second;e.kernings[r]||(e.kernings[r]={}),e.kernings[r][n]=s.amount/o}}initFont(e,t,i){let s=this.atlasesArr.length,r=this.getFullIndex(e);this.atlasIndexes[r]=s;let n=this.atlasIndexesDeferred[r];n||(n=this.atlasIndexesDeferred[r]=new pi),this.samplerArr[this.atlasesArr.length]=s;let o=new _o;o.height=0,o.width=0,o.gliphSize=0,o.distanceRange=0,o.kernings={},o.assignHandler(this._handler),this.atlasesArr[s]=o,this._applyFontDataToAtlas(o,t,s);let a=new Image;a.onload=()=>{this._createTexture(o,a),n.resolve(s)},a.src=i}_createTexture(e,t){e.createTexture(t)}loadFont(e,t,i){let s=this.atlasesArr.length,r=this.getFullIndex(e);this.atlasIndexes[r]=s;let n=this.atlasIndexesDeferred[r];n||(n=this.atlasIndexesDeferred[r]=new pi),this.samplerArr[this.atlasesArr.length]=s;let o=new _o;o.height=0,o.width=0,o.gliphSize=0,o.distanceRange=0,o.kernings={},o.assignHandler(this._handler),this.atlasesArr[s]=o,fetch(`${t}/${i}`).then((e=>{if(!e.ok)throw Error(`Unable to load "${t}/${i}"`);return e.json()})).then((e=>{this._applyFontDataToAtlas(o,e,s);let i=new Image;i.onload=()=>{this._createTexture(o,i),n.resolve(s)},i.src=`${t}/${e.pages[0]}`,i.crossOrigin="Anonymous"})).catch((e=>(n.reject(),{status:"error",msg:e.toString()})))}}let Cc=0,Ec=0,He=new Float32Array(2);class Ac{constructor(e,t={}){var i,s;if(this.div=null,this.handler=e instanceof Be?e:new Be(e,{pixelRatio:t.dpi||window.devicePixelRatio+.15,autoActivate:!0}),this.clearColor=new Float32Array(t.clearColor||[0,0,0,1]),this.exposure=t.exposure||3.01,this.gamma=t.gamma||.47,this.whitepoint=1,this.brightThreshold=.9,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=new Pi({width:null==(i=this.handler.canvas)?void 0:i.width,height:null==(s=this.handler.canvas)?void 0:s.height,eye:new v(0,0,0),look:new v(0,0,-1),up:new v(0,1,0)}),this.events=new yc(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._depthCallbacks=[],this.depthFramebuffer=null,this._depthRefreshRequired=!1;let r=new URLSearchParams(location.search),n=r.get("og_msaa");this._msaa=n?Number(r.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 Vr,this.fontAtlas=new Tc(t.fontsSrc),this.strokeTextureAtlas=new Vr,this._entityCollections=[[]],this._currentOutput="screen",this._fnScreenFrame=null,this.labelWorker=new Ka(4),this.screenDepthFramebuffer=null,this.screenFramePositionBuffer=null,this.screenTexture={},this.outputTexture=null,this._readPickingBuffer=this._readPickingBuffer_webgl2,(t.autoActivate||Gt(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)}setRelativeCenter(e){this.events.dispatch(this.events.changerelativecenter,e||this.activeCamera.eye)}setEventsActivity(e){this.events.active=e}addDepthCallback(e,t){let i=Ec++;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}}addPickingCallback(e,t){let i=Cc++;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,s=0,r="0_0_0";for(;!(t||i||s)||this.colorObjects.has(r);)t=Ni(1,255),i=Ni(1,255),s=Ni(1,255),r=`${t}_${i}_${s}`;e._pickingColor?e._pickingColor.set(t,i,s):e._pickingColor=new v(t,i,s),e._pickingColorU=new Float32Array([t/255,i/255,s/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 H(Math.round(.5*e.width),Math.round(.5*e.height))}getClientCenter(){let e=this.handler.canvas;return new H(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.fontAtlas.assignHandler(this.handler),this.strokeTextureAtlas.assignHandler(this.handler),this.handler.setFrameCallback((()=>{this.draw()})),this.events.initialize(),this.events.on("charkeypress",W.KEY_APOSTROPHE,(function(){ie.setVisibility(!ie.getVisibility())})),this.handler.addProgram(new X("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 Rt(this.handler,{width:640,height:480,targets:[{readAsync:!0}]}),this.pickingFramebuffer.init(),this.depthFramebuffer=new Rt(this.handler,{width:640,height:480,targets:[{internalFormat:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT",readAsync:!0},{internalFormat:"RGBA16F",type:"FLOAT",attachment:"COLOR_ATTACHMENT",readAsync:!0}],useDepth:!0}),this.depthFramebuffer.init(),this.screenDepthFramebuffer=new Rt(this.handler,{useDepth:!1}),this.screenDepthFramebuffer.init(),"webgl"===this.handler.gl.type)this._readPickingBuffer=this._readPickingBuffer_webgl1,this.sceneFramebuffer=new Rt(this.handler),this.sceneFramebuffer.init(),this._fnScreenFrame=this._screenFrameNoMSAA,this.screenTexture={screen:this.sceneFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0]};else{let e=this.getMaxMSAA(this._internalFormat);this._msaa>e&&(this._msaa=e),this.handler.addPrograms([new X("toneMapping",{uniforms:{hdrBuffer:"sampler2d",exposure:"float",gamma:"float",whitepoint:"float"},attributes:{corners:"vec3"},vertexShader:"#version 300 es\nin vec2 corners;out vec2 tc;void main(void){gl_Position=vec4(corners,0.0,1.0);tc=corners*0.5+0.5;}",fragmentShader:"#version 300 es\nprecision highp float;\n#ifndef saturate\n#define saturate(a) clamp(a, 0.0, 1.0)\n#endif\nuniform sampler2D hdrBuffer;uniform float whitepoint;uniform float exposure;uniform float gamma;vec3 LinearToneMapping(vec3 color){return exposure*color;}vec3 ReinhardToneMapping2(vec3 color){return vec3(1.0)-exp(-color*exposure);}vec3 ReinhardToneMapping(vec3 color){color*=exposure;return saturate(color/(vec3(1.0)+color));}\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))\nvec3 Uncharted2ToneMapping(vec3 color){color*=exposure;return saturate(Uncharted2Helper(color)/Uncharted2Helper(vec3(whitepoint)));}vec3 OptimizedCineonToneMapping(vec3 color){color*=exposure;color=max(vec3(0.0),color-0.004);return pow((color*(6.2*color+0.5))/(color*(6.2*color+1.7)+0.06),vec3(2.2));}vec3 ACESFilmicToneMapping(vec3 color){color*=exposure;return saturate((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14));}in vec2 tc;layout(location=0)out vec4 fragColor;void main(void){vec4 hdrColor=texture(hdrBuffer,tc);float oneByGamma=gamma/gamma;float oneByWhitePoint=whitepoint/whitepoint;vec3 mapped=ReinhardToneMapping2(hdrColor.rgb)*oneByGamma*oneByWhitePoint;mapped=pow(mapped,vec3(1.0/gamma));fragColor=vec4(mapped,hdrColor.a);}"})]),this.handler.addPrograms([new X("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 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 return texture(depthTexture, tc).r;\n }\n \n void main(void) {\n float c = LinearizeDepth(tc);\n fragColor = vec4(c, c, c, 1.0);\n }"})]),this.sceneFramebuffer=new Ta(this.handler,{size:1,msaa:this._msaa,internalFormat:this._internalFormat,filter:"LINEAR"}),this.sceneFramebuffer.init(),this.blitFramebuffer=new Rt(this.handler,{size:1,useDepth:!1,targets:[{internalFormat:this._internalFormat,format:this._format,type:this._type,filter:"NEAREST"}]}),this.blitFramebuffer.init(),this.toneMappingFramebuffer=new Rt(this.handler,{useDepth:!1}),this.toneMappingFramebuffer.init(),this._fnScreenFrame=this._screenFrameMSAA,this.screenTexture={screen:this.toneMappingFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0],frustum:this.depthFramebuffer.textures[0]}}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()}}_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.setViewportSize(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.setViewportSize(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.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.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.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]?ie.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])ie.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,t=0){this._entityCollections[t]||(this._entityCollections[t]=[]),this._entityCollections[t].push(...e)}markForDepthRefresh(){this._depthRefreshRequired=!0}_drawEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=this.handler.gl;this.enableBlendDefault();let i=t.length;for(;i--;)t[i]._fadingOpacity&&t[i].pointCloudHandler.draw();for(i=t.length;i--;){let e=t[i];t[i]._fadingOpacity&&(e.events.dispatch(e.events.draw,e),t[i].geoObjectHandler.draw())}for(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.billboardsTextureAtlas.texture),i=t.length;i--;){let e=t[i];e._fadingOpacity&&e.billboardHandler.draw()}let s=this.fontAtlas.atlasesArr;for(i=0;i<s.length;i++)e.activeTexture(e.TEXTURE0+i),e.bindTexture(e.TEXTURE_2D,s[i].texture);for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].labelHandler.draw();for(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.strokeTextureAtlas.texture),i=t.length;i--;)t[i]._fadingOpacity&&t[i].rayHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].polylineHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].stripHandler.draw()}}_drawPickingEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=t.length;for(;e--;)t[e]._fadingOpacity&&t[e].billboardHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].geoObjectHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].labelHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].rayHandler.drawPicking();for(e=t.length;e--;)t[e]._visibility&&t[e].polylineHandler.drawPicking();for(e=t.length;e--;)t[e]._visibility&&t[e].stripHandler.drawPicking()}}_drawDepthEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=t.length;for(;e--;)t[e]._fadingOpacity&&t[e].geoObjectHandler.drawDepth()}}_clearEntityCollectionQueue(e){this._entityCollections[e].length=0,this._entityCollections[e]=[]}draw(){this.activeCamera.checkMoveEnd();let e=this.events,t=e.pointerEvent(),i=!e.mouseState.leftButtonDown&&!e.mouseState.rightButtonDown,s=e.touchState.touchStart||e.touchState.touchEnd;const r=t&&i||s||this._depthRefreshRequired;this._depthRefreshRequired=!1,e.handleEvents();let n=this.sceneFramebuffer;n.activate();let o=this.handler.gl;o.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),o.clear(o.COLOR_BUFFER_BIT|o.DEPTH_BUFFER_BIT),this.enableBlendDefault(),e.dispatch(e.draw,this),this.activeCamera.checkFly();let a=this.activeCamera.frustums,l=this._renderNodesArr,h=a.length;for(;h--;){this.activeCamera.setCurrentFrustum(h),o.clear(o.DEPTH_BUFFER_BIT);let t=l.length;for(;t--;)l[t].preDrawNode();for(t=l.length;t--;)this.enableBlendDefault(),l[t].drawNode();this._drawEntityCollections(0),e.dispatch(e.drawtransparent,this),r&&this._drawPickingBuffer(0),this._drawDepthBuffer(0),this._clearEntityCollectionQueue(0)}for(let e=1;e<this._entityCollections.length;e++){o.clear(o.DEPTH_BUFFER_BIT);let t=a.length;for(;t--;)this.activeCamera.setCurrentFrustum(t),this._drawEntityCollections(e),r&&this._drawPickingBuffer(e),this._drawDepthBuffer(e);this._clearEntityCollectionQueue(e)}n.deactivate(),this.blitFramebuffer&&n.blitTo(this.blitFramebuffer,0),r&&(this._readPickingBuffer(),this._readDepthBuffer()),this._fnScreenFrame(),e.dispatch(e.postdraw,this),e.mouseState.wheelDelta=0,e.mouseState.justStopped=!1,e.mouseState.moving=!1,e.touchState.moving=!1}getImageDataURL(e="image/png",t=1){return this.draw(),this.handler.canvas?this.handler.canvas.toDataURL(e,t):""}_screenFrameMSAA(){let e=this.handler,t=e.programs.toneMapping,i=t._program,s=e.gl;s.disable(s.DEPTH_TEST),s.bindBuffer(s.ARRAY_BUFFER,this.screenFramePositionBuffer),s.vertexAttribPointer(i.attributes.corners,2,s.FLOAT,!1,0,0),this.toneMappingFramebuffer.activate(),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT),t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.blitFramebuffer.textures[0]),s.uniform1i(i.uniforms.hdrBuffer,0),s.uniform1f(i.uniforms.gamma,this.gamma),s.uniform1f(i.uniforms.exposure,this.exposure),s.uniform1f(i.uniforms.whitepoint,this.whitepoint),s.drawArrays(s.TRIANGLE_STRIP,0,4),this.toneMappingFramebuffer.deactivate(),t=e.programs.screenFrame,i=t._program,t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.outputTexture),s.uniform1i(i.uniforms.texture,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.enable(s.DEPTH_TEST)}_screenFrameNoMSAA(){let e=this.handler,t=e.programs.screenFrame,i=t._program,s=e.gl;s.disable(s.DEPTH_TEST),t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.outputTexture),s.uniform1i(i.uniforms.texture,0),s.bindBuffer(s.ARRAY_BUFFER,this.screenFramePositionBuffer),s.vertexAttribPointer(i.attributes.corners,2,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.enable(s.DEPTH_TEST)}_drawPickingBuffer(e){this.pickingFramebuffer.activate();let t=this.handler.gl;if(this.activeCamera.isFirstPass&&0===e?(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)):t.clear(t.DEPTH_BUFFER_BIT),t.disable(t.BLEND),0===e){let e=this._pickingCallbacks;for(let t=0,i=e.length;t<i;t++)e[t].callback.call(e[t].sender)}this._drawPickingEntityCollections(e),t.enable(t.BLEND),this.pickingFramebuffer.deactivate()}_drawDepthBuffer(e){this.depthFramebuffer.activate();let t=this.handler,i=t.gl;if(i.disable(i.BLEND),this.activeCamera.isFirstPass&&0===e?(i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT)):i.clear(i.DEPTH_BUFFER_BIT),0===e){let e=this._depthCallbacks,t=e.length;for(;t--;)e[t].callback.call(e[t].sender)}if(this._drawDepthEntityCollections(e),this.depthFramebuffer.deactivate(),"depth"===this._currentOutput||"frustum"===this._currentOutput){this.screenDepthFramebuffer.activate();let e=t.programs.depth,s=e._program;i.bindBuffer(i.ARRAY_BUFFER,this.screenFramePositionBuffer),i.vertexAttribPointer(s.attributes.corners,2,i.FLOAT,!1,0,0),e.activate(),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.depthFramebuffer.textures[1]),i.uniform1i(s.uniforms.depthTexture,0),i.drawArrays(i.TRIANGLE_STRIP,0,4),this.screenDepthFramebuffer.deactivate()}i.enable(i.BLEND)}_readDepthBuffer(e){this.depthFramebuffer.readPixelBuffersAsync(e)}_readPickingBuffer_webgl1(){this.pickingFramebuffer.readPixelBuffersAsync()}_readPickingBuffer_webgl2(){this.pickingFramebuffer.readPixelBuffersAsync()}readPickingColor(e,t,i){var s;let r=this.pickingFramebuffer.width,n=this.pickingFramebuffer.height;e=Math.round(e*r);let o=4*((t=Math.round(t*n))*r+e),a=null==(s=this.pickingFramebuffer)?void 0:s.pixelBuffers[0].data;a&&(i[0]=a[o],i[1]=a[o+1],i[2]=a[o+2])}readDepth(e,t,i){let s=new Float32Array(4),r=new Uint8Array(4);this.depthFramebuffer.readData(e,t,r,0),this.depthFramebuffer.readData(e,t,s,1),i[0]=s[0],i[1]=Math.round(r[0]/10)-1}getDistanceFromPixel(e){let t=this.activeCamera,i=this.handler.canvas,s=e.x/i.width,r=(i.height-e.y)/i.height;if(He[0]=He[1]=0,this.readDepth(s,r,He),-1===He[1])return;let n=He[0],o=t.frustums[He[1]];if(!o)return;let a=new et(2*s-1,2*r-1,2*n-1,1),l=o.inverseProjectionMatrix.mulVec4(a),h=-l.z/l.w;if(t.isOrthographic)return h;let c=e.direction||t.unproject(e.x,e.y);return h/Math.max(1e-6,c.dot(t.getForward()))}getCartesianFromPixel(e){let t=this.getDistanceFromPixel(e);if(t){if(this.activeCamera.isOrthographic){let i=new v;return this.activeCamera.unproject(e.x,e.y,t,i),i}return(e.direction||this.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.activeCamera.eye)}}getCartesianFromPixelAsync(e){return new Promise(((t,i)=>{this._readDepthBuffer((()=>{t(this.getCartesianFromPixel(e))}))}))}getDepthMinDistance(){let e=this.handler.canvas,t=e.width,i=e.height,s=or,r=i*t,n=new H;for(let e=0;e<r;e++){n.x=e%t,n.y=Math.floor(e/t);let i=this.getDistanceFromPixel(n);i&&i<s&&(s=i)}return s<or?s:0}getDepthMinDistanceAsync(){return new Promise(((e,t)=>{this._readDepthBuffer((()=>{e(this.getDepthMinDistance())}))}))}async setOrthographicProjection(e){if(e!==this.activeCamera.isOrthographic){let t=await this.getDepthMinDistanceAsync();t&&e&&(this.activeCamera.focusDistance=t),this.activeCamera.isOrthographic=e,this.events.dispatch(this.events.projchanged,this.activeCamera)}}start(){this._initialized||this.initialize(),this.handler.start()}destroy(){this.labelWorker.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.controls={},this.controlsBag={},this.colorObjects.clear(),this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=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._initialized=!1}}const fo="/res",Ye=class e{constructor(t){this.$target=null,this._instanceID=`__globus${e.__counter__++?e.__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"),t.attributionContainer?t.attributionContainer.appendChild(this.$inner.attributions):(this.$inner.attributions.classList.add("og-attribution"),this.$inner.appendChild(this.$inner.attributions)),t.target&&this.attachTo(t.target);const i=e=>{e.preventDefault()};this._canvas.onmouseenter=function(){document.addEventListener("mousewheel",i,{capture:!1,passive:!1})},this._canvas.onmouseleave=function(){document.removeEventListener("mousewheel",i)},this.renderer=new Ac(new Be(this._canvas,{autoActivate:!1,pixelRatio:t.dpi||window.devicePixelRatio+.15,context:{alpha:t.transparentBackground,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1}}),{autoActivate:!1,msaa:t.msaa,fontsSrc:t.fontsSrc,gamma:t.gamma,exposure:t.exposure,...t.transparentBackground&&{clearColor:[0,0,0,0]}}),this.renderer.div=this.$inner,t.skybox&&this.renderer.addNode(t.skybox),this._planetName=t.name?t.name:"globus_planet_"+e.__counter__,this.planet=new Ri({name:this._planetName,frustums:t.frustums,ellipsoid:t.ellipsoid,maxGridSize:t.maxGridSize,nightTextureSrc:null===t.nightTextureSrc?null:t.nightTextureSrc||`${t.resourcesSrc||fo}/night.png`,specularTextureSrc:null===t.specularTextureSrc?null:t.specularTextureSrc||`${t.resourcesSrc||fo}/spec.png`,minAltitude:t.minAltitude,maxAltitude:t.maxAltitude||15e6,maxEqualZoomAltitude:t.maxEqualZoomAltitude,minEqualZoomAltitude:t.minEqualZoomAltitude,minEqualZoomCameraSlope:t.minEqualZoomCameraSlope,quadTreeStrategyPrototype:t.quadTreeStrategyPrototype,maxLoadingRequests:t.maxLoadingRequests,atmosphereEnabled:t.atmosphereEnabled,transitionOpacityEnabled:t.transitionOpacityEnabled,atmosphereParameters:t.atmosphereParameters,minDistanceBeforeMemClear:t.minDistanceBeforeMemClear,vectorTileSize:t.vectorTileSize,maxNodesCount:t.maxNodesCount,transparentBackground:t.transparentBackground}),t.terrain?Array.isArray(t.terrain)?this.planet.setTerrain(t.terrain[0]):this.planet.setTerrain(t.terrain):this.planet.setTerrain(new Mi),this.renderer.addNode(this.planet),t.controls?this.planet.addControls(t.controls):this.planet.addControls([new ma,new Yi,new pa,new da,new fa,new Ho,new Fr]);const s=this.renderer.controls;let r,n;for(let e in s)s[e]instanceof Dr&&(r=s[e]),s[e]instanceof Yi&&(n=s[e]);r?this.sun=r:(this.sun=new Dr,this.planet.addControl(this.sun)),t.sun&&(void 0===t.sun.active||t.sun.active||this.sun.deactivate(),!0===t.sun.stopped&&this.sun.stop()),n?this.navigation=n:(this.navigation=new Yi,this.planet.addControl(this.navigation)),t.navigation&&(void 0===t.navigation.active||t.navigation.active||this.navigation.deactivate(),void 0!==t.navigation.inertia&&(this.navigation.inertia=t.navigation.inertia),void 0!==t.navigation.dragInertia&&(this.navigation.dragInertia=t.navigation.dragInertia),void 0!==t.navigation.minSlope&&(this.navigation.minSlope=t.navigation.minSlope),void 0!==t.navigation.mass&&(this.navigation.mass=t.navigation.mass),void 0!==t.navigation.zoomSpeed&&(this.navigation.zoomSpeed=t.navigation.zoomSpeed),void 0!==t.navigation.mode&&this.navigation.setMode(t.navigation.mode),void 0!==t.navigation.poleThreshold&&(this.navigation.poleThreshold=t.navigation.poleThreshold),void 0!==t.navigation.disableRotation&&(this.navigation.disableRotation=t.navigation.disableRotation),void 0!==t.navigation.disableTilt&&(this.navigation.disableTilt=t.navigation.disableTilt)),t.layers&&this.planet.addLayers(t.layers);let o=t.viewExtent;o&&(o instanceof Array?this.planet.viewExtentArr(o):this.planet.viewExtent(o)),(t.autoActivate||Gt(t.autoActivate))&&this.start()}start(){this.renderer.start(),this.fadeIn()}fadeIn(){this._canvas.style.opacity="1.0"}fadeOut(){this._canvas.style.opacity="0"}attachTo(e,t){let i;this.detach(),i=e instanceof HTMLElement?e:document.getElementById(e)||document.querySelector(e),i?(this.$target=i,t&&this.$target.firstChild?this.$target.insertBefore(this.$inner,this.$target.firstChild):i.appendChild(this.$inner)):console.warn(`Target container not found. Provided target: ${e}`)}detach(){this.$target&&(this.$target.removeChild(this.$inner),this.$target=null)}destroy(){this.detach(),this.planet.layers.forEach((e=>e.remove())),this.planet.destroy(),this.renderer.destroy(),window[this._instanceID]=null}};Ye.__counter__=0;let go=Ye;const Gc=new qr(3396200,3389508),jc=new qr(1737400,1737400),Lc=`<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">${Vo}</div>\n </div>\n <div class="og-popup-title">{title}</div>\n </div>`,Pc=["open","close"];class qc extends ut{constructor(e){super({template:Dt(Lc,{title:e.title||""}),classList:e.className?[e.className]:[],...e}),this.events=this.events.registerNames(Pc),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=vi(e.lonLat),this._cartPos=new v,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,s=this._planet.ellipsoid.equatorialSize+t,r=i._lonLat.height,n=e.sub(i.eye);Math.sqrt((s+r)*(s+r)-s*s)>n.length()&&i.getForward().dot(n.normalize())>0?(this.el.style.display="block",this.setScreen(i.project3v(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="")}}const po=5/Math.pow(2,5);class ki extends Hr{constructor(e,t,i,s){super(e,t,i,s),this._projection=_n,this.isPole=!1,this._tileGroup=0}_getMaxZoom(){let e;if(this._extent.northEast.lat>85){let t=Math.floor((90-this._extent.northEast.lat)/po);e=Math.floor(t/16)+5}else if(this._extent.southWest.lat<-85){let t=Math.floor((90+this._extent.southWest.lat)/po);e=Math.floor(t/16)+5}else e=50;return e}_assignTileYIndexes(e){const t=e.getCenter().lat;this.tileY=At(t,e.getHeight(),90),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_assignTileXIndexes(e){let t=e.getCenter().lon;this.tileX=At(t,e.getWidth(),-180);let i=2*(1<<this.tileZoom);this.tileXE=(this.tileX+1)%i,this.tileXW=(i+this.tileX-1)%i}getDefaultTexture(){return this.planet.solidTextureOne}}class Ee extends pe{constructor(e,t,i,s,r,n){super(e,t,i,s,r,n),this.strategy=e}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),r=t.northEast,n=t.southWest,o=new L(n.lon+i,n.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new Ee(e,0,this,new U(new L(n.lon,n.lat+s),new L(n.lon+i,r.lat)),l,h),a[1]=new Ee(e,1,this,new U(o,new L(r.lon,r.lat)),l,h),a[2]=new Ee(e,2,this,new U(new L(n.lon,n.lat),o),l,h),a[3]=new Ee(e,3,this,new U(new L(n.lon+i,n.lat),new L(r.lon,n.lat+s)),l,h)}_setExtentBounds(){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.strategy._renderingNodesWest[this.nodeId]||!!this.strategy._renderingNodesEast[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.extent.southWest.lon<0?this.strategy._renderingNodesWest[this.nodeId]=!0:this.strategy._renderingNodesEast[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.strategy._queueDeferredNode(this):this.applyCollection());const s=this.entityCollection;s._fadingOpacity=this.layer._fadingOpacity,s.scaleByDistance=this.layer.scaleByDistance,s.pickingScale=this.layer.pickingScale,s.isEmpty()||e.push(s)}}class Sc extends un{constructor(e,t,i){super(e,t,i);let s=t._planet;this._entityCollectionsTreeWest=new Ee(this,0,null,U.createFromArray([-180,-90,0,90]),s,0),this._entityCollectionsTreeEast=new Ee(this,0,null,U.createFromArray([0,-90,180,90]),s,0),this._renderingNodesWest={},this._renderingNodesEast={}}insertEntity(e,t=!1){e._lonLat.lon<0?(this._entityCollectionsTreeWest.__setLonLat__(e),this._entityCollectionsTreeWest.insertEntity(e,t)):(this._entityCollectionsTreeEast.__setLonLat__(e),this._entityCollectionsTreeEast.insertEntity(e,t))}setPickingEnabled(e){this._entityCollectionsTreeWest.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeEast.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)}))}dispose(){this._entityCollectionsTreeWest=null,this._entityCollectionsTreeEast=null,this._renderingNodesWest={},this._renderingNodesEast={}}insertEntities(e){let t=[],i=[];for(let s=0,r=e.length;s<r;s++){let r=e[s];r._lonLat.lon<0?(t.push(r),this._entityCollectionsTreeWest.__setLonLat__(r)):(i.push(r),this._entityCollectionsTreeEast.__setLonLat__(r))}this._entityCollectionsTreeWest.buildTree(t),this._entityCollectionsTreeEast.buildTree(i)}collectVisibleEntityCollections(e){this._renderingNodesWest={},this._renderingNodesEast={};let t=this._layer._planet.quadTreeStrategy;this._secondPASS=[],this._entityCollectionsTreeWest.collectRenderCollectionsPASS1(t._visibleNodesWest,e);let i=this._secondPASS.length;for(;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesWest,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeEast.collectRenderCollectionsPASS1(t._visibleNodesEast,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesEast,e,this._secondPASS[i].nodeId)}}class Rc extends Is{constructor(e){super({name:"Mars",proj:_n,...e}),this._westExtent=U.createFromArray([-180,-90,0,90]),this._eastExtent=U.createFromArray([0,-90,180,90]),this._visibleNodesWest={},this._visibleNodesEast={}}init(e){this._quadTreeList=[new qt(ki,this,0,null,0,this._westExtent),new qt(ki,this,0,null,0,this._eastExtent)],super.init(e)}getTileXY(e,t){let i,s,r=t,n=1<<r;return i=e.lon>0?At(e.lon,180/n,0)+n:At(e.lon,180/n,-180),s=At(e.lat,180/n,90),[i,s,r,0]}getLonLatTileOffset(e,t,i,s,r){let n;n=e.lon>0?Si(t-(1<<s),i,s,this._eastExtent):Si(t,i,s,this._westExtent);let o=n.getWidth()/(r-1),a=n.getHeight()/(r-1);return[r-Math.ceil((e.lat-n.southWest.lat)/a)-1,Math.floor((e.lon-n.southWest.lon)/o)]}createEntityCollectionsTreeStrategy(e,t){return new Sc(this,e,t)}collectVisibleNode(e){e.segment.getExtent().southWest.lon<0?this._visibleNodesWest[e.nodeId]=e:this._visibleNodesEast[e.nodeId]=e}_clearVisibleNodes(){this._visibleNodesWest={},this._visibleNodesEast={}}}class Mc extends Is{constructor(e){super({name:"wgs84",proj:zs,...e})}init(e){this._quadTreeList=[new qt(ki,this,0,null,0,U.createFromArray([-180,-90,180,90]))],super.init(e)}}const Yc={epsg4326:class extends Is{constructor(e){super({name:"EPSG4326",proj:zs,...e})}init(e){this._quadTreeList=[new qt(ki,this,0,null,0,U.createFromArray([-180,-90,0,90])),new qt(ki,this,0,null,0,U.createFromArray([0,-90,180,90]))],super.init(e)}},earth:La,equi:Rc,wgs84:Mc};class Bc{static async load(e){const t=await fetch(e);if(!t.ok)throw new Error(`Unable to load '${e}'`);const i=await t.arrayBuffer(),s=new DataView(i);if(1179937895!==s.getUint32(0,!0))throw new Error("Not a valid GLB");s.getUint32(4,!0);const r=this.getChunks(s);return this.parseChunks(r)}static getChunks(e){const t=[];let i=12;do{const s=this.getChunk(e,i);i+=8+s.length,t.push(s)}while(i<e.byteLength);return t}static getChunk(e,t){const i=e.getUint32(t,!0);return{length:i,type:this.getChunkType(e.getUint32(t+4,!0)),chunkData:e.buffer.slice(t+8,t+8+i)}}static getChunkType(e){switch(e){case 1313821514:return 0;case 5130562:return 1;default:return 2}}static parseChunks(e){let t,i=[];for(const s of e)switch(s.type){case 0:t=this.parseJsonChunk(s);break;case 1:i.push(s.chunkData)}if(void 0===t)throw new Error("GLB json data extraction failed");return{gltf:t,bin:i}}static parseJsonChunk(e){return JSON.parse((new TextDecoder).decode(e.chunkData))}}var we=(e=>(e[e.byte=5120]="byte",e[e.ubyte=5121]="ubyte",e[e.short=5122]="short",e[e.ushort=5123]="ushort",e[e.uint=5125]="uint",e[e.float=5126]="float",e))(we||{}),fe=(e=>(e.scalar="SCALAR",e.vec2="VEC2",e.vec3="VEC3",e.vec4="VEC4",e.mat2="MAT2",e.mat3="MAT3",e.mat4="MAT4",e))(fe||{}),Ur=(e=>(e[e.points=0]="points",e[e.lines=1]="lines",e[e.lineLoop=2]="lineLoop",e[e.lineStrip=3]="lineStrip",e[e.triangles=4]="triangles",e[e.triangleStrip=5]="triangleStrip",e[e.triangleFan=6]="triangleFan",e))(Ur||{});const Zt=class e{constructor(t){var i;if(this.gltf=t,this._materials=[],this._images=[],this.meshes=[],(null==(i=t.gltf.extensionsRequired)?void 0:i.includes("KHR_draco_mesh_compression"))&&null===e._dracoDecoderModule)throw new Error("Unable to import GLTF. Draco decoder module is not connected");this._initImages(),this._initMaterials(),this._initMeshes()}static connectDracoDecoderModule(t){e._dracoDecoderModule=t}static async loadGlb(t){const i=await Bc.load(t);return new e(i)}getObjects3d(){const e=[];for(let t=0;t<this.meshes.length;t++)for(let i=0;i<this.meshes[t].primitives.length;i++)void 0!==this.meshes[t].primitives[i].object3d&&e.push(this.meshes[t].primitives[i].object3d);return e}toEntities(){const e=[];for(const t of this.gltf.gltf.scenes){if(void 0===t||void 0===t.nodes)return[];for(const i of t.nodes){const t=this.gltf.gltf.nodes[i];void 0===t.mesh&&void 0===t.children||e.push(this._nodeToEntity(t))}}return e}_nodeToEntity(e,t){const i=new G({name:e.name,cartesian:new v(0,0,0),relativePosition:void 0!==t});let s=null;if(void 0!==e.mesh&&(s=this.meshToEntity(this.meshes[e.mesh],t),i.appendChild(s)),void 0!==e.matrix){const t=new tt;t.set(e.matrix),i.setCartesian3v(t.getPosition()),i.setDirectQuaternionRotation(t.getQuat()),i.setScale3v(t.getScaling())}if(void 0!==e.translation&&void 0===e.matrix&&(i.relativePosition=!0,i.setCartesian(e.translation[0],e.translation[1],e.translation[2])),void 0!==e.rotation&&void 0===e.matrix&&i.setDirectQuaternionRotation(new F(e.rotation[0],e.rotation[1],e.rotation[2],e.rotation[3])),void 0!==e.scale&&void 0===e.matrix&&i.setScale3v(new v(e.scale[0],e.scale[1],e.scale[2])),void 0!==e.children)for(const t of e.children){const e=this._nodeToEntity(this.gltf.gltf.nodes[t],i);s?s.appendChild(e):i.appendChild(e)}return i}meshToEntity(e,t){const i=new G({name:e.name,cartesian:new v(0,0,0),relativePosition:!0,independentPicking:!0});return e.primitives.map((e=>{i.appendChild(new G({name:e.name,relativePosition:!0,geoObject:{object3d:e.object3d,tag:e.name}}))})),i}_initImages(){if(this.gltf.gltf.images)for(const e of this.gltf.gltf.images)this._images.push({src:e.uri,element:this._getImage(e.mimeType,e.bufferView),mimeType:e.mimeType,name:e.name})}_getImage(e,t){if(t&&e){const i=this.gltf.gltf.bufferViews[t],s=URL.createObjectURL(new Blob([this.gltf.bin[i.buffer].slice(i.byteOffset,i.byteOffset+i.byteLength)],{type:e})),r=new Image;return r.src=s,r}}_initMaterials(){if(this.gltf.gltf.materials)for(const e of this.gltf.gltf.materials){const t={name:e.name,emissiveFactor:e.emissiveFactor,alphaMode:e.alphaMode,alphaCutoff:e.alphaCutoff,doubleSided:e.doubleSided};if(e.pbrMetallicRoughness){if(e.pbrMetallicRoughness.baseColorFactor&&(t.baseColorFactor=e.pbrMetallicRoughness.baseColorFactor),e.pbrMetallicRoughness.baseColorTexture){const i=this.gltf.gltf.textures[e.pbrMetallicRoughness.baseColorTexture.index].source;void 0!==i&&(t.baseColorTexture={image:this._images[i],texCoord:e.pbrMetallicRoughness.baseColorTexture.texCoord})}if(e.pbrMetallicRoughness.metallicRoughnessTexture){const i=this.gltf.gltf.textures[e.pbrMetallicRoughness.metallicRoughnessTexture.index].source;void 0!==i&&(t.metallicRoughnessTexture={image:this._images[i],texCoord:e.pbrMetallicRoughness.metallicRoughnessTexture.texCoord})}}if(e.normalTexture){const i=this.gltf.gltf.textures[e.normalTexture.index].source;void 0!==i&&(t.normalTexture={image:this._images[i],texCoord:e.normalTexture.texCoord,scale:e.normalTexture.scale})}if(e.occlusionTexture){const i=this.gltf.gltf.textures[e.occlusionTexture.index].source;void 0!==i&&(t.occlusionTexture={image:this._images[i],texCoord:e.occlusionTexture.texCoord,strength:e.occlusionTexture.strength})}if(e.emissiveTexture){const i=this.gltf.gltf.textures[e.emissiveTexture.index].source;void 0!==i&&(t.emissiveTexture={image:this._images[i],texCoord:e.emissiveTexture.texCoord})}this._materials.push(t)}}_initMeshes(){this.meshes=[];for(let e=0;e<this.gltf.gltf.meshes.length;e++){const t=this.gltf.gltf.meshes[e],i={name:t.name,primitives:[]};for(let s=0;s<t.primitives.length;s++)i.primitives.push(this._buildPrimitive(t,t.primitives[s],`${e}-${s}`));this.meshes.push(i)}}_buildPrimitive(t,i,s){var r,n;let o=null;const a=this._materials[i.material||0],l=null!=(r=a.baseColorTexture)&&r.texCoord?`TEXCOORD_${a.baseColorTexture.texCoord}`:"TEXCOORD_0";if(null!=(n=i.extensions)&&n.KHR_draco_mesh_compression){const r=i.extensions.KHR_draco_mesh_compression,n=this.gltf.gltf.bufferViews[r.bufferView],l=n.byteOffset||0,h=e._dracoDecoderModule,c=new h.Decoder,d=new h.DecoderBuffer;if(d.Init(new Int8Array(this.gltf.bin[n.buffer].slice(l,l+n.byteLength)),n.byteLength),c.GetEncodedGeometryType(d)!==h.TRIANGULAR_MESH)throw new Error("Draco compressed data is not a mesh");const _=new h.Mesh;if(!c.DecodeBufferToMesh(d,_).ok()||0===_.ptr)throw new Error("Failed to decode Draco mesh");const u=_.num_faces(),f=new Uint32Array(3*u),g=new h.DracoInt32Array;for(let e=0;e<u;e++)c.GetFaceFromMesh(_,e,g),f[3*e]=g.GetValue(0),f[3*e+1]=g.GetValue(1),f[3*e+2]=g.GetValue(2);h.destroy(g);const p={};for(const e in r.attributes){const t=r.attributes[e],i=c.GetAttributeByUniqueId(_,t),s=_.num_points(),n=i.num_components(),o=new h.DracoFloat32Array;c.GetAttributeFloatForAllPoints(_,i,o);const a=new Float32Array(s*n);for(let e=0;e<a.length;e++)a[e]=o.GetValue(e);h.destroy(o),p[e]=a}h.destroy(_),h.destroy(d),h.destroy(c),o={name:`${t.name}/${a.name}/${s}`,vertices:p.POSITION,indices:f,mode:i.mode?i.mode:Ur.triangles,material:this._materials[i.material||0]||void 0,normals:p.NORMAL,texCoords:void 0}}else{const r=l?i.attributes[l]:void 0,n=r?this.gltf.gltf.accessors[r]:void 0;o={name:`${t.name}/${a.name}/${s}`,indices:i.indices?e._access(this.gltf.gltf.accessors[i.indices],this.gltf):void 0,mode:i.mode?i.mode:Ur.triangles,material:this._materials[i.material||0]||void 0,vertices:e._access(this.gltf.gltf.accessors[i.attributes.POSITION],this.gltf),normals:e._access(this.gltf.gltf.accessors[i.attributes.NORMAL],this.gltf),texCoords:n?e._access(n,this.gltf):void 0}}if(null===o)throw new Error("Unable to build primitive");return o.object3d=e._toObject3d(o),o}static _toObject3d(e){var t,i,s,r,n,o,a,l,h,c,d,_,u;return new $({name:e.name,vertices:Array.from(e.vertices),normals:Array.from(e.normals),texCoords:e.texCoords?Array.from(e.texCoords):void 0,indices:Array.from(e.indices),normalTextureImage:null==(i=null==(t=e.material)?void 0:t.normalTexture)?void 0:i.image.element,normalTextureSrc:null==(r=null==(s=e.material)?void 0:s.normalTexture)?void 0:r.image.src,colorTextureImage:null==(o=null==(n=e.material)?void 0:n.baseColorTexture)?void 0:o.image.element,colorTextureSrc:null==(l=null==(a=e.material)?void 0:a.baseColorTexture)?void 0:l.image.src,metallicRoughnessTextureImage:null==(c=null==(h=e.material)?void 0:h.occlusionTexture)?void 0:c.image.element,metallicRoughnessTextureSrc:null==(_=null==(d=e.material)?void 0:d.occlusionTexture)?void 0:_.image.src,color:null==(u=e.material)?void 0:u.baseColorFactor})}static _access(e,t){const i=t.gltf.bufferViews[e.bufferView],s=t.bin[i.buffer];let r=i.byteOffset||0;void 0!==e.byteOffset&&(r+=e.byteOffset);const n=s.slice(r,r+i.byteLength);switch(e.type){case fe.scalar:return this._getTensor(n,e,1,i.byteStride);case fe.vec2:return this._getTensor(n,e,2,i.byteStride);case fe.vec3:return this._getTensor(n,e,3,i.byteStride);case fe.vec4:case fe.mat2:return this._getTensor(n,e,4,i.byteStride);case fe.mat3:return this._getTensor(n,e,9,i.byteStride);case fe.mat4:return this._getTensor(n,e,16,i.byteStride);default:throw new Error("Unknown accessor type")}}static _getTensor(e,t,i,s){if(t.componentType===we.ushort)return new Uint16Array(e,0,t.count*i);if(t.componentType===we.short)return new Int16Array(e,0,t.count*i);if(t.componentType===we.uint)return new Uint32Array(e,0,t.count*i);if(t.componentType===we.float)return new Float32Array(e,0,t.count*i);if(t.componentType===we.ubyte)return new Uint8Array(e,0,t.count*i);if(t.componentType===we.byte)return new Int8Array(e,0,t.count*i);throw new Error("Unknown component type")}};Zt._dracoDecoderModule=null;let mo=Zt;const Wc="0.28.4";(globalThis.og??(globalThis.og={})).version="0.28.4";export{_i as ALIGN,je as BilTerrain,Qa as Billboard,gc as Bing,Pi as Camera,ss as CanvasTiles,Nr as Clock,Q as Control,La as EarthQuadTreeStrategy,Or as Easing,qr as Ellipsoid,Mi as EmptyTerrain,G as Entity,se as EntityCollection,Rc as EquiQuadTreeStrategy,bi as Events,U as Extent,Rt as Framebuffer,Ca as GeoImage,yr as GeoObject,cc as GeoTexture2d,dc as GeoVideo,Pa as Geoid,vr as Geometry,ai as GeometryTypeEnum,go as Globe,hc as GlobusRgbTerrain,gn as GlobusTerrain,mo as Gltf,Be as Handler,uc as KML,Go as LAYER_EVENTS,tl as LOCAL_FORWARD,el as Label,zt as Layer,Il as LightSource,qi as Line2,Jt as Line3,Sa as Loader,L as LonLat,Se as Mat3,tt as Mat4,Uo as Material,ch as MoveAxisEntity,Ta as Multisample,$ as Object3d,_c as OpenStreetMap,vt as Plane,Ri as Planet,wa as PlanetCamera,xr as PointCloud,br as Polyline,qc as Popup,X as Program,Is as QuadTreeStrategy,F as Quat,V as Ray,de as RenderNode,Ac as Renderer,St as RgbTerrain,Tr as Strip,H as Vec2,v as Vec3,et as Vec4,_t as Vector,me as WMS,Mc as Wgs84QuadTreeStrategy,Ds as XYZ,Fc as bv,Nc as control,lt as createEvents,W as input,Dc as jd,Uc as layer,Gc as mars,kc as math,Ic as mercator,jc as moon,Yc as quadTreeStrategyType,Hc as scene,Vc as terrain,zc as utils,Wc as version,Oc as webgl,So as wgs84};
|
|
2
2
|
//# sourceMappingURL=og.es.js.map
|