maplibre-gl-nightlayer 1.0.0-alpha.7 → 1.0.0-alpha.8
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/README.md +41 -27
- package/dist/main.d.ts +14 -5
- package/dist/main.js +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,7 +16,15 @@ import { NightLayer } from 'maplibre-gl-nightlayer';
|
|
|
16
16
|
:
|
|
17
17
|
|
|
18
18
|
map.on('load', () => {
|
|
19
|
-
map.addLayer(new NightLayer(
|
|
19
|
+
map.addLayer(new NightLayer({
|
|
20
|
+
// These are the default values
|
|
21
|
+
date: null,
|
|
22
|
+
opacity: 0.5,
|
|
23
|
+
color: [0, 0, 0],
|
|
24
|
+
twilightSteps: 0,
|
|
25
|
+
twilightStepAngle: 6,
|
|
26
|
+
twilightAttenuation: 0.5,
|
|
27
|
+
}));
|
|
20
28
|
});
|
|
21
29
|
```
|
|
22
30
|
|
|
@@ -25,40 +33,46 @@ map.on('load', () => {
|
|
|
25
33
|
type Color = [number, number, number];
|
|
26
34
|
|
|
27
35
|
type Options = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
date?: Date | null;
|
|
37
|
+
opacity?: number;
|
|
38
|
+
color?: Color;
|
|
39
|
+
twilightSteps?: number;
|
|
40
|
+
twilightStepAngle?: number;
|
|
41
|
+
twilightAttenuation?: number;
|
|
34
42
|
};
|
|
35
43
|
|
|
36
|
-
class NightLayer implements CustomLayerInterface {
|
|
37
|
-
|
|
44
|
+
export class NightLayer implements CustomLayerInterface {
|
|
45
|
+
constructor(opts?: Options);
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
getSubsolarPoint(): {
|
|
48
|
+
lng: number;
|
|
49
|
+
lat: number;
|
|
50
|
+
};
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
getDate(): Date | null;
|
|
53
|
+
setDate(date: Date | null): void;
|
|
46
54
|
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
getOpacity(): number;
|
|
56
|
+
setOpacity(opacity: number): void;
|
|
49
57
|
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
getColor(): Color;
|
|
59
|
+
setColor(color: Color): void;
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
getTwilightSteps(): number;
|
|
62
|
+
setTwilightSteps(steps: number): void;
|
|
55
63
|
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
getTwilightStepAngle(): number;
|
|
65
|
+
setTwilightStepAngle(angle: number): void;
|
|
58
66
|
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
getTwilightAttenuation(): number;
|
|
68
|
+
setTwilightAttenuation(attenuation: number): void;
|
|
69
|
+
|
|
70
|
+
:
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export function getSubsolarPoint(date?: Date): {
|
|
74
|
+
lng: number;
|
|
75
|
+
lat: number;
|
|
76
|
+
};
|
|
61
77
|
|
|
62
|
-
:
|
|
63
|
-
}
|
|
64
78
|
```
|
package/dist/main.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { CustomLayerInterface, CustomRenderMethodInput, Map as MaplibreMap } from 'maplibre-gl';
|
|
2
2
|
import type { mat4 } from 'gl-matrix';
|
|
3
|
+
/**
|
|
4
|
+
* Get the subsolar point (longitude and latitude) at the given date.
|
|
5
|
+
* @param date If null, the current date is used.
|
|
6
|
+
* @returns The subsolar point.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getSubsolarPoint(date?: Date): {
|
|
9
|
+
lng: number;
|
|
10
|
+
lat: number;
|
|
11
|
+
};
|
|
3
12
|
type Color = [number, number, number];
|
|
4
13
|
/**
|
|
5
14
|
* Options for the NightLayer.
|
|
@@ -49,12 +58,12 @@ export declare class NightLayer implements CustomLayerInterface {
|
|
|
49
58
|
*/
|
|
50
59
|
constructor(opts?: Options);
|
|
51
60
|
/**
|
|
52
|
-
* Get the subsolar point (longitude and latitude)
|
|
53
|
-
* @
|
|
61
|
+
* Get the current subsolar point (longitude and latitude)
|
|
62
|
+
* @returns The subsolar point.
|
|
54
63
|
*/
|
|
55
|
-
getSubsolarPoint(
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
getSubsolarPoint(): {
|
|
65
|
+
lng: number;
|
|
66
|
+
lat: number;
|
|
58
67
|
};
|
|
59
68
|
/**
|
|
60
69
|
* Get the date for the shadow.
|
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";import{MercatorCoordinate as f,createTileMesh as
|
|
1
|
+
"use strict";import{MercatorCoordinate as f,createTileMesh as m}from"maplibre-gl";function p(o){return o*Math.PI/180}function d(o){return o/Math.PI*180}export function getSubsolarPoint(o){o=o||new Date;const t=(o.getTime()-Date.UTC(o.getUTCFullYear(),0,0))/864e5,r=2*Math.PI/365.24,u=p(23.44),s=.0167,n=(t+9)*r,e=n+2*s*Math.sin((t-3)*r),i=(n-Math.atan2(Math.sin(e),Math.cos(e)*Math.cos(u)))/Math.PI,a=720*(i-Math.trunc(i+.5)),h=-15*(o.getUTCHours()+o.getUTCMinutes()/60+o.getUTCSeconds()/3600-12+a/60),l=d(Math.asin(Math.sin(-u)*Math.cos(e)));return{lng:h,lat:l}}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(){return getSubsolarPoint(this.#n||new Date)}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 s=`#version 300 es
|
|
2
2
|
precision highp float;
|
|
3
3
|
|
|
4
4
|
in vec2 a_position;
|
|
@@ -19,7 +19,7 @@ ${!r.vertexShaderPrelude?`
|
|
|
19
19
|
gl_Position = projectTile(a_position);
|
|
20
20
|
v_position = a_position;
|
|
21
21
|
}
|
|
22
|
-
`,
|
|
22
|
+
`,n=`#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,
|
|
68
|
+
}`,e=t.createShader(t.VERTEX_SHADER);if(!e)throw new Error("failed to create vertex shader");t.shaderSource(e,s),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}#m(t){if(!this.#t||!this.#i||!this.#r)return;const[r,u]=this.#t.getBounds().toArray(),s=Math.floor(f.fromLngLat(r).x),n=Math.ceil(f.fromLngLat(u).x),e=this.#t.style?.projection?.name==="globe"?"globe":[s,n].join(":");if(e===this.#f)return;let i;e==="globe"?(i=m({granularity:100,generateBorders:!1,extendToNorthPole:!0,extendToSouthPole:!0},"16bit"),i.vertices=new Float32Array(new Int16Array(i.vertices)).map(a=>a/8192).buffer):i={vertices:new Float32Array([s,0,n,0,s,1,s,1,n,0,n,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,u){if(u||(u=r),!this.#e||!this.#i||!this.#r||!this.#t)return;const s=u.shaderData||{},n=s.variantName||"default";this.#e.has(n)||this.#e.set(n,this.#l(t,s));const e=this.#e.get(n);if(!e)return;const{lng:i,lat:a}=this.getSubsolarPoint();if(t.useProgram(e),t.uniform2fv(t.getUniformLocation(e,"u_subsolar"),[i,a]),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 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.#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.
|
|
3
|
+
"version": "1.0.0-alpha.8",
|
|
4
4
|
"description": "A Night Layer for MapLibre GL JS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@biomejs/biome": "^1.9.4",
|
|
35
35
|
"esbuild": "^0.24.0",
|
|
36
36
|
"gl-matrix": "^3.4.3",
|
|
37
|
-
"maplibre-gl": "5.0.0-pre.
|
|
37
|
+
"maplibre-gl": "5.0.0-pre.10",
|
|
38
38
|
"typescript": "^5.7.2",
|
|
39
39
|
"vite": "^6.0.3"
|
|
40
40
|
}
|