maplibre-gl-nightlayer 1.0.0 → 2.0.0-beta.0

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 CHANGED
@@ -1,6 +1,10 @@
1
1
  # A Night Layer for MapLibre GL JS
2
2
 
3
3
  Adds a simple night shadow (Earth's shadow) on the map.
4
+
5
+ > [!WARNING]
6
+ > This package relies on MapLibre GL JS internals. Compatibility may break even in minor or patch releases.
7
+
4
8
  ![image](https://github.com/user-attachments/assets/425f58e0-66f6-4779-8c03-ff543972c59e)
5
9
 
6
10
  ## Demo
@@ -18,14 +22,14 @@ import { NightLayer } from 'maplibre-gl-nightlayer';
18
22
 
19
23
  map.on('load', () => {
20
24
  map.addLayer(new NightLayer({
21
- // These are the default values
22
25
  date: null,
23
26
  opacity: 0.5,
24
- color: [0, 0, 0, 255],
27
+ color: [0, 0, 0, 0],
25
28
  daytimeColor: [0, 0, 0, 0],
26
29
  twilightSteps: 0,
27
- twilightAttenuation: 0.5,
30
+ twilightAttenuation: 1,
28
31
  updateInterval: 10000,
32
+ atmosphere: 0,
29
33
  }));
30
34
  });
31
35
  ```
@@ -59,6 +63,8 @@ type Options = {
59
63
  twilightSteps?: number;
60
64
  twilightAttenuation?: number;
61
65
  updateInterval?: number;
66
+ atmosphere?: number;
67
+ lut?: string | URL;
62
68
  };
63
69
 
64
70
  export class NightLayer implements CustomLayerInterface {
@@ -90,6 +96,9 @@ export class NightLayer implements CustomLayerInterface {
90
96
  getUpdateInterval(): number;
91
97
  setUpdateInterval(interval: number): void;
92
98
 
99
+ getAtmosphere(): number;
100
+ setAtmosphere(atmosphere: number): void;
101
+
93
102
  :
94
103
  };
95
104
 
@@ -99,3 +108,5 @@ export function getSubsolarPoint(date?: Date | null): {
99
108
  };
100
109
 
101
110
  ```
111
+
112
+ The default LUT is embedded. Use `lut` to load a custom LUT ZIP by URL. Requires `OES_texture_float_linear`.
@@ -0,0 +1,30 @@
1
+ The atmospheric lighting LUT is generated using Eric Bruneton's
2
+ Precomputed Atmospheric Scattering implementation:
3
+ https://github.com/ebruneton/precomputed_atmospheric_scattering
4
+ Revision: 34f14e745cff948f4ca3157d1b62a445ffa7286f
5
+
6
+ Copyright (c) 2017 Eric Bruneton
7
+ All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are met:
11
+ 1. Redistributions of source code must retain the above copyright notice,
12
+ this list of conditions and the following disclaimer.
13
+ 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ this list of conditions and the following disclaimer in the documentation
15
+ and/or other materials provided with the distribution.
16
+ 3. Neither the name of the copyright holders nor the names of its contributors
17
+ may be used to endorse or promote products derived from this software
18
+ without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ POSSIBILITY OF SUCH DAMAGE.
package/dist/main.d.ts CHANGED
@@ -1,157 +1,62 @@
1
1
  import { CustomLayerInterface, CustomRenderMethodInput, Map } from "maplibre-gl";
2
2
  //#region src/main.d.ts
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 | null): {
9
- lng: number;
10
- lat: number;
11
- };
12
3
  type Color3 = [number, number, number];
13
4
  type Color4 = [number, number, number, number];
14
5
  type Color = Color3 | Color4;
15
- /**
16
- * Options for the NightLayer.
17
- */
18
6
  type Options = {
19
- /**
20
- * Date for the shadow.
21
- * If null, the current date is used.
22
- */
23
7
  date?: Date | null;
24
- /**
25
- * Opacity of the layer.
26
- * 0.0 means fully transparent, 1.0 means fully opaque
27
- * default: 0.5
28
- */
8
+ /** Whole-layer opacity, including atmospheric effects. Default: 0.5. */
29
9
  opacity?: number;
30
- /**
31
- * Color of the shadow: [r, g, b, a]
32
- * Each value should be in the range [0, 255].
33
- * default: [0, 0, 0, 255]
34
- */
10
+ /** Night illumination override; alpha controls replacement strength. Default: transparent. */
35
11
  color?: Color;
36
- /**
37
- * Color of the daytime: [r, g, b, a]
38
- * Each value should be in the range [0, 255].
39
- * default: [0, 0, 0, 0]
40
- */
12
+ /** Day illumination override; alpha controls replacement strength. Default: transparent. */
41
13
  daytimeColor?: Color;
42
- /**
43
- * Number of twilight steps.
44
- * 0 means no steps (gradation), 1 means one step (day/night), etc.
45
- * default: 0
46
- */
47
14
  twilightSteps?: number;
48
- /**
49
- * Attenuation factor for each twilight step.
50
- * 0.0 means no attenuation, 1.0 means full attenuation
51
- * default: 0.5
52
- */
15
+ /** Gamma of intermediate twilight opacity. Default: 1. Ignored for continuous illumination. */
53
16
  twilightAttenuation?: number;
17
+ updateInterval?: number;
54
18
  /**
55
- * Update interval in milliseconds.
56
- * Periodically triggers a repaint.
57
- * default: 10000
19
+ * Blend from vacuum to atmospheric lighting and transport, from 0 to 1. The Sun remains visible. Default: 0.
58
20
  */
59
- updateInterval?: number;
21
+ atmosphere?: number;
22
+ /** Custom LUT ZIP URL. Uses the embedded LUT when omitted. */
23
+ lut?: string | URL;
24
+ };
25
+ /** Subsolar longitude/latitude; omitted or null date means now. */
26
+ export declare function getSubsolarPoint(date?: Date | null): {
27
+ lng: number;
28
+ lat: number;
60
29
  };
61
- /**
62
- * A custom Maplibre GL JS layer that renders the night side of the Earth.
63
- */
64
30
  export declare class NightLayer implements CustomLayerInterface {
65
31
  #private;
66
32
  id: string;
67
33
  type: "custom";
68
34
  renderingMode: "2d";
69
- /**
70
- * Create a new NightLayer instance. Intended to be passed to `map.addLayer`.
71
- * @param opts The options.
72
- */
73
35
  constructor(opts?: Options);
74
- /**
75
- * Get the current subsolar point (longitude and latitude)
76
- * @returns The subsolar point.
77
- */
78
36
  getSubsolarPoint(): {
79
37
  lng: number;
80
38
  lat: number;
81
39
  };
82
- /**
83
- * Get the date for the shadow.
84
- * @returns The date. If null, the current date is used.
85
- */
86
40
  getDate(): Date | null;
87
- /**
88
- * Set the date for the shadow.
89
- * @param date If null, the current date is used.
90
- */
91
41
  setDate(date: Date | null): void;
92
- /**
93
- * Get the opacity of the shadow.
94
- * @returns The opacity. 0.0 means fully transparent, 1.0 means fully opaque.
95
- */
96
42
  getOpacity(): number;
97
- /**
98
- * Set the opacity of the shadow.
99
- * @param opacity 0.0 means fully transparent, 1.0 means fully opaque.
100
- */
101
43
  setOpacity(opacity: number): void;
102
- /**
103
- * Get the color of the shadow.
104
- * @returns The color. Each value is in the range [0, 255].
105
- */
106
44
  getColor(): Color4;
107
- /**
108
- * Set the color of the shadow.
109
- * @param color Each value should be in the range [0, 255].
110
- */
111
45
  setColor(color: Color): void;
112
- /**
113
- * Get the color of the daytime.
114
- * @returns The color [r, g, b, a]. Each value is in the range [0, 255].
115
- */
116
46
  getDaytimeColor(): Color4;
117
- /**
118
- * Set the color of the daytime.
119
- * @param color Each value should be in the range [0, 255].
120
- */
121
47
  setDaytimeColor(color: Color): void;
122
- /**
123
- * Get the number of twilight steps.
124
- * @returns The steps. 0 means no steps (gradation), 1 means one step (day/night), etc.
125
- */
126
48
  getTwilightSteps(): number;
127
- /**
128
- * Set the number of twilight steps.
129
- * @param steps 0 means no steps (gradation), 1 means one step (day/night), etc.
130
- */
131
49
  setTwilightSteps(steps: number): void;
132
- /**
133
- * Get the attenuation factor for each twilight step.
134
- * @returns The attenuation. 0.0 means no attenuation, 1.0 means full attenuation.
135
- */
136
50
  getTwilightAttenuation(): number;
137
- /**
138
- * Set the attenuation factor for each twilight step.
139
- * @param attenuation 0.0 means no attenuation, 1.0 means full attenuation.
140
- */
141
- setTwilightAttenuation(attenuation: number): void;
142
- /**
143
- * Get the update interval.
144
- * @returns The interval in milliseconds.
145
- */
51
+ setTwilightAttenuation(gamma: number): void;
146
52
  getUpdateInterval(): number;
147
- /**
148
- * Set the update interval.
149
- * @param interval The interval in milliseconds..
150
- */
151
53
  setUpdateInterval(interval: number): void;
152
- onAdd(map: Map, _gl: WebGLRenderingContext | WebGL2RenderingContext): void;
153
- onRemove(_map: Map, gl: WebGLRenderingContext | WebGL2RenderingContext): void;
154
- render(gl: WebGLRenderingContext | WebGL2RenderingContext, options: CustomRenderMethodInput): void;
54
+ getAtmosphere(): number;
55
+ setAtmosphere(atmosphere: number): void;
56
+ onAdd(map: Map, context: WebGLRenderingContext | WebGL2RenderingContext): void;
57
+ onRemove(map: Map, context: WebGLRenderingContext | WebGL2RenderingContext): void;
58
+ prerender(gl: WebGL2RenderingContext, options: CustomRenderMethodInput): void;
59
+ render(context: WebGLRenderingContext | WebGL2RenderingContext, options: CustomRenderMethodInput): void;
155
60
  }
156
61
  //#endregion
157
62
  export { NightLayer as default };