UNPKG

maplibre-gl-nightlayer

Version:

A Night Layer for MapLibre GL JS

73 lines (58 loc) 20.4 kB
"use strict";var nightLayer=(()=>{var L=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var J=(r,t)=>{for(var e in t)L(r,e,{get:t[e],enumerable:!0})},Q=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of H(t))!K.call(r,n)&&n!==e&&L(r,n,{get:()=>t[n],enumerable:!(i=X(t,n))||i.enumerable});return r};var tt=r=>Q(L({},"__esModule",{value:!0}),r);var wt={};J(wt,{NightLayer:()=>R,default:()=>$t,getSubsolarPoint:()=>z});function b(r,t="Digits must be an integer"){if(typeof r=="bigint"){let e=Number(r),i=2**53-1;if(e>i||e<-i)throw Error(t);return e}if(!Number.isFinite(r)||!Number.isInteger(r))throw Error(t);return r}function M(r){let t=b(r);return t<0?0:t}function et(r,t="Value must be an integer"){if(typeof r=="bigint")return r;if(!Number.isFinite(r)||!Number.isInteger(r))throw Error(t);return BigInt(r)}function it(r){return r<D.length?D[r]:5n**BigInt(r)}function y(r){return r<I.length?I[r]:10n**BigInt(r)}function B(r,t,e){let i=BigInt(t);if(i<=0n)return new $(1n);let n=new $(1n),s=r.clone();for(;i&1n&&n.mul$(s,e),i>>=1n,i!==0n;)s.mul$(s,e);return n}function rt(r,t,e,i){if(t.isZero()||i<=0)return new $(1n);let{guardPrec:n,rootPrec:s}=ot(e,i),o=A(t.coeff).toString().padStart(i,"0"),a=r.round(s),u=new $(1n);for(let h=0;h<i;h++){a=a.root(10n,s);let f=o.charCodeAt(h)-48;if(f<=0)continue;let l=B(a.clone(),f,n);u.mul$(l,n)}return u.round$(e)}function A(r){return r<0n?-r:r}function U(r){if(r==="")throw Error("Invalid number");let t=1n,e=r;if(e[0]==="-"?(t=-1n,e=e.slice(1)):e[0]==="+"&&(e=e.slice(1)),e==="")throw Error("Invalid number");let i=e.indexOf("."),n=i>=0?e.length-i-1:0,s=-1;for(let a=0;a<e.length;a++){let u=e.charCodeAt(a);if(u!==46&&u!==48){s=a;break}}if(s===-1)return{coeff:0n,digits:n};let o;return o=i<0||s>i?e.slice(s):e.slice(s,i)+e.slice(i+1),{coeff:t*BigInt(o),digits:n}}function O(r){let t=r.search(/[eE]/);if(t===-1)return U(r);let e=r.slice(0,t),i=r.slice(t+1);if(i.trim()==="")throw Error("Invalid number");let{coeff:n,digits:s}=U(e),o=BigInt(i),a=BigInt(2**53-1);if(o>a||o<-a)throw Error("Exponent is out of range");return{coeff:n,digits:s-Number(o)}}function _(r,t){if(r.digits>=t.digits){let i=r.digits-t.digits;return{digits:r.digits,aCoeff:r.coeff,bCoeff:i===0?t.coeff:t.coeff*y(i)}}let e=t.digits-r.digits;return{digits:t.digits,aCoeff:r.coeff*y(e),bCoeff:t.coeff}}function j(r){let t=Math.max(0,r);return Math.min(2**53-1,t)}function nt(r,t,e){let i=j(t),n=j(e),s=Math.max(i,n)+1,o=Math.max(s,1),a=r+o;for(;;){let u=Math.ceil(a*ut)+o,h=Math.max(u*2,1),f=Math.max(s,Math.ceil(Math.log10(h))+1);if(f<=o){let l=a+o;return{guardPrec:o,fracPrec:a,bits:u,divPrec:l}}o=f,a=r+o}}function ot(r,t){let e=Math.max(1,t),i=Math.max(6,Math.ceil(Math.log10(e*4))+2),n=r+i;return{guardPrec:n,rootPrec:n+Math.max(i,6)}}function st(r,t){let e=Math.max(1,t.toString().replace("-","").length);return{iterPrec:r+Math.max(12,e+4),stopShift:r+2}}function G(r,t,e,i){let n=[],s=[],o=new $(t),a=1n,u=e+Math.max(i,1);for(;o.le(r);)n.push(o),s.push(a),o=o.mul(o),a*=2n;let h=new $(r),f=0n;for(let l=n.length-1;l>=0;l--){let d=n[l];h.ge(d)&&(h.div$(d,u),f+=s[l])}return{exponent:f,remainder:h}}function at(r,t,e,i){let n=e+Math.max(i,1);if(r.eq(v))return{exponent:0n,remainder:v.clone()};if(r.ge(v))return G(r,t,e,i);let s=G(v.div(r,n),t,e,i);return s.remainder.eq(v)?{exponent:-s.exponent,remainder:v.clone()}:{exponent:-s.exponent-1n,remainder:v.div(s.remainder,n).mul$(t)}}var $=class x{coeff;digits;constructor(t,e){if(t instanceof x){this.coeff=t.coeff,this.digits=t.digits;return}switch(typeof t){case"number":if(t!==t||t===1/0||t===-1/0)throw Error("Invalid number");({coeff:this.coeff,digits:this.digits}=O(t.toString()));return;case"string":{let i=t.trim();if(i==="")throw Error("Invalid number");({coeff:this.coeff,digits:this.digits}=O(i))}return;case"bigint":this.coeff=t,this.digits=e==null?0:b(e);return;case"object":if(t&&"coeff"in t&&typeof t.coeff=="bigint"&&"digits"in t){this.coeff=t.coeff,this.digits=b(t.digits);return}}throw Error("Invalid input type for Decimal")}clone(){return new x(this)}#t(t,e=0){return C(t)?(this.digits=t.digits,this.coeff=t.coeff,this):(this.coeff=t,this.digits=e,this)}#r(t,e,i){let n=this.coeff,s=t.coeff,o=t.digits+e-this.digits;o>=0?n*=y(o):s*=y(-o);let a=n/s,u=n-a*s;if(u!==0n&&i!=="trunc"){let h=n>=0n;switch(i){case"floor":h||(a-=1n);break;case"ceil":h&&(a+=1n);break;case"round":{let f=A(u),l=s<0n?-s:s;f*2n>=l&&(a+=h?1n:-1n);break}default:break}}return this.#t(a,e)}#i(t,e="trunc"){let i=b(t);if(this.isZero())return this.digits=i,this;if(i===this.digits)return this;if(i>this.digits){let n=y(i-this.digits);return this.coeff*=n,this.digits=i,this}return this.#r(v,i,e)}#o(){if(this.coeff===0n)return this.digits=0,this;if(this.digits<=0)return this;for(;this.digits>0&&this.coeff%10n==0n;)this.coeff/=10n,--this.digits;return this}round$(t=0,e=!1){let i=b(t);return!e&&this.digits<=i?this:this.#i(i,"round")}round(t=0,e=!1){return this.clone().round$(t,e)}roundBy$(t,e="round"){let i=new x(t).abs();if(i.isZero())throw Error("Cannot align to zero");return this.div$(i,0,e).mul$(i)}roundBy(t,e="round"){return this.clone().roundBy$(t,e)}floor$(t=0,e=!1){let i=b(t);return!e&&this.digits<=i?this:this.#i(i,"floor")}floor(t=0,e=!1){return this.clone().floor$(t,e)}floorBy$(t){return this.roundBy$(t,"floor")}floorBy(t){return this.clone().floorBy$(t)}ceil$(t=0,e=!1){let i=b(t);return!e&&this.digits<=i?this:this.#i(i,"ceil")}ceil(t=0,e=!1){return this.clone().ceil$(t,e)}ceilBy$(t){return this.roundBy$(t,"ceil")}ceilBy(t){return this.clone().ceilBy$(t)}trunc$(t=0,e=!1){let i=b(t);return!e&&this.digits<=i?this:this.#i(i,"trunc")}trunc(t=0,e=!1){return this.clone().trunc$(t,e)}rescale$(t,e="trunc"){return t==null?this.#o():this.#i(t,e)}rescale(t,e="trunc"){return this.clone().rescale$(t,e)}truncBy$(t){return this.roundBy$(t,"trunc")}truncBy(t){return this.clone().truncBy$(t)}#n(t){let e=this.clone();return t(this),[this,e.sub$(this)]}split$(t,e="floor"){return this.#n(i=>i.#i(t??0,e))}split(t,e="floor"){return this.clone().split$(t,e)}splitBy$(t,e="floor"){return this.#n(i=>i.roundBy$(t,e))}splitBy(t,e="floor"){return this.clone().splitBy$(t,e)}frac$(){if(this.digits<=0)return this.coeff=0n,this.digits=0,this;let t=y(this.digits);return this.coeff%=t,this}frac(){return this.clone().frac$()}neg$(t){return t!==!1&&(this.coeff=-this.coeff),this}neg(t){return this.clone().neg$(t)}isZero(){return this.coeff===0n}isPositive(){return this.coeff>0n}isNegative(){return this.coeff<0n}add$(t){let e=c(t),{digits:i,aCoeff:n,bCoeff:s}=_(this,e);return this.coeff=n+s,this.digits=i,this}add(t){return this.clone().add$(t)}sub$(t){let e=c(t),{digits:i,aCoeff:n,bCoeff:s}=_(this,e);return this.coeff=n-s,this.digits=i,this}sub(t){return this.clone().sub$(t)}mul$(t,e){let i=c(t);return this.coeff*=i.coeff,this.digits+=i.digits,e!==void 0&&this.round$(e),this}mul(t,e){return this.clone().mul$(t,e)}shift10$(t){let e=b(t,"Shift amount must be an integer");return e===0||(this.digits-=e),this}shift10(t){return this.clone().shift10$(t)}inverse$(t=p){if(this.isZero())throw Error("Division by zero");let e=M(t),i=this.clone();return this.#t(1n).div$(i,e)}inverse(t=p){return this.clone().inverse$(t)}div$(t,e,i="round"){let n=e===void 0,s=M(e??p),o=c(t);if(o.isZero())throw Error("Division by zero");return this.isZero()?this:(this.#r(o,s,i),n?this.#o():this)}div(t,e,i="round"){return this.clone().div$(t,e,i)}abs$(){return this.isNegative()&&(this.coeff=-this.coeff),this}abs(){return this.clone().abs$()}mod$(t){let e=c(t);if(e.isZero())throw Error("Division by zero");let{digits:i,aCoeff:n,bCoeff:s}=_(this,e);return this.coeff=n%s,this.digits=i,this}mod(t){return this.clone().mod$(t)}modPositive$(t){let e=c(t);if(e.isNegative())throw Error("Modulo divisor must be positive");return this.mod$(e),this.isNegative()&&this.add$(e),this}modPositive(t){return this.clone().modPositive$(t)}clamp$(t,e){let i=c(t),n=c(e);if(i&&n&&i.gt(n))throw Error("Invalid clamp range");return i&&this.lt(i)?(this.coeff=i.coeff,this.digits=i.digits,this):n&&this.gt(n)?(this.coeff=n.coeff,this.digits=n.digits,this):this}clamp(t,e){return this.clone().clamp$(t,e)}cmp(t){let e=c(t),{aCoeff:i,bCoeff:n}=_(this,e);return i===n?0:i>n?1:-1}eq(t){return this.cmp(t)===0}neq(t){return this.cmp(t)!==0}lt(t){return this.cmp(t)<0}gt(t){return this.cmp(t)>0}le(t){return this.cmp(t)<=0}ge(t){return this.cmp(t)>=0}between(t,e){let i=c(t),n=c(e);if(i&&n&&i.gt(n))throw Error("Invalid between range");return!(i&&this.lt(i)||n&&this.gt(n))}isCloseTo(t,e){let i=c(e);if(i.isNegative())throw Error("Tolerance must be non-negative");return this.sub(t).abs$().le(i)}pow$(t,e=p){let i=M(e),n=c(t);if(n.isZero())return this.#t(1n);if(this.isZero()){if(n.isNegative())throw Error("Zero to negative exponent is undefined");return this}let s=n.isNegative(),[o,a]=n.abs().split$(),u=this.clone(),h=a.isZero()?0:a.digits;if(u.isNegative()&&h>0)throw Error("Fractional exponent requires non-negative base");let f=B(u,o.coeff),l=i;h>0&&(l=i+Math.max(4,h));let d=rt(u,a,l,h);h>0&&f.mul$(d,l);let g=l>i?l:i,m=h>0?l:i;return s?this.#t(1n).div$(f,g):(f.round$(g,!0),this.#t(f)),this.round$(m,m===0),this}pow(t,e=p){return this.clone().pow$(t,e)}root$(t,e=p){let i=et(t,"Root degree must be an integer");if(i<=0n)throw Error("Invalid root degree");let n=M(e);if(i===1n)return n<this.digits?this:this.trunc$(n,!0);if(this.isZero())return this;let s=this.isNegative();if(s&&i%2n==0n)throw Error("Even root of negative value is not defined");let o=this.abs(),a=i-1n,{iterPrec:u,stopShift:h}=st(n,i),f=P(-h),l=(()=>{let d=o.number();if(Number.isFinite(d)&&d>0){let g=Number(i);if(g>0){let m=d**(1/g);if(Number.isFinite(m)&&m>0)return new x(m).round$(u,!0)}}return new x(P(o.order()/i)).round$(u,!0)})();this.#t(l.coeff,l.digits),this.isZero()&&this.#t(1n);for(let d=0;d<64;d++){let g=B(this.clone(),a,u);if(g.isZero())break;let m=o.div(g,u),w=this.mul(a,u).add$(m).div$(i,u);if(w.isCloseTo(this,f)||w.eq(this)){this.#t(w);break}this.#t(w)}return this.round$(u,!0),this.round$(n,n===0),s&&this.neg$(),this}root(t,e=p){return this.clone().root$(t,e)}sqrt$(t=p){return this.root$(2n,t)}sqrt(t=p){return this.clone().sqrt$(t)}log$(t,e=p){let i=M(e),n=new x(t);if(!this.isPositive())throw Error("Logarithm argument must be positive");if(!n.isPositive())throw Error("Logarithm base must be positive");if(n.eq(v))throw Error("Logarithm base cannot be one");let{guardPrec:s,fracPrec:o,bits:a,divPrec:u}=nt(i,n.digits,this.digits),h=n.lt(v),f=h?v.div(n,u):n,{exponent:l,remainder:d}=at(this,f,o,s);if(this.#t(l),o>0){let m=0n;for(let w=0;w<a;w++)d.mul$(d,u),m<<=1n,d.ge(f)&&(d.div$(f,u),m|=1n);m!==0n&&this.add$({coeff:m*it(a),digits:a})}let g=i===0?0:o;return this.round$(g),h&&this.neg$(),this}log(t,e=p){return this.clone().log$(t,e)}sign$(){return this.isZero()?this:(this.coeff=this.coeff<0n?-1n:1n,this.digits=0,this)}sign(){return this.clone().sign$()}order(){if(this.isZero())throw RangeError("order undefined for 0");return BigInt(A(this.coeff).toString().length)-1n-BigInt(this.digits)}toFixed(t){let e="Fraction digits must be a non-negative integer",i=b(t,e);if(i<0)throw Error(e);return this.round(i,!0).toString()}toString(){if(this.coeff===0n)return this.digits<=0?"0":`0.${"0".repeat(this.digits)}`;let t=this.coeff<0n,e=t?"-":"",i=(t?-this.coeff:this.coeff).toString();if(this.digits<=0)return`${e}${i}${"0".repeat(-this.digits)}`;let n=this.digits,s=i.length;if(s>n){let o=s-n;return`${e}${i.slice(0,o)}.${i.slice(o)}`}return s===n?`${e}0.${i}`:`${e}0.${"0".repeat(n-s)}${i}`}[Symbol.for("nodejs.util.inspect.custom")](t,e){return"colors"in e&&e?.colors?`\x1B[33m${this.toString()}\x1B[m \x1B[90m(${this.coeff} * 10 ** ${-this.digits})\x1B[m`:this.toString()}number(){return Number(this.toString())}integer(){return this.digits<=0?this.coeff*y(-this.digits):this.coeff/y(this.digits)}},p=18,ut=Math.log2(10),v=new $(1n),D=[],I=[];(function(){for(let r=0;r<256;r++)I[r]=10n**BigInt(r),D[r]=5n**BigInt(r)})();function c(r){return r==null||C(r)?r:new $(r)}function C(r){return r instanceof $}function Y(r){return!!(C(r)||typeof r=="object"&&r&&"coeff"in r&&"digits"in r&&typeof r.coeff=="bigint")}function ht(r){return!!(Y(r)||typeof r=="string"||typeof r=="number"||typeof r=="bigint")}function P(r){return new $(1n,-b(r,"Exponent must be an integer")||0)}function T(...r){let t=null,e=null;for(let i=0;i<r.length;i++){let n=c(r[i]);n!=null&&((t===null||n.lt(t))&&(t=n),(e===null||n.gt(e))&&(e=n))}return[t,e]}function ft(...r){return T(...r)[0]}function lt(...r){return T(...r)[1]}function ct(r,t){return r===t||r!=null&&t!=null&&c(r).eq(c(t))}Object.assign(c,{isDecimal:C,isDecimalType:Y,isDecimalLike:ht,pow10:P,minmax:T,min:ft,max:lt,equals:ct});var{createTileMesh:W,MercatorCoordinate:N}=maplibregl;function dt(r){return r*Math.PI/180}function mt(r){return r/Math.PI*180}var Z=86400n,gt=719528n,q=146097n;function E(r,t){let e=r/t;return r%t!==0n&&r<0n!=t<0n?e-1n:e}function pt(r,t){return r-E(r,t)*t}function bt(r){return r%4n!==0n?!1:r%100n!==0n?!0:r%400n===0n}function vt(r){let t=r.floor(0),e=t.integer(),i=r.sub(t),n=E(e,Z),s=pt(e,Z),o=n+gt;o-=60n;let a=E(o,q),u=o-a*q,h=E(u-u/1460n+u/36524n-u/146096n,365n),f=h+a*400n,l=u-(365n*h+h/4n-h/100n),d=(5n*l+2n)/153n,g=l-(153n*d+2n)/5n+1n,m=d+3n;m>12n&&(m-=12n,f+=1n);let w=[31n,bt(f)?29n:28n,31n,30n,31n,30n,31n,31n,30n,31n,30n,31n],F=g;for(let S=0;S<Number(m)-1;S+=1)F+=w[S];let V=c(s.toString()).add(i);return{dayOfYear:F,secondsOfDayDecimal:V}}function k(r){let[t,e,i,n]=r.map(s=>s/255);return[t*n,e*n,i*n,n]}function z(r){r==null&&(r=c(Date.now()/1e3));let{dayOfYear:t,secondsOfDayDecimal:e}=vt(r),i=c(t.toString()).add(e.div(86400)).number(),n=2*Math.PI/365.24,s=dt(23.44),o=.0167,a=(i+9)*n,u=a+2*o*Math.sin((i-3)*n),h=(a-Math.atan2(Math.sin(u),Math.cos(u)*Math.cos(s)))/Math.PI,f=720*(h-Math.trunc(h+.5)),d=-15*(e.div(3600).number()-12+f/60),g=mt(Math.asin(Math.sin(-s)*Math.cos(u)));return{lng:d,lat:g}}var R=class{id="nightlayer";type="custom";renderingMode="2d";#t;#r;#i;#o;#n;#h;#f;#l;#s;#e;#a;#u;#c;#d;constructor(t={}){this.#r=t.opacity??.5,this.#f=t.twilightSteps??0,this.#l=t.twilightAttenuation??.5,this.#h=t.updateInterval??1e4,this.setColor(t.color??[0,0,0,255]),this.setDaytimeColor(t.daytimeColor??[0,0,0,0]),this.setDate(t.date??null)}#m(){let t=this.#t===null;this.#n&&(clearInterval(this.#n),this.#n=void 0),t&&this.#h>0&&(this.#n=setInterval(()=>this.#e?.triggerRepaint(),this.#h))}getSubsolarPoint(){return z(this.#t)}getDate(){return this.#t?new Date(this.#t.mul(1e3).number()):null}getTime(){return this.#t}setDate(t){this.setTime(t)}setTime(t){t instanceof Date&&(t=c(t.getTime()).div(1e3)),this.#t=c(t),this.#m(),this.#e?.triggerRepaint()}getOpacity(){return this.#r}setOpacity(t){this.#r=t,this.#e?.triggerRepaint()}getColor(){return this.#i}setColor(t){this.#i=[...t.slice(0,3),t?.[3]??255],this.#e?.triggerRepaint()}getDaytimeColor(){return this.#o}setDaytimeColor(t){this.#o=[...t.slice(0,3),t?.[3]??255],this.#e?.triggerRepaint()}getTwilightSteps(){return this.#f}setTwilightSteps(t){this.#f=t,this.#e?.triggerRepaint()}getTwilightAttenuation(){return this.#l}setTwilightAttenuation(t){this.#l=t,this.#e?.triggerRepaint()}getUpdateInterval(){return this.#h}setUpdateInterval(t){this.#h=t,this.#m()}onAdd(t,e){this.#s=new Map,this.#a=e.createBuffer(),this.#u=e.createBuffer(),this.#e=t}onRemove(){this.#s=void 0,this.#e=void 0,this.#a=void 0,this.#u=void 0}#g(t,e){let n=`#version 300 es precision highp float; in vec2 a_position; out vec2 v_position; ${!e.vertexShaderPrelude?` uniform mat4 u_matrix; vec4 projectTile(vec2 pos) { return u_matrix * vec4(pos, 0., 1.); } `:` ${e.vertexShaderPrelude} ${e.define} `} void main() { gl_Position = projectTile(a_position); v_position = a_position; } `,s=`#version 300 es precision highp float; in vec2 v_position; out vec4 fragColor; uniform vec2 u_subsolar; uniform float u_opacity; uniform float u_twilight_steps; uniform float u_twilight_attenuation; uniform vec4 u_daytime_color; uniform vec4 u_night_color; vec2 mercatorToLngLat(vec2 mercator) { // 0 <= x <= 1, 0 <= y <= 1 float x = mercator.x; float y = mercator.y; float lng = x * 360.0 - 180.0; float lat = degrees(2.0 * atan(exp(${Math.PI} * (1.0 - 2.0 * y))) - ${Math.PI/2}); return vec2(lng, lat); } void main() { vec2 lnglat = mercatorToLngLat(v_position); vec2 observer = radians(lnglat); vec2 subsolar = radians(u_subsolar); float A = sin(observer.y) * sin(subsolar.y); float B = cos(observer.y) * cos(subsolar.y) * cos(subsolar.x - observer.x); float altitude = degrees(asin(A + B)); float twilightStepAngle = 6.0; float twilightBegins = -0.8333333; float twilightSteps = u_twilight_steps; // Attenuation for each twilightStepAngle float att = u_twilight_attenuation; float twilightLevel = -altitude / twilightStepAngle; if (twilightSteps > 0.) { twilightLevel = ceil(clamp(twilightLevel, 0., twilightSteps)); if (altitude > twilightBegins) { // XXX: Adjust for sunset/sunrise line twilightLevel = 0.; } } float brightness = clamp(pow(clamp(1. - att, 0., 1.), twilightLevel), 0., 1.); fragColor = mix(u_night_color, u_daytime_color, brightness) * u_opacity; }`,o=t.createShader(t.VERTEX_SHADER);if(!o)throw new Error("failed to create vertex shader");t.shaderSource(o,n),t.compileShader(o);let a=t.createShader(t.FRAGMENT_SHADER);if(!a)throw new Error("failed to create fragment shader");t.shaderSource(a,s),t.compileShader(a);let u=t.createProgram();if(!u)throw new Error("failed to create program");return t.attachShader(u,o),t.attachShader(u,a),t.linkProgram(u),u}#p(t){if(!this.#e||!this.#a||!this.#u)return;let[e,i]=this.#e.getBounds().toArray(),n=Math.floor(N.fromLngLat(e).x),s=Math.ceil(N.fromLngLat(i).x),o=this.#e.style?.projection?.name==="globe"?"globe":[n,s].join(":");if(o===this.#d)return;let a;o==="globe"?(a=W({granularity:100,generateBorders:!1,extendToNorthPole:!0,extendToSouthPole:!0},"16bit"),a.vertices=new Float32Array(new Int16Array(a.vertices)).map(u=>u/8192).buffer):a={vertices:new Float32Array([n,0,s,0,n,1,n,1,s,0,s,1]).buffer,indices:new Uint16Array([0,1,2,3,4,5]).buffer,uses32bitIndices:!1},t.bindBuffer(t.ARRAY_BUFFER,this.#a),t.bufferData(t.ARRAY_BUFFER,a.vertices,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.#u),t.bufferData(t.ELEMENT_ARRAY_BUFFER,a.indices,t.DYNAMIC_DRAW),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null),this.#c=a.indices.byteLength/2,this.#d=o}render(t,e,i){if(i||(i=e),!this.#s||!this.#a||!this.#u||!this.#e)return;let n=i.shaderData||{},s=n.variantName||"default";this.#s.has(s)||this.#s.set(s,this.#g(t,n));let o=this.#s.get(s);if(!o)return;let{lng:a,lat:u}=this.getSubsolarPoint();if(t.useProgram(o),t.uniform2fv(t.getUniformLocation(o,"u_subsolar"),[a,u]),t.uniform1f(t.getUniformLocation(o,"u_opacity"),this.#r),t.uniform4fv(t.getUniformLocation(o,"u_night_color"),k(this.#i)),t.uniform4fv(t.getUniformLocation(o,"u_daytime_color"),k(this.#o)),t.uniform1f(t.getUniformLocation(o,"u_twilight_steps"),this.#f),t.uniform1f(t.getUniformLocation(o,"u_twilight_attenuation"),this.#l),"getProjectionDataForCustomLayer"in this.#e.transform){let f=this.#e.transform.getProjectionDataForCustomLayer(!0);t.uniformMatrix4fv(t.getUniformLocation(o,"u_projection_fallback_matrix"),!1,f.fallbackMatrix),t.uniformMatrix4fv(t.getUniformLocation(o,"u_projection_matrix"),!1,f.mainMatrix),t.uniform4f(t.getUniformLocation(o,"u_projection_tile_mercator_coords"),...f.tileMercatorCoords),t.uniform4f(t.getUniformLocation(o,"u_projection_clipping_plane"),...f.clippingPlane),t.uniform1f(t.getUniformLocation(o,"u_projection_transition"),f.projectionTransition)}else t.uniformMatrix4fv(t.getUniformLocation(o,"u_matrix"),!1,e);this.#p(t),t.bindBuffer(t.ARRAY_BUFFER,this.#a),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.#u);let h=t.getAttribLocation(o,"a_position");t.enableVertexAttribArray(h),t.vertexAttribPointer(h,2,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLES,this.#c,t.UNSIGNED_SHORT,0)}},$t=R;return tt(wt);})();