maplibre-gl-nightlayer 2.0.0-beta.0 → 2.0.0-beta.1
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 +54 -37
- package/THIRD-PARTY-NOTICES +84 -0
- package/dist/atmosphere-lut.zip +0 -0
- package/dist/main.d.ts +65 -24
- package/dist/main.js +1695 -314
- package/package.json +7 -8
- package/dist/nightlayer.min.js +0 -367
package/README.md
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
# A Night Layer for MapLibre GL JS
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Night falls on your map: twilight, starlight and moonlight.
|
|
4
4
|
|
|
5
5
|
> [!WARNING]
|
|
6
6
|
> This package relies on MapLibre GL JS internals. Compatibility may break even in minor or patch releases.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
<img width="1680" height="1280" alt="image" src="https://github.com/user-attachments/assets/ed8f5264-f997-4b3c-990c-35a2454a4e91" />
|
|
9
9
|
|
|
10
10
|
## Demo
|
|
11
|
+
|
|
11
12
|
[example](https://kikuchan.github.io/maplibre-gl-nightlayer/)
|
|
12
13
|
|
|
13
14
|
## Usage
|
|
15
|
+
|
|
14
16
|
### Module
|
|
17
|
+
|
|
15
18
|
```sh
|
|
16
19
|
$ npm install --save-dev maplibre-gl-nightlayer
|
|
17
20
|
```
|
|
21
|
+
|
|
18
22
|
```js
|
|
19
23
|
import { NightLayer } from 'maplibre-gl-nightlayer';
|
|
20
24
|
|
|
@@ -24,47 +28,65 @@ map.on('load', () => {
|
|
|
24
28
|
map.addLayer(new NightLayer({
|
|
25
29
|
date: null,
|
|
26
30
|
opacity: 0.5,
|
|
27
|
-
|
|
28
|
-
daytimeColor: [0, 0, 0, 0],
|
|
29
|
-
twilightSteps: 0,
|
|
30
|
-
twilightAttenuation: 1,
|
|
31
|
+
twilight: null,
|
|
31
32
|
updateInterval: 10000,
|
|
32
|
-
atmosphere:
|
|
33
|
+
atmosphere: false,
|
|
34
|
+
development: false,
|
|
33
35
|
}));
|
|
34
36
|
});
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
### via CDN
|
|
38
40
|
|
|
39
|
-
Load MapLibre GL JS first so that `maplibregl` is available globally.
|
|
40
|
-
|
|
41
41
|
```html
|
|
42
|
-
<script
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
map.on('load', () => {
|
|
46
|
-
map.addLayer(new nightLayer.NightLayer({
|
|
42
|
+
<script type="module">
|
|
43
|
+
import { NightLayer } from 'https://unpkg.com/maplibre-gl-nightlayer';
|
|
44
|
+
|
|
47
45
|
:
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
|
|
47
|
+
map.on('load', () => {
|
|
48
|
+
map.addLayer(new NightLayer());
|
|
49
|
+
});
|
|
50
|
+
</script>
|
|
50
51
|
```
|
|
51
52
|
|
|
52
53
|
## API
|
|
54
|
+
|
|
53
55
|
```ts
|
|
54
56
|
type Color3 = [number, number, number];
|
|
55
57
|
type Color4 = [number, number, number, number];
|
|
56
58
|
type Color = Color3 | Color4;
|
|
59
|
+
type TwilightSteps = 1 | 2 | 3 | 4;
|
|
60
|
+
type Twilight = { steps: TwilightSteps; color: Color4; attenuation: number };
|
|
61
|
+
type TwilightInput = TwilightSteps | {
|
|
62
|
+
steps: TwilightSteps;
|
|
63
|
+
color?: Color; // RGB/alpha 0..1; default [0,0,0,0.95]; RGB-only alpha defaults to 0.95
|
|
64
|
+
attenuation?: number; // positive, default 0.5
|
|
65
|
+
} | null;
|
|
66
|
+
type DevelopmentProcess = 'linear' | 'aces' | 'agx' | 'filmic';
|
|
67
|
+
type Development = {
|
|
68
|
+
process: DevelopmentProcess;
|
|
69
|
+
exposure: number; // -12..32 EV
|
|
70
|
+
autoExposure: boolean;
|
|
71
|
+
compensation: number; // -12..12 EV, AE only
|
|
72
|
+
gamma: number; // 0.1..4, post-development
|
|
73
|
+
};
|
|
74
|
+
type DevelopmentInput = false | DevelopmentProcess | Partial<Development>;
|
|
75
|
+
type Atmosphere = { sky: number; fog: number; stars: boolean };
|
|
76
|
+
type AtmosphereInput = boolean | number | {
|
|
77
|
+
sky?: boolean | number;
|
|
78
|
+
fog?: boolean | number;
|
|
79
|
+
stars?: boolean;
|
|
80
|
+
};
|
|
57
81
|
|
|
58
82
|
type Options = {
|
|
59
83
|
date?: Date | null;
|
|
60
84
|
opacity?: number;
|
|
61
|
-
|
|
62
|
-
daytimeColor?: Color;
|
|
63
|
-
twilightSteps?: number;
|
|
64
|
-
twilightAttenuation?: number;
|
|
85
|
+
twilight?: TwilightInput; // map-only stepped lighting; null/omission keeps continuous lighting
|
|
65
86
|
updateInterval?: number;
|
|
66
|
-
atmosphere?:
|
|
67
|
-
|
|
87
|
+
atmosphere?: AtmosphereInput; // default false
|
|
88
|
+
development?: DevelopmentInput; // default false
|
|
89
|
+
lut?: string;
|
|
68
90
|
};
|
|
69
91
|
|
|
70
92
|
export class NightLayer implements CustomLayerInterface {
|
|
@@ -81,23 +103,20 @@ export class NightLayer implements CustomLayerInterface {
|
|
|
81
103
|
getOpacity(): number;
|
|
82
104
|
setOpacity(opacity: number): void;
|
|
83
105
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
getDaytimeColor(): Color4;
|
|
88
|
-
setDaytimeColor(color: Color): void;
|
|
89
|
-
|
|
90
|
-
getTwilightSteps(): number;
|
|
91
|
-
setTwilightSteps(steps: number): void;
|
|
92
|
-
|
|
93
|
-
getTwilightAttenuation(): number;
|
|
94
|
-
setTwilightAttenuation(attenuation: number): void;
|
|
106
|
+
getTwilight(): Twilight | null;
|
|
107
|
+
setTwilight(twilight?: TwilightInput): void;
|
|
95
108
|
|
|
96
109
|
getUpdateInterval(): number;
|
|
97
110
|
setUpdateInterval(interval: number): void;
|
|
98
111
|
|
|
99
|
-
getAtmosphere():
|
|
100
|
-
setAtmosphere(atmosphere:
|
|
112
|
+
getAtmosphere(): Atmosphere;
|
|
113
|
+
setAtmosphere(atmosphere: AtmosphereInput): void;
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
getDevelopment(): Development | false;
|
|
117
|
+
setDevelopment(development: DevelopmentInput): void;
|
|
118
|
+
setLUT(source?: string): Promise<void>;
|
|
119
|
+
captureEXR(options?: { exposure?: 'preview' | 'raw' }): Promise<Blob>;
|
|
101
120
|
|
|
102
121
|
:
|
|
103
122
|
};
|
|
@@ -108,5 +127,3 @@ export function getSubsolarPoint(date?: Date | null): {
|
|
|
108
127
|
};
|
|
109
128
|
|
|
110
129
|
```
|
|
111
|
-
|
|
112
|
-
The default LUT is embedded. Use `lut` to load a custom LUT ZIP by URL. Requires `OES_texture_float_linear`.
|
package/THIRD-PARTY-NOTICES
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
The analytic AgX base-look and fitted ACES preview transforms are adapted from three.js:
|
|
2
|
+
https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js
|
|
3
|
+
Its implementation follows Filament's Blender-derived Rec.2020 AgX transform
|
|
4
|
+
and the minimal AgX default-contrast polynomial approximation.
|
|
5
|
+
Adaptations: shared preview exposure/sRGB encoding, explicit zero-input guard,
|
|
6
|
+
no optional look, and no three.js dependency. This is an analytic approximation,
|
|
7
|
+
not Blender's complete OpenColorIO configuration.
|
|
8
|
+
The ACES transform uses Stephen Hill's fitted RRT/ODT and input/output matrices,
|
|
9
|
+
including three.js's 1/0.6 viewing-environment scale. Its rational fit is evaluated
|
|
10
|
+
in a scaled form to avoid HDR overflow. It is not the full ACES reference pipeline.
|
|
11
|
+
Original fitted transform: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
|
|
12
|
+
|
|
13
|
+
The MIT License
|
|
14
|
+
|
|
15
|
+
Copyright © 2010-2026 three.js authors
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
in the Software without restriction, including without limitation the rights
|
|
20
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
furnished to do so, subject to the following conditions:
|
|
23
|
+
|
|
24
|
+
The above copyright notice and this permission notice shall be included in
|
|
25
|
+
all copies or substantial portions of the Software.
|
|
26
|
+
|
|
27
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
33
|
+
THE SOFTWARE.
|
|
34
|
+
|
|
35
|
+
The analytic Filmic preview is an independently implemented approximation to
|
|
36
|
+
Troy Sobotka's Filmic Blender OpenColorIO configuration and Base Contrast look:
|
|
37
|
+
https://github.com/sobotka/filmic-blender
|
|
38
|
+
Reference revision: 84bf836a4d9e130045c962c47ac4206395d4393b
|
|
39
|
+
The reference config, desat65cube.spi3d and Filmic_to_0-70_1-03.spi1d were used
|
|
40
|
+
for numerical comparisons. They are not included in the package. The intensity
|
|
41
|
+
compression is evaluated analytically, and an eighth-degree polynomial fitted
|
|
42
|
+
to Base Contrast replaces the 1D look. This is not the complete OCIO pipeline.
|
|
43
|
+
The default final log range is -12.473931188 to 4.026068812 (16.5 stops).
|
|
44
|
+
It uses the shared sRGB output encoder, not a second display encoding.
|
|
45
|
+
|
|
1
46
|
The atmospheric lighting LUT is generated using Eric Bruneton's
|
|
2
47
|
Precomputed Atmospheric Scattering implementation:
|
|
3
48
|
https://github.com/ebruneton/precomputed_atmospheric_scattering
|
|
@@ -28,3 +73,42 @@ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
28
73
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
29
74
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
30
75
|
POSSIBILITY OF SUCH DAMAGE.
|
|
76
|
+
|
|
77
|
+
The embedded diffuse Milky Way is adapted from Deep Star Maps 2020:
|
|
78
|
+
https://svs.gsfc.nasa.gov/4851/
|
|
79
|
+
Sources: milkyway_2020_4k.exr (texture), starmap_2020_4k.exr (photometric
|
|
80
|
+
reference), both in celestial ICRF/J2000 coordinates.
|
|
81
|
+
Credit: NASA/Goddard Space Flight Center Scientific Visualization Studio.
|
|
82
|
+
Gaia DR2: ESA/Gaia/DPAC.
|
|
83
|
+
Visualization by Ernie Wright (USRA).
|
|
84
|
+
|
|
85
|
+
Adaptations: linear-light reduction to 1024x512, sRGB encoding and lossy WebP
|
|
86
|
+
compression; empirical normalization from unsaturated catalogue stars.
|
|
87
|
+
No constellation figures or boundaries are included.
|
|
88
|
+
NASA media usage guidelines: https://www.nasa.gov/nasa-brand-center/images-and-media/
|
|
89
|
+
Gaia credit: https://gea.esac.esa.int/archive/documentation/GDR2/Miscellaneous/sec_credit_and_citation_instructions/
|
|
90
|
+
|
|
91
|
+
The embedded point-star dataset is derived from the HYG Stellar Database v4.1,
|
|
92
|
+
Copyright David Nash / Astronexus. It is licensed under Creative Commons
|
|
93
|
+
Attribution-ShareAlike 4.0 International (CC BY-SA 4.0):
|
|
94
|
+
https://creativecommons.org/licenses/by-sa/4.0/
|
|
95
|
+
Source: https://github.com/astronexus/HYG-Database
|
|
96
|
+
Revision: c7f7f883fe678cc7680169a50ccd7dcc49b060ce
|
|
97
|
+
Data: hyg/CURRENT/hygdata_v41.csv
|
|
98
|
+
|
|
99
|
+
Adaptations: select V <= 6.5; convert J2000 positions/proper motions and
|
|
100
|
+
V magnitudes/B-V colours to GPU point records, including blackbody-based
|
|
101
|
+
estimated angular diameters (not measured sizes); compress the
|
|
102
|
+
result as star-catalog.bin.gz. This adapted dataset retains CC BY-SA 4.0.
|
|
103
|
+
The library code is a separate work and retains the project's MIT license.
|
|
104
|
+
|
|
105
|
+
Photometric filter response: SVO Filter Profile Service, Generic/Johnson.V
|
|
106
|
+
https://svo2.cab.inta-csic.es/theory/fps/fps.php?ID=Generic/Johnson.V
|
|
107
|
+
|
|
108
|
+
Lunar orbital elements and main perturbation formulae: Paul Schlyter,
|
|
109
|
+
"How to compute planetary positions": https://stjarnhimlen.se/comp/ppcomp.html
|
|
110
|
+
Lunar visual phase-law reference: Krisciunas & Schaefer (1991),
|
|
111
|
+
"A Model of the Brightness of Moonlight", PASP 103, 1033.
|
|
112
|
+
Natural moonless-night horizontal illuminance reference (0.8 millilux):
|
|
113
|
+
U.S. National Park Service, "Metrics Guide to Night Skies Report":
|
|
114
|
+
https://www.nps.gov/subjects/nightskies/NSQmetrics.html
|
|
Binary file
|
package/dist/main.d.ts
CHANGED
|
@@ -1,26 +1,61 @@
|
|
|
1
1
|
import { CustomLayerInterface, CustomRenderMethodInput, Map } from "maplibre-gl";
|
|
2
|
-
|
|
2
|
+
type DepthSample = {
|
|
3
|
+
/** Straight-line range; infinity for sky. */
|
|
4
|
+
distanceMeters: number;
|
|
5
|
+
/** Optical-axis depth; infinity for sky or endpoints behind the camera. */
|
|
6
|
+
depthMeters: number;
|
|
7
|
+
groundCoverage: number;
|
|
8
|
+
};
|
|
3
9
|
type Color3 = [number, number, number];
|
|
4
10
|
type Color4 = [number, number, number, number];
|
|
5
11
|
type Color = Color3 | Color4;
|
|
12
|
+
type TwilightSteps = 1 | 2 | 3 | 4;
|
|
13
|
+
type Twilight = {
|
|
14
|
+
steps: TwilightSteps;
|
|
15
|
+
/** Linear RGB illumination multipliers and application strength, all 0..1. */
|
|
16
|
+
color: Color4;
|
|
17
|
+
attenuation: number;
|
|
18
|
+
};
|
|
19
|
+
type TwilightInput = TwilightSteps | {
|
|
20
|
+
steps: TwilightSteps;
|
|
21
|
+
color?: Color;
|
|
22
|
+
attenuation?: number;
|
|
23
|
+
} | null;
|
|
24
|
+
type Atmosphere = {
|
|
25
|
+
sky: number;
|
|
26
|
+
fog: number;
|
|
27
|
+
stars: boolean;
|
|
28
|
+
};
|
|
29
|
+
type AtmosphereInput = boolean | number | {
|
|
30
|
+
sky?: boolean | number;
|
|
31
|
+
fog?: boolean | number;
|
|
32
|
+
stars?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type DevelopmentProcess = "linear" | "aces" | "agx" | "filmic";
|
|
35
|
+
type Development = {
|
|
36
|
+
process: DevelopmentProcess;
|
|
37
|
+
exposure: number;
|
|
38
|
+
autoExposure: boolean;
|
|
39
|
+
compensation: number;
|
|
40
|
+
gamma: number;
|
|
41
|
+
};
|
|
42
|
+
type DevelopmentInput = false | DevelopmentProcess | Partial<Development>;
|
|
6
43
|
type Options = {
|
|
7
44
|
date?: Date | null;
|
|
8
45
|
/** Whole-layer opacity, including atmospheric effects. Default: 0.5. */
|
|
9
46
|
opacity?: number;
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
daytimeColor?: Color;
|
|
14
|
-
twilightSteps?: number;
|
|
15
|
-
/** Gamma of intermediate twilight opacity. Default: 1. Ignored for continuous illumination. */
|
|
16
|
-
twilightAttenuation?: number;
|
|
47
|
+
/** Map-only stepped surface lighting; null/omission keeps continuous lighting.
|
|
48
|
+
* Defaults: black with alpha 0.95, attenuation 0.5. Ignored by camera/physical export. */
|
|
49
|
+
twilight?: TwilightInput;
|
|
17
50
|
updateInterval?: number;
|
|
18
51
|
/**
|
|
19
|
-
*
|
|
52
|
+
* Sky scattering, finite-path fog, and celestial backgrounds/disks. Default: false.
|
|
20
53
|
*/
|
|
21
|
-
atmosphere?:
|
|
22
|
-
/**
|
|
23
|
-
|
|
54
|
+
atmosphere?: AtmosphereInput;
|
|
55
|
+
/** False: fixed linear map presentation. A process string abbreviates an object. */
|
|
56
|
+
development?: DevelopmentInput;
|
|
57
|
+
/** Atmosphere LUT archive URL. Defaults to atmosphere-lut.zip next to the module. */
|
|
58
|
+
lut?: string;
|
|
24
59
|
};
|
|
25
60
|
/** Subsolar longitude/latitude; omitted or null date means now. */
|
|
26
61
|
export declare function getSubsolarPoint(date?: Date | null): {
|
|
@@ -41,22 +76,28 @@ export declare class NightLayer implements CustomLayerInterface {
|
|
|
41
76
|
setDate(date: Date | null): void;
|
|
42
77
|
getOpacity(): number;
|
|
43
78
|
setOpacity(opacity: number): void;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
getDaytimeColor(): Color4;
|
|
47
|
-
setDaytimeColor(color: Color): void;
|
|
48
|
-
getTwilightSteps(): number;
|
|
49
|
-
setTwilightSteps(steps: number): void;
|
|
50
|
-
getTwilightAttenuation(): number;
|
|
51
|
-
setTwilightAttenuation(gamma: number): void;
|
|
79
|
+
getTwilight(): Twilight | null;
|
|
80
|
+
setTwilight(twilight?: TwilightInput): void;
|
|
52
81
|
getUpdateInterval(): number;
|
|
53
82
|
setUpdateInterval(interval: number): void;
|
|
54
|
-
getAtmosphere():
|
|
55
|
-
setAtmosphere(atmosphere:
|
|
83
|
+
getAtmosphere(): Atmosphere;
|
|
84
|
+
setAtmosphere(atmosphere: AtmosphereInput): void;
|
|
85
|
+
getDevelopment(): Development | false;
|
|
86
|
+
setDevelopment(input: DevelopmentInput): void;
|
|
87
|
+
/** Last rendered logical pixel at canvas-relative CSS coordinates (top-left).
|
|
88
|
+
* Returns ground depth and coverage for each pixel.
|
|
89
|
+
* Returns null before a valid frame, outside the canvas, or for unsupported CRS. */
|
|
90
|
+
getDepthAt(x: number, y: number): DepthSample | null;
|
|
91
|
+
/** Capture linear FLOAT RGB + Z (axial metres) OpenEXR, without preview tone mapping.
|
|
92
|
+
* Pass { exposure: 'raw' } to preserve the unexposed receiver values. */
|
|
93
|
+
captureEXR(options?: {
|
|
94
|
+
exposure?: "preview" | "raw";
|
|
95
|
+
}): Promise<Blob>;
|
|
96
|
+
/** Replace the LUT after loading succeeds; omit the URL to restore the default atmosphere archive. */
|
|
97
|
+
setLUT(source?: string): Promise<void>;
|
|
56
98
|
onAdd(map: Map, context: WebGLRenderingContext | WebGL2RenderingContext): void;
|
|
57
99
|
onRemove(map: Map, context: WebGLRenderingContext | WebGL2RenderingContext): void;
|
|
58
100
|
prerender(gl: WebGL2RenderingContext, options: CustomRenderMethodInput): void;
|
|
59
101
|
render(context: WebGLRenderingContext | WebGL2RenderingContext, options: CustomRenderMethodInput): void;
|
|
60
102
|
}
|
|
61
|
-
|
|
62
|
-
export { NightLayer as default };
|
|
103
|
+
export { type Atmosphere, type AtmosphereInput, type Color, type Color3, type Color4, type DepthSample, type Development, type DevelopmentInput, type DevelopmentProcess, NightLayer as default, type Twilight, type TwilightInput, type TwilightSteps };
|