maplibre-gl-nightlayer 1.0.0-alpha.6 → 1.0.0-alpha.7

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/dist/main.d.ts CHANGED
@@ -116,7 +116,7 @@ export declare class NightLayer implements CustomLayerInterface {
116
116
  * @param attenuation 0.0 means no attenuation, 1.0 means full attenuation.
117
117
  */
118
118
  setTwilightAttenuation(attenuation: number): void;
119
- onAdd(map: MaplibreMap, gl: WebGLRenderingContext): void;
119
+ onAdd(map: MaplibreMap, gl: WebGLRenderingContext | WebGL2RenderingContext): void;
120
120
  onRemove(): void;
121
121
  render(gl: WebGLRenderingContext | WebGL2RenderingContext, matrix: mat4, options: CustomRenderMethodInput): void;
122
122
  render(gl: WebGLRenderingContext | WebGL2RenderingContext, options: CustomRenderMethodInput): void;
package/dist/main.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";import{MercatorCoordinate as f,createTileMesh as p}from"maplibre-gl";function d(c){return c*Math.PI/180}function g(c){return c/Math.PI*180}export class NightLayer{id="nightlayer";type="custom";renderingMode="2d";#o;#n;#a;#s;#u;#h;#e;#t;#i;#r;#c;#f;constructor(t={}){this.#o=t.date??null,this.#n=t.opacity??.5,this.#a=t.color??[0,0,0],this.#s=t.twilightSteps??0,this.#u=t.twilightStepAngle??6,this.#h=t.twilightAttenuation??.5}getSubsolarPoint(t){const r=(t.getTime()-Date.UTC(t.getUTCFullYear(),0,0))/864e5,s=2*Math.PI/365.24,o=d(23.44),n=.0167,e=(r+9)*s,i=e+2*n*Math.sin((r-3)*s),a=(e-Math.atan2(Math.sin(i),Math.cos(i)*Math.cos(o)))/Math.PI,u=720*(a-Math.trunc(a+.5)),l=-15*(t.getUTCHours()+t.getUTCMinutes()/60+t.getUTCSeconds()/3600-12+u/60),m=g(Math.asin(Math.sin(-o)*Math.cos(i)));return{subsolarLng:l,subsolarLat:m}}getDate(){return this.#o}setDate(t){this.#o=t,this.#t?.triggerRepaint()}getOpacity(){return this.#n}setOpacity(t){this.#n=t,this.#t?.triggerRepaint()}getColor(){return this.#a}setColor(t){this.#a=t,this.#t?.triggerRepaint()}getTwilightSteps(){return this.#s}setTwilightSteps(t){this.#s=t,this.#t?.triggerRepaint()}getTwilightStepAngle(){return this.#u}setTwilightStepAngle(t){this.#u=t,this.#t?.triggerRepaint()}getTwilightAttenuation(){return this.#h}setTwilightAttenuation(t){this.#h=t,this.#t?.triggerRepaint()}#l(t){if(!this.#t||!this.#i||!this.#r)return;const[r,s]=this.#t.getBounds().toArray(),o=Math.floor(f.fromLngLat(r).x),n=Math.ceil(f.fromLngLat(s).x),e=this.#t.style?.projection?.name==="globe"?"globe":[o,n].join(":");if(e===this.#f)return;let i;e==="globe"?i=p({granularity:100,generateBorders:!1,extendToNorthPole:!0,extendToSouthPole:!0},"16bit"):i={vertices:new Int16Array([o,0,n,0,o,1,o,1,n,0,n,1]).map(u=>u*8192).buffer,indices:new Uint16Array([0,1,2,3,4,5]).buffer,uses32bitIndices:!1},t.bindBuffer(t.ARRAY_BUFFER,this.#i),t.bufferData(t.ARRAY_BUFFER,i.vertices,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.#r),t.bufferData(t.ELEMENT_ARRAY_BUFFER,i.indices,t.DYNAMIC_DRAW),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null),this.#c=i.indices.byteLength/2,this.#f=e}onAdd(t,r){this.#e=new Map,this.#i=r.createBuffer(),this.#r=r.createBuffer(),this.#t=t}onRemove(){this.#e=void 0,this.#t=void 0,this.#i=void 0,this.#r=void 0}#m(t,r){const o=`#version 300 es
1
+ "use strict";import{MercatorCoordinate as f,createTileMesh as p}from"maplibre-gl";function d(h){return h*Math.PI/180}function g(h){return h/Math.PI*180}export class NightLayer{id="nightlayer";type="custom";renderingMode="2d";#n;#o;#a;#s;#u;#h;#e;#t;#i;#r;#c;#f;constructor(t={}){this.#n=t.date??null,this.#o=t.opacity??.5,this.#a=t.color??[0,0,0],this.#s=t.twilightSteps??0,this.#u=t.twilightStepAngle??6,this.#h=t.twilightAttenuation??.5}getSubsolarPoint(t){const r=(t.getTime()-Date.UTC(t.getUTCFullYear(),0,0))/864e5,s=2*Math.PI/365.24,o=d(23.44),a=.0167,e=(r+9)*s,i=e+2*a*Math.sin((r-3)*s),n=(e-Math.atan2(Math.sin(i),Math.cos(i)*Math.cos(o)))/Math.PI,c=720*(n-Math.trunc(n+.5)),l=-15*(t.getUTCHours()+t.getUTCMinutes()/60+t.getUTCSeconds()/3600-12+c/60),m=g(Math.asin(Math.sin(-o)*Math.cos(i)));return{subsolarLng:l,subsolarLat:m}}getDate(){return this.#n}setDate(t){this.#n=t,this.#t?.triggerRepaint()}getOpacity(){return this.#o}setOpacity(t){this.#o=t,this.#t?.triggerRepaint()}getColor(){return this.#a}setColor(t){this.#a=t,this.#t?.triggerRepaint()}getTwilightSteps(){return this.#s}setTwilightSteps(t){this.#s=t,this.#t?.triggerRepaint()}getTwilightStepAngle(){return this.#u}setTwilightStepAngle(t){this.#u=t,this.#t?.triggerRepaint()}getTwilightAttenuation(){return this.#h}setTwilightAttenuation(t){this.#h=t,this.#t?.triggerRepaint()}onAdd(t,r){this.#e=new Map,this.#i=r.createBuffer(),this.#r=r.createBuffer(),this.#t=t}onRemove(){this.#e=void 0,this.#t=void 0,this.#i=void 0,this.#r=void 0}#l(t,r){const o=`#version 300 es
2
2
  precision highp float;
3
3
 
4
4
  in vec2 a_position;
@@ -16,10 +16,10 @@ ${!r.vertexShaderPrelude?`
16
16
  `}
17
17
 
18
18
  void main() {
19
- gl_Position = projectTile(a_position / 8192.); // scale to 0.0 - 1.0
20
- v_position = a_position / 8192.;
19
+ gl_Position = projectTile(a_position);
20
+ v_position = a_position;
21
21
  }
22
- `,n=`#version 300 es
22
+ `,a=`#version 300 es
23
23
  precision highp float;
24
24
 
25
25
  in vec2 v_position;
@@ -65,4 +65,4 @@ ${!r.vertexShaderPrelude?`
65
65
 
66
66
  fragColor = vec4(v_position, 0.0, 1.0);
67
67
  fragColor = vec4(u_color / 255., 1.0) * darkness * u_opacity;
68
- }`,e=t.createShader(t.VERTEX_SHADER);if(!e)throw new Error("failed to create vertex shader");t.shaderSource(e,o),t.compileShader(e);const i=t.createShader(t.FRAGMENT_SHADER);if(!i)throw new Error("failed to create fragment shader");t.shaderSource(i,n),t.compileShader(i);const a=t.createProgram();if(!a)throw new Error("failed to create program");return t.attachShader(a,e),t.attachShader(a,i),t.linkProgram(a),a}render(t,r,s){if(s||(s=r),!this.#e||!this.#i||!this.#r||!this.#t)return;const o=s.shaderData||{},n=o.variantName||"default";this.#e.has(n)||this.#e.set(n,this.#m(t,o));const e=this.#e.get(n);if(!e)return;const{subsolarLng:i,subsolarLat:a}=this.getSubsolarPoint(this.#o||new Date);if(t.useProgram(e),t.uniform2fv(t.getUniformLocation(e,"u_subsolar"),[i,a]),t.uniform1f(t.getUniformLocation(e,"u_opacity"),this.#n),t.uniform3fv(t.getUniformLocation(e,"u_color"),this.#a),t.uniform1f(t.getUniformLocation(e,"u_twilight_steps"),this.#s),t.uniform1f(t.getUniformLocation(e,"u_twilight_step_angle"),this.#u),t.uniform1f(t.getUniformLocation(e,"u_twilight_attenuation"),this.#h),"getProjectionDataForCustomLayer"in this.#t.transform){const h=this.#t.transform.getProjectionDataForCustomLayer(!0);t.uniformMatrix4fv(t.getUniformLocation(e,"u_projection_fallback_matrix"),!1,h.fallbackMatrix),t.uniformMatrix4fv(t.getUniformLocation(e,"u_projection_matrix"),!1,h.mainMatrix),t.uniform4f(t.getUniformLocation(e,"u_projection_tile_mercator_coords"),...h.tileMercatorCoords),t.uniform4f(t.getUniformLocation(e,"u_projection_clipping_plane"),...h.clippingPlane),t.uniform1f(t.getUniformLocation(e,"u_projection_transition"),h.projectionTransition)}else t.uniformMatrix4fv(t.getUniformLocation(e,"u_matrix"),!1,r);this.#l(t),t.bindBuffer(t.ARRAY_BUFFER,this.#i),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.#r);const u=t.getAttribLocation(e,"a_position");t.enableVertexAttribArray(u),t.vertexAttribPointer(u,2,t.SHORT,!1,0,0),t.drawElements(t.TRIANGLES,this.#c,t.UNSIGNED_SHORT,0)}}export default NightLayer;
68
+ }`,e=t.createShader(t.VERTEX_SHADER);if(!e)throw new Error("failed to create vertex shader");t.shaderSource(e,o),t.compileShader(e);const i=t.createShader(t.FRAGMENT_SHADER);if(!i)throw new Error("failed to create fragment shader");t.shaderSource(i,a),t.compileShader(i);const n=t.createProgram();if(!n)throw new Error("failed to create program");return t.attachShader(n,e),t.attachShader(n,i),t.linkProgram(n),n}#m(t){if(!this.#t||!this.#i||!this.#r)return;const[r,s]=this.#t.getBounds().toArray(),o=Math.floor(f.fromLngLat(r).x),a=Math.ceil(f.fromLngLat(s).x),e=this.#t.style?.projection?.name==="globe"?"globe":[o,a].join(":");if(e===this.#f)return;let i;e==="globe"?(i=p({granularity:100,generateBorders:!1,extendToNorthPole:!0,extendToSouthPole:!0},"16bit"),i.vertices=new Float32Array(new Int16Array(i.vertices)).map(n=>n/8192).buffer):i={vertices:new Float32Array([o,0,a,0,o,1,o,1,a,0,a,1]).buffer,indices:new Uint16Array([0,1,2,3,4,5]).buffer,uses32bitIndices:!1},t.bindBuffer(t.ARRAY_BUFFER,this.#i),t.bufferData(t.ARRAY_BUFFER,i.vertices,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.#r),t.bufferData(t.ELEMENT_ARRAY_BUFFER,i.indices,t.DYNAMIC_DRAW),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null),this.#c=i.indices.byteLength/2,this.#f=e}render(t,r,s){if(s||(s=r),!this.#e||!this.#i||!this.#r||!this.#t)return;const o=s.shaderData||{},a=o.variantName||"default";this.#e.has(a)||this.#e.set(a,this.#l(t,o));const e=this.#e.get(a);if(!e)return;const{subsolarLng:i,subsolarLat:n}=this.getSubsolarPoint(this.#n||new Date);if(t.useProgram(e),t.uniform2fv(t.getUniformLocation(e,"u_subsolar"),[i,n]),t.uniform1f(t.getUniformLocation(e,"u_opacity"),this.#o),t.uniform3fv(t.getUniformLocation(e,"u_color"),this.#a),t.uniform1f(t.getUniformLocation(e,"u_twilight_steps"),this.#s),t.uniform1f(t.getUniformLocation(e,"u_twilight_step_angle"),this.#u),t.uniform1f(t.getUniformLocation(e,"u_twilight_attenuation"),this.#h),"getProjectionDataForCustomLayer"in this.#t.transform){const u=this.#t.transform.getProjectionDataForCustomLayer(!0);t.uniformMatrix4fv(t.getUniformLocation(e,"u_projection_fallback_matrix"),!1,u.fallbackMatrix),t.uniformMatrix4fv(t.getUniformLocation(e,"u_projection_matrix"),!1,u.mainMatrix),t.uniform4f(t.getUniformLocation(e,"u_projection_tile_mercator_coords"),...u.tileMercatorCoords),t.uniform4f(t.getUniformLocation(e,"u_projection_clipping_plane"),...u.clippingPlane),t.uniform1f(t.getUniformLocation(e,"u_projection_transition"),u.projectionTransition)}else t.uniformMatrix4fv(t.getUniformLocation(e,"u_matrix"),!1,r);this.#m(t),t.bindBuffer(t.ARRAY_BUFFER,this.#i),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.#r);const c=t.getAttribLocation(e,"a_position");t.enableVertexAttribArray(c),t.vertexAttribPointer(c,2,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLES,this.#c,t.UNSIGNED_SHORT,0)}}export default NightLayer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maplibre-gl-nightlayer",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.7",
4
4
  "description": "A Night Layer for MapLibre GL JS",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",