maplibre-gl-nightlayer 1.0.0-alpha.9 → 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 +42 -10
- package/THIRD-PARTY-NOTICES +30 -0
- package/dist/main.d.ts +55 -132
- package/dist/main.js +363 -68
- package/dist/nightlayer.min.js +367 -0
- package/package.json +32 -28
package/README.md
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
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
|

|
|
5
9
|
|
|
6
|
-
##
|
|
10
|
+
## Demo
|
|
11
|
+
[example](https://kikuchan.github.io/maplibre-gl-nightlayer/)
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
### Module
|
|
7
15
|
```sh
|
|
8
16
|
$ npm install --save-dev maplibre-gl-nightlayer
|
|
9
17
|
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
18
|
```js
|
|
14
19
|
import { NightLayer } from 'maplibre-gl-nightlayer';
|
|
15
20
|
|
|
@@ -17,13 +22,29 @@ import { NightLayer } from 'maplibre-gl-nightlayer';
|
|
|
17
22
|
|
|
18
23
|
map.on('load', () => {
|
|
19
24
|
map.addLayer(new NightLayer({
|
|
20
|
-
// These are the default values
|
|
21
25
|
date: null,
|
|
22
26
|
opacity: 0.5,
|
|
23
|
-
color: [0, 0, 0,
|
|
24
|
-
daytimeColor: [0, 0, 0, 0],
|
|
27
|
+
color: [0, 0, 0, 0],
|
|
28
|
+
daytimeColor: [0, 0, 0, 0],
|
|
25
29
|
twilightSteps: 0,
|
|
26
|
-
twilightAttenuation:
|
|
30
|
+
twilightAttenuation: 1,
|
|
31
|
+
updateInterval: 10000,
|
|
32
|
+
atmosphere: 0,
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### via CDN
|
|
38
|
+
|
|
39
|
+
Load MapLibre GL JS first so that `maplibregl` is available globally.
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<script src="https://unpkg.com/maplibre-gl-nightlayer@latest/dist/nightlayer.min.js"></script>
|
|
43
|
+
```
|
|
44
|
+
```js
|
|
45
|
+
map.on('load', () => {
|
|
46
|
+
map.addLayer(new nightLayer.NightLayer({
|
|
47
|
+
:
|
|
27
48
|
}));
|
|
28
49
|
});
|
|
29
50
|
```
|
|
@@ -41,6 +62,9 @@ type Options = {
|
|
|
41
62
|
daytimeColor?: Color;
|
|
42
63
|
twilightSteps?: number;
|
|
43
64
|
twilightAttenuation?: number;
|
|
65
|
+
updateInterval?: number;
|
|
66
|
+
atmosphere?: number;
|
|
67
|
+
lut?: string | URL;
|
|
44
68
|
};
|
|
45
69
|
|
|
46
70
|
export class NightLayer implements CustomLayerInterface {
|
|
@@ -61,7 +85,7 @@ export class NightLayer implements CustomLayerInterface {
|
|
|
61
85
|
setColor(color: Color): void;
|
|
62
86
|
|
|
63
87
|
getDaytimeColor(): Color4;
|
|
64
|
-
setDaytimeColor(color: Color);
|
|
88
|
+
setDaytimeColor(color: Color): void;
|
|
65
89
|
|
|
66
90
|
getTwilightSteps(): number;
|
|
67
91
|
setTwilightSteps(steps: number): void;
|
|
@@ -69,12 +93,20 @@ export class NightLayer implements CustomLayerInterface {
|
|
|
69
93
|
getTwilightAttenuation(): number;
|
|
70
94
|
setTwilightAttenuation(attenuation: number): void;
|
|
71
95
|
|
|
96
|
+
getUpdateInterval(): number;
|
|
97
|
+
setUpdateInterval(interval: number): void;
|
|
98
|
+
|
|
99
|
+
getAtmosphere(): number;
|
|
100
|
+
setAtmosphere(atmosphere: number): void;
|
|
101
|
+
|
|
72
102
|
:
|
|
73
103
|
};
|
|
74
104
|
|
|
75
|
-
export function getSubsolarPoint(date?: Date): {
|
|
105
|
+
export function getSubsolarPoint(date?: Date | null): {
|
|
76
106
|
lng: number;
|
|
77
107
|
lat: number;
|
|
78
108
|
};
|
|
79
109
|
|
|
80
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,139 +1,62 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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
|
-
};
|
|
1
|
+
import { CustomLayerInterface, CustomRenderMethodInput, Map } from "maplibre-gl";
|
|
2
|
+
//#region src/main.d.ts
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
daytimeColor?: Color;
|
|
42
|
-
/**
|
|
43
|
-
* Number of twilight steps.
|
|
44
|
-
* 0 means no steps (gradation), 1 means one step (day/night), etc.
|
|
45
|
-
*/
|
|
46
|
-
twilightSteps?: number;
|
|
47
|
-
/**
|
|
48
|
-
* Attenuation factor for each twilight step.
|
|
49
|
-
* 0.0 means no attenuation, 1.0 means full attenuation
|
|
50
|
-
*/
|
|
51
|
-
twilightAttenuation?: number;
|
|
7
|
+
date?: Date | null;
|
|
8
|
+
/** Whole-layer opacity, including atmospheric effects. Default: 0.5. */
|
|
9
|
+
opacity?: number;
|
|
10
|
+
/** Night illumination override; alpha controls replacement strength. Default: transparent. */
|
|
11
|
+
color?: Color;
|
|
12
|
+
/** Day illumination override; alpha controls replacement strength. Default: transparent. */
|
|
13
|
+
daytimeColor?: Color;
|
|
14
|
+
twilightSteps?: number;
|
|
15
|
+
/** Gamma of intermediate twilight opacity. Default: 1. Ignored for continuous illumination. */
|
|
16
|
+
twilightAttenuation?: number;
|
|
17
|
+
updateInterval?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Blend from vacuum to atmospheric lighting and transport, from 0 to 1. The Sun remains visible. Default: 0.
|
|
20
|
+
*/
|
|
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;
|
|
52
29
|
};
|
|
53
|
-
/**
|
|
54
|
-
* A custom Maplibre GL JS layer that renders the night side of the Earth.
|
|
55
|
-
*/
|
|
56
30
|
export declare class NightLayer implements CustomLayerInterface {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
* @returns The opacity. 0.0 means fully transparent, 1.0 means fully opaque.
|
|
87
|
-
*/
|
|
88
|
-
getOpacity(): number;
|
|
89
|
-
/**
|
|
90
|
-
* Set the opacity of the shadow.
|
|
91
|
-
* @param opacity 0.0 means fully transparent, 1.0 means fully opaque.
|
|
92
|
-
*/
|
|
93
|
-
setOpacity(opacity: number): void;
|
|
94
|
-
/**
|
|
95
|
-
* Get the color of the shadow.
|
|
96
|
-
* @returns The color. Each value is in the range [0, 255].
|
|
97
|
-
*/
|
|
98
|
-
getColor(): Color4;
|
|
99
|
-
/**
|
|
100
|
-
* Set the color of the shadow.
|
|
101
|
-
* @param color Each value should be in the range [0, 255].
|
|
102
|
-
*/
|
|
103
|
-
setColor(color: Color): void;
|
|
104
|
-
/**
|
|
105
|
-
* Get the color of the daytime.
|
|
106
|
-
* @returns The color [r, g, b, a]. Each value is in the range [0, 255].
|
|
107
|
-
*/
|
|
108
|
-
getDaytimeColor(): Color4;
|
|
109
|
-
/**
|
|
110
|
-
* Set the color of the daytime.
|
|
111
|
-
* @param color Each value should be in the range [0, 255].
|
|
112
|
-
*/
|
|
113
|
-
setDaytimeColor(color: Color): void;
|
|
114
|
-
/**
|
|
115
|
-
* Get the number of twilight steps.
|
|
116
|
-
* @returns The steps. 0 means no steps (gradation), 1 means one step (day/night), etc.
|
|
117
|
-
*/
|
|
118
|
-
getTwilightSteps(): number;
|
|
119
|
-
/**
|
|
120
|
-
* Set the number of twilight steps.
|
|
121
|
-
* @param steps 0 means no steps (gradation), 1 means one step (day/night), etc.
|
|
122
|
-
*/
|
|
123
|
-
setTwilightSteps(steps: number): void;
|
|
124
|
-
/**
|
|
125
|
-
* Get the attenuation factor for each twilight step.
|
|
126
|
-
* @returns The attenuation. 0.0 means no attenuation, 1.0 means full attenuation.
|
|
127
|
-
*/
|
|
128
|
-
getTwilightAttenuation(): number;
|
|
129
|
-
/**
|
|
130
|
-
* Set the attenuation factor for each twilight step.
|
|
131
|
-
* @param attenuation 0.0 means no attenuation, 1.0 means full attenuation.
|
|
132
|
-
*/
|
|
133
|
-
setTwilightAttenuation(attenuation: number): void;
|
|
134
|
-
onAdd(map: MaplibreMap, gl: WebGLRenderingContext | WebGL2RenderingContext): void;
|
|
135
|
-
onRemove(): void;
|
|
136
|
-
render(gl: WebGLRenderingContext | WebGL2RenderingContext, matrix: mat4, options: CustomRenderMethodInput): void;
|
|
137
|
-
render(gl: WebGLRenderingContext | WebGL2RenderingContext, options: CustomRenderMethodInput): void;
|
|
31
|
+
#private;
|
|
32
|
+
id: string;
|
|
33
|
+
type: "custom";
|
|
34
|
+
renderingMode: "2d";
|
|
35
|
+
constructor(opts?: Options);
|
|
36
|
+
getSubsolarPoint(): {
|
|
37
|
+
lng: number;
|
|
38
|
+
lat: number;
|
|
39
|
+
};
|
|
40
|
+
getDate(): Date | null;
|
|
41
|
+
setDate(date: Date | null): void;
|
|
42
|
+
getOpacity(): number;
|
|
43
|
+
setOpacity(opacity: number): void;
|
|
44
|
+
getColor(): Color4;
|
|
45
|
+
setColor(color: Color): void;
|
|
46
|
+
getDaytimeColor(): Color4;
|
|
47
|
+
setDaytimeColor(color: Color): void;
|
|
48
|
+
getTwilightSteps(): number;
|
|
49
|
+
setTwilightSteps(steps: number): void;
|
|
50
|
+
getTwilightAttenuation(): number;
|
|
51
|
+
setTwilightAttenuation(gamma: number): void;
|
|
52
|
+
getUpdateInterval(): number;
|
|
53
|
+
setUpdateInterval(interval: number): 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;
|
|
138
60
|
}
|
|
139
|
-
|
|
61
|
+
//#endregion
|
|
62
|
+
export { NightLayer as default };
|