@maptoolkit/maplibre-scene3d-control 0.0.0-stage → 0.1.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/LICENSE +27 -0
- package/README.md +141 -2
- package/dist/Scene3dControl.d.ts +184 -0
- package/dist/index.d.ts +2 -0
- package/dist/maplibre-scene3d-control.css +2 -0
- package/dist/maplibre-scene3d-control.js +266 -0
- package/dist/maplibre-scene3d-control.js.map +1 -0
- package/package.json +75 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2026, Maptoolkit - Toursprung GmbH
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other third-party materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,142 @@
|
|
|
1
|
-
#
|
|
1
|
+
# maplibre-scene3d-control
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://www.npmjs.com/package/@maptoolkit/maplibre-scene3d-control)
|
|
5
|
+
|
|
6
|
+
A [MapLibre GL JS](https://maplibre.org/maplibre-gl-js/docs/) control plugin that adds the 3D scene of a Maptoolkit style: 3D buildings and glTF vegetation.
|
|
7
|
+
|
|
8
|
+
Maptoolkit styles name their scene in `metadata["maptoolkit:scene3d"]`. The control reads it whenever the style changes, so switching styles switches the scene. It draws the buildings with a `fill-extrusion` plus [`@maptoolkit/maplibre-3d-layers`](https://www.npmjs.com/package/@maptoolkit/maplibre-3d-layers) (`Fill3DLayer`, `GltfLayer`) and takes care of the rest:
|
|
9
|
+
|
|
10
|
+
- adds the buildings source with your API key,
|
|
11
|
+
- puts the layers under the style's labels,
|
|
12
|
+
- keeps the tilt in the global state `pitch`, which the scene's opacity fades read,
|
|
13
|
+
- rebuilds the layers after a style or terrain change; a diffed `setStyle` that keeps the scene only puts back what the diff dropped and keeps the 3D layers,
|
|
14
|
+
- loads the 3D library (with three.js) only once the map reaches zoom 12.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @maptoolkit/maplibre-scene3d-control @maptoolkit/maplibre-3d-layers three maplibre-gl
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import * as maplibregl from "maplibre-gl";
|
|
26
|
+
import { Scene3dControl } from "@maptoolkit/maplibre-scene3d-control";
|
|
27
|
+
import "@maptoolkit/maplibre-scene3d-control/style.css";
|
|
28
|
+
|
|
29
|
+
const map = new maplibregl.Map({
|
|
30
|
+
container: "map",
|
|
31
|
+
style: "https://styles.maptoolkit.net/maptoolkit/maptoolkit.summer.json?api_key=YOUR_KEY",
|
|
32
|
+
center: [16.359, 48.21],
|
|
33
|
+
zoom: 16,
|
|
34
|
+
pitch: 70,
|
|
35
|
+
maxPitch: 85,
|
|
36
|
+
canvasContextAttributes: { antialias: true }, // soft edges on distant trees
|
|
37
|
+
});
|
|
38
|
+
map.addControl(new Scene3dControl({ apiKey: "YOUR_KEY" }));
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
That is all: the scene of the style appears from zoom 12, and a style switch brings the next style's scene.
|
|
42
|
+
|
|
43
|
+
### Without a bundler
|
|
44
|
+
|
|
45
|
+
The package is ESM-only. With an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap), point `maplibre-gl` at its module build and let the control load the standalone build of maplibre-3d-layers, which includes three.js:
|
|
46
|
+
|
|
47
|
+
```html
|
|
48
|
+
<script type="importmap">
|
|
49
|
+
{ "imports": { "maplibre-gl": "https://unpkg.com/maplibre-gl@^6.0.0/dist/maplibre-gl.mjs" } }
|
|
50
|
+
</script>
|
|
51
|
+
<script type="module">
|
|
52
|
+
import * as maplibregl from "maplibre-gl";
|
|
53
|
+
import { Scene3dControl } from "https://unpkg.com/@maptoolkit/maplibre-scene3d-control@^0.1.0/dist/maplibre-scene3d-control.js";
|
|
54
|
+
|
|
55
|
+
const map = new maplibregl.Map({ container: "map", style, center, zoom, pitch: 70, canvasContextAttributes: { antialias: true } });
|
|
56
|
+
map.addControl(
|
|
57
|
+
new Scene3dControl({
|
|
58
|
+
apiKey: "YOUR_KEY",
|
|
59
|
+
library: () => import("https://unpkg.com/@maptoolkit/maplibre-3d-layers@^0.5.1/dist/maplibre-3d-layers.standalone.mjs"),
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
</script>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Options
|
|
66
|
+
|
|
67
|
+
| Option | Type | Default | Description |
|
|
68
|
+
| ------------ | ----------------------------------- | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
69
|
+
| `apiKey` | `string` | — | Maptoolkit API key, added to the buildings source URL as `api_key`. Without it the buildings source answers 403. |
|
|
70
|
+
| `scene` | `Scene3dManifest \| string \| null` | the style's | A scene (or its URL) to show instead of the style's own; `null` shows none. |
|
|
71
|
+
| `enabled` | `boolean` | `true` | Show the scene right away. |
|
|
72
|
+
| `button` | `boolean` | `false` | Add a 3D button that switches the scene on and off. Without it the control has no UI. |
|
|
73
|
+
| `minzoom` | `number` | `12` | Zoom from which the 3D library is loaded. The buildings source has no tiles below 12. |
|
|
74
|
+
| `hideLayers` | `string[]` | `["building_3d", "building_3d_multicolored"]` | Style layers hidden while the scene's buildings are shown, e.g. a style's own 3D buildings. Hidden only once the buildings source has loaded: without a working API key the style keeps them. |
|
|
75
|
+
| `modelBase` | `string` | document base URL | Base for relative model URLs. |
|
|
76
|
+
| `library` | `() => Promise<Scene3dLibrary>` | `import("@maptoolkit/maplibre-3d-layers")` | Loads the 3D library, e.g. from a CDN. |
|
|
77
|
+
| `idPrefix` | `string` | `"scene3d-"` | Prefix of the source and layer ids the control adds. |
|
|
78
|
+
|
|
79
|
+
## Methods
|
|
80
|
+
|
|
81
|
+
| Method | Description |
|
|
82
|
+
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
83
|
+
| `setScene(scene)` | Show another scene: a manifest, its URL, `null` for none, or `undefined` to go back to the style's own. The same scene again keeps the layers. |
|
|
84
|
+
| `getScene()` | The scene shown now, or `null`. |
|
|
85
|
+
| `setEnabled(on)` / `isEnabled()` | Switch the scene on or off. |
|
|
86
|
+
| `getLayers()` | The maplibre-3d-layers layers on the map, e.g. to drive them frame by frame. |
|
|
87
|
+
| `loadLibrary()` / `getLibrary()` | Load the 3D library now instead of at `minzoom`; the loaded library. |
|
|
88
|
+
|
|
89
|
+
## Events
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
control.on("scene.change", (ev) => console.log(ev.scene)); // built, rebuilt or removed
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## The scene (`metadata["maptoolkit:scene3d"]`, version 1)
|
|
96
|
+
|
|
97
|
+
All values are plain MapLibre or maplibre-3d-layers options. Maptoolkit styles get it from [style-family-js](https://github.com/maptoolkit/style-family-js).
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
{
|
|
101
|
+
version: 1,
|
|
102
|
+
source: "https://…/buildings.json", // TileJSON of the buildings, without api_key
|
|
103
|
+
lod1: { filter, paint, layout }, // fill-extrusion on the source layer buildings2d
|
|
104
|
+
fill3d: { paint }, // Fill3DLayer on the source layer buildings3d
|
|
105
|
+
models: { tree_1: "https://static.maptoolkit.net/3d/models/…/Tree.gltf" },
|
|
106
|
+
gltf: [{ id, models: ["tree_1"], source: "mtk", "source-layer": "natural", filter, minzoom, layout, paint, lighting }],
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Every part is optional except `version` and `source`. A layer goes under the style's labels unless it says `position: "top"`. Vegetation needs the source it names in the style (`mtk` in Maptoolkit styles); a layer whose source the style lacks is left out with a warning.
|
|
111
|
+
|
|
112
|
+
MapLibre ignores a diffed `setStyle` that changes nothing but the metadata. A scene that changes on its own, with the rest of the style unchanged, therefore never reaches the control that way: pass it with `setScene()` or use `setStyle` with `diff: false`.
|
|
113
|
+
|
|
114
|
+
## Requirements
|
|
115
|
+
|
|
116
|
+
- MapLibre GL JS ≥ 6, `@maptoolkit/maplibre-3d-layers` ≥ 0.5.1 and three.js ≥ 0.160 (peer dependencies of the 3D library).
|
|
117
|
+
- A Maptoolkit API key with access to the buildings source.
|
|
118
|
+
- A style with a scene, or a scene passed with `scene`. Vegetation also needs the style's `mtk` source.
|
|
119
|
+
|
|
120
|
+
## Styling
|
|
121
|
+
|
|
122
|
+
```css
|
|
123
|
+
.maplibre-scene3d-control {
|
|
124
|
+
--scene3d-control-color: #333;
|
|
125
|
+
--scene3d-control-color-active: #0074d9;
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Development
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npm install
|
|
133
|
+
npm run dev # demo on http://localhost:5173 (demo/index.html, scene in demo/public/scene.json)
|
|
134
|
+
npm test
|
|
135
|
+
npm run lint
|
|
136
|
+
npm run typecheck
|
|
137
|
+
npm run build
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
BSD-3-Clause
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Evented, ControlPosition, CustomLayerInterface, FilterSpecification, IControl, Map as MaplibreMap, MapLibreEvent } from 'maplibre-gl';
|
|
2
|
+
/** Root metadata key under which a Maptoolkit style carries its 3D scene. */
|
|
3
|
+
export declare const SCENE3D_METADATA_KEY = "maptoolkit:scene3d";
|
|
4
|
+
/** Where a layer of the scene goes: under the style's labels (default) or on top of everything. */
|
|
5
|
+
export type Scene3dPosition = "below-labels" | "top";
|
|
6
|
+
type Expression = unknown;
|
|
7
|
+
/** One glTF vegetation layer: maplibre-3d-layers `GltfLayer` options, `models` as ids of the scene's model library. */
|
|
8
|
+
export interface Scene3dGltfLayer {
|
|
9
|
+
id: string;
|
|
10
|
+
position?: Scene3dPosition;
|
|
11
|
+
/** Model ids from {@link Scene3dManifest.models}; all of them when missing. */
|
|
12
|
+
models?: string[];
|
|
13
|
+
source: string;
|
|
14
|
+
"source-layer"?: string;
|
|
15
|
+
filter?: FilterSpecification;
|
|
16
|
+
minzoom?: number;
|
|
17
|
+
maxzoom?: number;
|
|
18
|
+
layout?: Record<string, Expression>;
|
|
19
|
+
paint?: Record<string, Expression>;
|
|
20
|
+
lighting?: {
|
|
21
|
+
ambient?: number;
|
|
22
|
+
directional?: number;
|
|
23
|
+
environment?: number;
|
|
24
|
+
};
|
|
25
|
+
maxInstances?: number;
|
|
26
|
+
doubleSided?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** The 3D scene of a style, `metadata["maptoolkit:scene3d"]` (version 1). Values are plain MapLibre / maplibre-3d-layers options. */
|
|
29
|
+
export interface Scene3dManifest {
|
|
30
|
+
version: 1;
|
|
31
|
+
/** TileJSON URL of the buildings source, without api_key. */
|
|
32
|
+
source: string;
|
|
33
|
+
/** `fill-extrusion` on the source layer `buildings2d`. */
|
|
34
|
+
lod1?: {
|
|
35
|
+
position?: Scene3dPosition;
|
|
36
|
+
minzoom?: number;
|
|
37
|
+
maxzoom?: number;
|
|
38
|
+
filter?: FilterSpecification;
|
|
39
|
+
paint?: Record<string, Expression>;
|
|
40
|
+
layout?: Record<string, Expression>;
|
|
41
|
+
};
|
|
42
|
+
/** `Fill3DLayer` on the source layer `buildings3d`. */
|
|
43
|
+
fill3d?: {
|
|
44
|
+
position?: Scene3dPosition;
|
|
45
|
+
filter?: FilterSpecification;
|
|
46
|
+
paint?: Record<string, Expression>;
|
|
47
|
+
};
|
|
48
|
+
/** Model library of the vegetation: id → glTF/glb URL. */
|
|
49
|
+
models?: Record<string, string>;
|
|
50
|
+
gltf?: Scene3dGltfLayer[];
|
|
51
|
+
}
|
|
52
|
+
/** What the control needs from `@maptoolkit/maplibre-3d-layers`. */
|
|
53
|
+
export interface Scene3dLibrary {
|
|
54
|
+
Fill3DLayer: new (options: Record<string, unknown>) => CustomLayerInterface;
|
|
55
|
+
GltfLayer: new (options: Record<string, unknown>) => CustomLayerInterface;
|
|
56
|
+
}
|
|
57
|
+
export interface Scene3dControlOptions {
|
|
58
|
+
/** Maptoolkit API key, added to the buildings source URL as `api_key`. */
|
|
59
|
+
apiKey?: string;
|
|
60
|
+
/**
|
|
61
|
+
* The scene to show. Left out: the one the current style names in `metadata["maptoolkit:scene3d"]`,
|
|
62
|
+
* re-read on every style change. A manifest or its URL replaces it; `null` shows none.
|
|
63
|
+
*/
|
|
64
|
+
scene?: Scene3dManifest | string | null;
|
|
65
|
+
/** Show the scene right away (default `true`). */
|
|
66
|
+
enabled?: boolean;
|
|
67
|
+
/** Add a 3D button that switches the scene on and off (default `false`: the control has no UI). */
|
|
68
|
+
button?: boolean;
|
|
69
|
+
/** The 3D library is loaded once the map reaches this zoom; the buildings source has no tiles below 12 (default `12`). */
|
|
70
|
+
minzoom?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Style layers hidden while the scene's buildings are shown, e.g. a style's own 3D buildings (default the v2 ids
|
|
73
|
+
* `building_3d`, `building_3d_multicolored`). Hidden only once the buildings source has loaded, so without a working
|
|
74
|
+
* API key the style keeps them.
|
|
75
|
+
*/
|
|
76
|
+
hideLayers?: string[];
|
|
77
|
+
/** Base for relative model URLs (default the document's base URL). */
|
|
78
|
+
modelBase?: string;
|
|
79
|
+
/** Loads `@maptoolkit/maplibre-3d-layers` (default a dynamic import of the package). Pass another loader for its standalone build or a CDN. */
|
|
80
|
+
library?: () => Promise<Scene3dLibrary>;
|
|
81
|
+
/** Prefix of the source and layer ids the control adds (default `"scene3d-"`). */
|
|
82
|
+
idPrefix?: string;
|
|
83
|
+
}
|
|
84
|
+
/** Fired via `control.on("scene.change", ...)` whenever the shown scene is (re)built or removed. */
|
|
85
|
+
export type Scene3dControlEventType = {
|
|
86
|
+
"scene.change": MapLibreEvent<"scene.change"> & {
|
|
87
|
+
scene: Scene3dManifest | null;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
type ResolvedOptions = Required<Omit<Scene3dControlOptions, "apiKey" | "scene" | "modelBase">> & Pick<Scene3dControlOptions, "apiKey" | "modelBase">;
|
|
91
|
+
/**
|
|
92
|
+
* A MapLibre GL JS control plugin that adds the 3D scene of a Maptoolkit style: 3D buildings
|
|
93
|
+
* (a `fill-extrusion` plus maplibre-3d-layers' `Fill3DLayer`) and glTF vegetation (`GltfLayer`).
|
|
94
|
+
*
|
|
95
|
+
* The scene comes from the style itself (`metadata["maptoolkit:scene3d"]`, written by style-family-js),
|
|
96
|
+
* so a style switch brings its own scene. The control keeps the tilt in the global state `pitch`
|
|
97
|
+
* that the scene's opacity fades read, puts the layers under the style's labels, rebuilds them after
|
|
98
|
+
* style and terrain changes and loads the 3D library only when the map gets close enough.
|
|
99
|
+
*/
|
|
100
|
+
export declare class Scene3dControl extends Evented<Scene3dControlEventType> implements IControl {
|
|
101
|
+
readonly options: ResolvedOptions;
|
|
102
|
+
private map?;
|
|
103
|
+
private container?;
|
|
104
|
+
private button?;
|
|
105
|
+
private enabled;
|
|
106
|
+
/** undefined: the style's own scene. */
|
|
107
|
+
private override;
|
|
108
|
+
private scene;
|
|
109
|
+
private lib?;
|
|
110
|
+
private libPromise?;
|
|
111
|
+
private custom;
|
|
112
|
+
private native;
|
|
113
|
+
private hidden;
|
|
114
|
+
private loadedStyle;
|
|
115
|
+
private pitch;
|
|
116
|
+
private building;
|
|
117
|
+
private generation;
|
|
118
|
+
private warned;
|
|
119
|
+
/** Stops waiting for the buildings source (see hideOnceBuildingsLoad). */
|
|
120
|
+
private stopWaiting?;
|
|
121
|
+
/** The scene last read from the style or override (also an unsupported one), and as JSON; null for none. */
|
|
122
|
+
private sceneRef;
|
|
123
|
+
private sceneKey;
|
|
124
|
+
/** Whether the buildings source of the current scene has loaded (its TileJSON answered). */
|
|
125
|
+
private sourceOk;
|
|
126
|
+
/** Custom layers added with `position: "top"`. */
|
|
127
|
+
private topIds;
|
|
128
|
+
constructor(options?: Scene3dControlOptions);
|
|
129
|
+
getDefaultPosition(): ControlPosition;
|
|
130
|
+
onAdd(map: MaplibreMap): HTMLElement;
|
|
131
|
+
onRemove(): void;
|
|
132
|
+
/**
|
|
133
|
+
* Replace the style's scene: a manifest, the URL of one, `null` for none, or `undefined` to go back
|
|
134
|
+
* to the style's own scene. The same scene again keeps the layers.
|
|
135
|
+
*
|
|
136
|
+
* MapLibre ignores a diffed `setStyle` that changes nothing but the metadata, so a scene that changes
|
|
137
|
+
* on its own never reaches the control that way; pass it here (or use `setStyle` with `diff: false`).
|
|
138
|
+
*/
|
|
139
|
+
setScene(scene: Scene3dManifest | string | null | undefined): Promise<void>;
|
|
140
|
+
/** The scene shown now, or null. */
|
|
141
|
+
getScene(): Scene3dManifest | null;
|
|
142
|
+
setEnabled(enabled: boolean): void;
|
|
143
|
+
isEnabled(): boolean;
|
|
144
|
+
/** The maplibre-3d-layers layers on the map (`Fill3DLayer`, `GltfLayer`s), e.g. to drive them frame by frame. */
|
|
145
|
+
getLayers(): CustomLayerInterface[];
|
|
146
|
+
/** The 3D library, once loaded. */
|
|
147
|
+
getLibrary(): Scene3dLibrary | undefined;
|
|
148
|
+
/** Load the 3D library now instead of waiting for `minzoom`. */
|
|
149
|
+
loadLibrary(): Promise<Scene3dLibrary>;
|
|
150
|
+
private onStyleLoad;
|
|
151
|
+
private onStyleData;
|
|
152
|
+
private syncWithStyle;
|
|
153
|
+
private onTerrain;
|
|
154
|
+
private onZoom;
|
|
155
|
+
/** `["global-state", "pitch"]` for the scene's opacity fades. Whole degrees: each change is a style update. */
|
|
156
|
+
private syncPitch;
|
|
157
|
+
private styleReady;
|
|
158
|
+
private currentScene;
|
|
159
|
+
private refresh;
|
|
160
|
+
private sourceId;
|
|
161
|
+
/** The id of the style's first symbol layer: the scene goes right below it. */
|
|
162
|
+
private labelsAnchor;
|
|
163
|
+
private beforeFor;
|
|
164
|
+
/** The buildings source and the native layers, before `anchor` (default: under the labels). */
|
|
165
|
+
private addNative;
|
|
166
|
+
/** After a diffed setStyle with the same scene: put back the source and native layers, keep the 3D layers. */
|
|
167
|
+
private restoreNative;
|
|
168
|
+
private loadCustom;
|
|
169
|
+
private addCustom;
|
|
170
|
+
private removeCustom;
|
|
171
|
+
/** Remove everything the control added; `restore` puts hidden style layers back. */
|
|
172
|
+
private teardown;
|
|
173
|
+
/**
|
|
174
|
+
* Hide the style's own 3D buildings (`hideLayers`) only once the scene's buildings source has
|
|
175
|
+
* loaded. Without a working API key it answers 403, and the style keeps its buildings.
|
|
176
|
+
*/
|
|
177
|
+
private hideOnceBuildingsLoad;
|
|
178
|
+
private hideStyleLayers;
|
|
179
|
+
private withKey;
|
|
180
|
+
private modelUrl;
|
|
181
|
+
private showState;
|
|
182
|
+
private warnOnce;
|
|
183
|
+
}
|
|
184
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.maplibre-scene3d-control{--scene3d-control-color:#333;--scene3d-control-color-active:#0074d9}.maplibre-scene3d-control-hidden{display:none}.maplibre-scene3d-control-toggle{color:var(--scene3d-control-color);justify-content:center;align-items:center;display:flex}.maplibre-scene3d-control-toggle svg{width:20px;height:20px}.maplibre-scene3d-control-toggle[aria-pressed=true]{color:var(--scene3d-control-color-active)}
|
|
2
|
+
/*$vite$:1*/
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { Evented as e } from "maplibre-gl";
|
|
2
|
+
// src/Scene3dControl.ts
|
|
3
|
+
var t = "maptoolkit:scene3d", n = {
|
|
4
|
+
enabled: !0,
|
|
5
|
+
button: !1,
|
|
6
|
+
minzoom: 12,
|
|
7
|
+
hideLayers: ["building_3d", "building_3d_multicolored"],
|
|
8
|
+
idPrefix: "scene3d-"
|
|
9
|
+
}, r = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"currentColor\" d=\"M12 2 3 7v10l9 5 9-5V7l-9-5Zm0 2.3L18.7 8 12 11.7 5.3 8 12 4.3ZM5 9.7l6 3.3v6.7l-6-3.4V9.7Zm8 10V13l6-3.3v6.6l-6 3.4Z\"/></svg>", i = (e) => e.style, a = (e) => e ? JSON.stringify(e) : null, o = class extends e {
|
|
10
|
+
options;
|
|
11
|
+
map;
|
|
12
|
+
container;
|
|
13
|
+
button;
|
|
14
|
+
enabled;
|
|
15
|
+
override;
|
|
16
|
+
scene = null;
|
|
17
|
+
lib;
|
|
18
|
+
libPromise;
|
|
19
|
+
custom = [];
|
|
20
|
+
native = [];
|
|
21
|
+
hidden = /* @__PURE__ */ new Map();
|
|
22
|
+
loadedStyle = void 0;
|
|
23
|
+
pitch = null;
|
|
24
|
+
building = !1;
|
|
25
|
+
generation = 0;
|
|
26
|
+
warned = /* @__PURE__ */ new Set();
|
|
27
|
+
stopWaiting;
|
|
28
|
+
sceneRef = null;
|
|
29
|
+
sceneKey = null;
|
|
30
|
+
sourceOk = !1;
|
|
31
|
+
topIds = /* @__PURE__ */ new Set();
|
|
32
|
+
constructor(e = {}) {
|
|
33
|
+
super();
|
|
34
|
+
let { scene: t, ...r } = e;
|
|
35
|
+
this.options = {
|
|
36
|
+
...n,
|
|
37
|
+
library: () => import("@maptoolkit/maplibre-3d-layers"),
|
|
38
|
+
...Object.fromEntries(Object.entries(r).filter(([, e]) => e !== void 0))
|
|
39
|
+
}, this.enabled = this.options.enabled, t !== void 0 && this.setScene(t);
|
|
40
|
+
}
|
|
41
|
+
getDefaultPosition() {
|
|
42
|
+
return "top-right";
|
|
43
|
+
}
|
|
44
|
+
onAdd(e) {
|
|
45
|
+
this.map = e;
|
|
46
|
+
let t = document.createElement("div");
|
|
47
|
+
if (t.className = "maplibregl-ctrl maplibregl-ctrl-group maplibre-scene3d-control", this.options.button) {
|
|
48
|
+
let e = document.createElement("button");
|
|
49
|
+
e.type = "button", e.className = "maplibre-scene3d-control-toggle", e.title = "3D", e.setAttribute("aria-label", "3D"), e.innerHTML = r, e.addEventListener("click", () => this.setEnabled(!this.enabled)), t.appendChild(e), this.button = e, this.showState();
|
|
50
|
+
} else t.classList.add("maplibre-scene3d-control-hidden");
|
|
51
|
+
return this.container = t, e.on("style.load", this.onStyleLoad), e.on("styledata", this.onStyleData), e.on("terrain", this.onTerrain), e.on("pitch", this.syncPitch), e.on("zoomend", this.onZoom), i(e)?._loaded && this.onStyleLoad(), t;
|
|
52
|
+
}
|
|
53
|
+
onRemove() {
|
|
54
|
+
let e = this.map;
|
|
55
|
+
e && (this.teardown(!0), e.off("style.load", this.onStyleLoad), e.off("styledata", this.onStyleData), e.off("terrain", this.onTerrain), e.off("pitch", this.syncPitch), e.off("zoomend", this.onZoom), this.container?.remove(), this.container = this.button = void 0, this.map = void 0, this.loadedStyle = void 0);
|
|
56
|
+
}
|
|
57
|
+
async setScene(e) {
|
|
58
|
+
if (typeof e == "string") {
|
|
59
|
+
let t = await fetch(new URL(e, document.baseURI).href);
|
|
60
|
+
if (!t.ok) throw Error(`Scene ${e}: HTTP ${t.status}`);
|
|
61
|
+
e = await t.json();
|
|
62
|
+
}
|
|
63
|
+
(e === void 0 || this.override === void 0 || a(e) !== a(this.override)) && (this.override = e, this.refresh());
|
|
64
|
+
}
|
|
65
|
+
getScene() {
|
|
66
|
+
return this.scene;
|
|
67
|
+
}
|
|
68
|
+
setEnabled(e) {
|
|
69
|
+
this.enabled !== e && (this.enabled = e, this.showState(), this.refresh());
|
|
70
|
+
}
|
|
71
|
+
isEnabled() {
|
|
72
|
+
return this.enabled;
|
|
73
|
+
}
|
|
74
|
+
getLayers() {
|
|
75
|
+
return [...this.custom];
|
|
76
|
+
}
|
|
77
|
+
getLibrary() {
|
|
78
|
+
return this.lib;
|
|
79
|
+
}
|
|
80
|
+
loadLibrary() {
|
|
81
|
+
return this.libPromise ??= this.options.library().then((e) => this.lib = e, (e) => {
|
|
82
|
+
throw this.libPromise = void 0, e;
|
|
83
|
+
}), this.libPromise;
|
|
84
|
+
}
|
|
85
|
+
onStyleLoad = () => {
|
|
86
|
+
this.map && (this.pitch = null, i(this.map) === this.loadedStyle ? this.syncWithStyle() : (this.loadedStyle = i(this.map), this.teardown(!1), this.refresh()));
|
|
87
|
+
};
|
|
88
|
+
onStyleData = () => this.syncWithStyle();
|
|
89
|
+
syncWithStyle() {
|
|
90
|
+
if (this.building || !this.map || !this.styleReady()) return;
|
|
91
|
+
let e = this.map, t = this.currentScene();
|
|
92
|
+
if (t !== this.sceneRef) {
|
|
93
|
+
if (a(t) !== this.sceneKey) {
|
|
94
|
+
this.refresh();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.sceneRef = t;
|
|
98
|
+
}
|
|
99
|
+
this.scene && (this.custom.some((t) => !e.getLayer(t.id)) ? this.refresh() : this.native.some((t) => !e.getLayer(t)) || !e.getSource(this.sourceId()) ? this.restoreNative() : this.syncPitch());
|
|
100
|
+
}
|
|
101
|
+
onTerrain = () => {
|
|
102
|
+
this.map && this.styleReady() && this.custom.length && this.scene && (this.removeCustom(), this.addCustom(this.scene, this.generation));
|
|
103
|
+
};
|
|
104
|
+
onZoom = () => {
|
|
105
|
+
!this.map || this.lib || !this.scene || this.map.getZoom() < this.options.minzoom || this.loadCustom(this.scene, this.generation);
|
|
106
|
+
};
|
|
107
|
+
syncPitch = () => {
|
|
108
|
+
if (!this.map || !this.styleReady()) return;
|
|
109
|
+
let e = Math.round(this.map.getPitch());
|
|
110
|
+
e !== this.pitch && (this.pitch = e, this.map.setGlobalStateProperty("pitch", e));
|
|
111
|
+
};
|
|
112
|
+
styleReady() {
|
|
113
|
+
return !!this.map && !!this.loadedStyle && i(this.map) === this.loadedStyle;
|
|
114
|
+
}
|
|
115
|
+
currentScene() {
|
|
116
|
+
if (!this.enabled) return null;
|
|
117
|
+
if (this.override !== void 0) return this.override;
|
|
118
|
+
let e = this.map?.style?.stylesheet;
|
|
119
|
+
return (e ? e.metadata : this.map?.getStyle()?.metadata)?.["maptoolkit:scene3d"] ?? null;
|
|
120
|
+
}
|
|
121
|
+
refresh() {
|
|
122
|
+
let e = this.map;
|
|
123
|
+
if (e && this.styleReady()) {
|
|
124
|
+
this.building = !0;
|
|
125
|
+
try {
|
|
126
|
+
this.teardown(!0);
|
|
127
|
+
let t = ++this.generation, n = this.currentScene();
|
|
128
|
+
this.sceneRef = n, this.sceneKey = a(n), n && n.version !== 1 && (this.warnOnce(`version-${String(n.version)}`, `Scene3dControl: unsupported scene version ${String(n.version)}`), n = null), this.scene = n, n && (this.syncPitch(), (n.lod1 || n.fill3d) && this.hideOnceBuildingsLoad(t), this.addNative(n), this.lib ? this.addCustom(n, t) : e.getZoom() >= this.options.minzoom && this.loadCustom(n, t));
|
|
129
|
+
} finally {
|
|
130
|
+
this.building = !1;
|
|
131
|
+
}
|
|
132
|
+
this.fire("scene.change", { scene: this.scene });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
sourceId() {
|
|
136
|
+
return `${this.options.idPrefix}buildings`;
|
|
137
|
+
}
|
|
138
|
+
labelsAnchor() {
|
|
139
|
+
return this.map?.getStyle().layers.find((e) => e.type === "symbol" && !e.id.startsWith(this.options.idPrefix))?.id;
|
|
140
|
+
}
|
|
141
|
+
beforeFor(e, t) {
|
|
142
|
+
return e === "top" ? void 0 : t;
|
|
143
|
+
}
|
|
144
|
+
addNative(e, t = this.labelsAnchor()) {
|
|
145
|
+
let n = this.map, r = this.sourceId();
|
|
146
|
+
n.getSource(r) || n.addSource(r, {
|
|
147
|
+
type: "vector",
|
|
148
|
+
url: this.withKey(e.source)
|
|
149
|
+
});
|
|
150
|
+
let i = this.options.idPrefix;
|
|
151
|
+
if (e.lod1) {
|
|
152
|
+
let { position: a, ...o } = e.lod1;
|
|
153
|
+
n.addLayer({
|
|
154
|
+
id: `${i}lod1`,
|
|
155
|
+
type: "fill-extrusion",
|
|
156
|
+
source: r,
|
|
157
|
+
"source-layer": "buildings2d",
|
|
158
|
+
...o
|
|
159
|
+
}, this.beforeFor(a, t)), this.native.push(`${i}lod1`);
|
|
160
|
+
} else e.fill3d && (n.addLayer({
|
|
161
|
+
id: `${i}consumer`,
|
|
162
|
+
type: "fill",
|
|
163
|
+
source: r,
|
|
164
|
+
"source-layer": "buildings2d",
|
|
165
|
+
filter: ["boolean", !1],
|
|
166
|
+
paint: { "fill-opacity": 0 }
|
|
167
|
+
}, this.beforeFor(e.fill3d.position, t)), this.native.push(`${i}consumer`));
|
|
168
|
+
}
|
|
169
|
+
restoreNative() {
|
|
170
|
+
let e = this.map, t = this.scene;
|
|
171
|
+
this.building = !0;
|
|
172
|
+
try {
|
|
173
|
+
for (let t of this.native) e.getLayer(t) && e.removeLayer(t);
|
|
174
|
+
this.native = [], this.hidden.clear(), this.addNative(t, this.custom.find((e) => !this.topIds.has(e.id))?.id ?? this.labelsAnchor()), (t.lod1 || t.fill3d) && (this.sourceOk ? this.hideStyleLayers() : (this.stopWaiting?.(), this.hideOnceBuildingsLoad(this.generation))), this.pitch = null, this.syncPitch();
|
|
175
|
+
} finally {
|
|
176
|
+
this.building = !1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
loadCustom(e, t) {
|
|
180
|
+
this.loadLibrary().then(() => {
|
|
181
|
+
t === this.generation && this.scene === e && !this.custom.length && this.addCustom(e, t);
|
|
182
|
+
}, (e) => console.error("Scene3dControl: could not load @maptoolkit/maplibre-3d-layers", e));
|
|
183
|
+
}
|
|
184
|
+
addCustom(e, t) {
|
|
185
|
+
let n = this.map, r = this.lib;
|
|
186
|
+
if (!n || !r || t !== this.generation || !this.styleReady()) return;
|
|
187
|
+
let i = this.labelsAnchor(), a = this.options.idPrefix, o = (e, t) => {
|
|
188
|
+
n.addLayer(e, this.beforeFor(t, i)), this.custom.push(e), t === "top" && this.topIds.add(e.id);
|
|
189
|
+
};
|
|
190
|
+
this.building = !0;
|
|
191
|
+
try {
|
|
192
|
+
if (e.fill3d) {
|
|
193
|
+
let { position: t, ...n } = e.fill3d;
|
|
194
|
+
o(new r.Fill3DLayer({
|
|
195
|
+
id: `${a}fill3d`,
|
|
196
|
+
source: this.sourceId(),
|
|
197
|
+
"source-layer": "buildings3d",
|
|
198
|
+
...n
|
|
199
|
+
}), t);
|
|
200
|
+
}
|
|
201
|
+
let t = e.models ?? {};
|
|
202
|
+
for (let i of e.gltf ?? []) {
|
|
203
|
+
let { id: e, position: s, models: c, ...l } = i;
|
|
204
|
+
if (!n.getSource(l.source)) {
|
|
205
|
+
this.warnOnce(`source-${l.source}`, `Scene3dControl: the style has no source "${l.source}", layer "${e}" left out`);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
let u = c ?? Object.keys(t), d = Object.fromEntries(u.filter((e) => t[e]).map((e) => [e, this.modelUrl(t[e])]));
|
|
209
|
+
Object.keys(d).length && o(new r.GltfLayer({
|
|
210
|
+
id: `${a}${e}`,
|
|
211
|
+
models: d,
|
|
212
|
+
...l
|
|
213
|
+
}), s);
|
|
214
|
+
}
|
|
215
|
+
} finally {
|
|
216
|
+
this.building = !1;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
removeCustom() {
|
|
220
|
+
let e = this.map;
|
|
221
|
+
for (let t of this.custom) e?.getLayer(t.id) ? e.removeLayer(t.id) : e && t.onRemove?.(e, void 0);
|
|
222
|
+
this.custom = [], this.topIds.clear();
|
|
223
|
+
}
|
|
224
|
+
teardown(e) {
|
|
225
|
+
let t = this.map;
|
|
226
|
+
this.stopWaiting?.(), this.building = !0;
|
|
227
|
+
try {
|
|
228
|
+
if (this.removeCustom(), t) {
|
|
229
|
+
for (let e of this.native) t.getLayer(e) && t.removeLayer(e);
|
|
230
|
+
if (t.getSource(this.sourceId()) && this.styleReady() && t.removeSource(this.sourceId()), e && this.styleReady()) for (let [e, n] of this.hidden) t.getLayer(e) && t.setLayoutProperty(e, "visibility", n);
|
|
231
|
+
}
|
|
232
|
+
this.native = [], this.hidden.clear(), this.scene = null, this.sourceOk = !1;
|
|
233
|
+
} finally {
|
|
234
|
+
this.building = !1;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
hideOnceBuildingsLoad(e) {
|
|
238
|
+
let t = this.map, n = this.sourceId(), r = (r) => {
|
|
239
|
+
r.sourceId === n && r.sourceDataType === "metadata" && t.getSource(n) && (this.stopWaiting?.(), e === this.generation && this.styleReady() && (this.sourceOk = !0, this.hideStyleLayers()));
|
|
240
|
+
};
|
|
241
|
+
t.on("sourcedata", r), this.stopWaiting = () => {
|
|
242
|
+
t.off("sourcedata", r), this.stopWaiting = void 0;
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
hideStyleLayers() {
|
|
246
|
+
let e = this.map;
|
|
247
|
+
for (let t of this.options.hideLayers) e.getLayer(t) && (this.hidden.set(t, e.getLayoutProperty(t, "visibility") ?? "visible"), e.setLayoutProperty(t, "visibility", "none"));
|
|
248
|
+
}
|
|
249
|
+
withKey(e) {
|
|
250
|
+
if (!this.options.apiKey) return e;
|
|
251
|
+
let t = new URL(e, document.baseURI);
|
|
252
|
+
return t.searchParams.has("api_key") || t.searchParams.set("api_key", this.options.apiKey), t.href;
|
|
253
|
+
}
|
|
254
|
+
modelUrl(e) {
|
|
255
|
+
return new URL(e, this.options.modelBase ?? document.baseURI).href;
|
|
256
|
+
}
|
|
257
|
+
showState() {
|
|
258
|
+
this.button?.setAttribute("aria-pressed", String(this.enabled));
|
|
259
|
+
}
|
|
260
|
+
warnOnce(e, t) {
|
|
261
|
+
this.warned.has(e) || (this.warned.add(e), console.warn(t));
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
export { t as SCENE3D_METADATA_KEY, o as Scene3dControl };
|
|
265
|
+
|
|
266
|
+
//# sourceMappingURL=maplibre-scene3d-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maplibre-scene3d-control.js","names":["SCENE3D_METADATA_KEY","DEFAULTS","CUBE_ICON","styleOf","map","sceneKeyOf","scene","Scene3dControl","Evented","rest","options","v","container","button","response","enabled","lib","err","next","l","id","pitch","sheet","generation","position","anchor","source","p","lod1","add","layer","fill3d","library","entry","ids","picked","models","m","restore","visibility","onData","e","url","u","key","message"],"sources":["../src/Scene3dControl.ts"],"sourcesContent":["import { Evented } from \"maplibre-gl\";\nimport type { ControlPosition, CustomLayerInterface, FilterSpecification, IControl, Map as MaplibreMap, MapLibreEvent, MapSourceDataEvent } from \"maplibre-gl\";\n\n/** Root metadata key under which a Maptoolkit style carries its 3D scene. */\nexport const SCENE3D_METADATA_KEY = \"maptoolkit:scene3d\";\n\n/** Where a layer of the scene goes: under the style's labels (default) or on top of everything. */\nexport type Scene3dPosition = \"below-labels\" | \"top\";\n\ntype Expression = unknown;\n\n/** One glTF vegetation layer: maplibre-3d-layers `GltfLayer` options, `models` as ids of the scene's model library. */\nexport interface Scene3dGltfLayer {\n id: string;\n position?: Scene3dPosition;\n /** Model ids from {@link Scene3dManifest.models}; all of them when missing. */\n models?: string[];\n source: string;\n \"source-layer\"?: string;\n filter?: FilterSpecification;\n minzoom?: number;\n maxzoom?: number;\n layout?: Record<string, Expression>;\n paint?: Record<string, Expression>;\n lighting?: { ambient?: number; directional?: number; environment?: number };\n maxInstances?: number;\n doubleSided?: boolean;\n}\n\n/** The 3D scene of a style, `metadata[\"maptoolkit:scene3d\"]` (version 1). Values are plain MapLibre / maplibre-3d-layers options. */\nexport interface Scene3dManifest {\n version: 1;\n /** TileJSON URL of the buildings source, without api_key. */\n source: string;\n /** `fill-extrusion` on the source layer `buildings2d`. */\n lod1?: {\n position?: Scene3dPosition;\n minzoom?: number;\n maxzoom?: number;\n filter?: FilterSpecification;\n paint?: Record<string, Expression>;\n layout?: Record<string, Expression>;\n };\n /** `Fill3DLayer` on the source layer `buildings3d`. */\n fill3d?: { position?: Scene3dPosition; filter?: FilterSpecification; paint?: Record<string, Expression> };\n /** Model library of the vegetation: id → glTF/glb URL. */\n models?: Record<string, string>;\n gltf?: Scene3dGltfLayer[];\n}\n\n/** What the control needs from `@maptoolkit/maplibre-3d-layers`. */\nexport interface Scene3dLibrary {\n Fill3DLayer: new (options: Record<string, unknown>) => CustomLayerInterface;\n GltfLayer: new (options: Record<string, unknown>) => CustomLayerInterface;\n}\n\nexport interface Scene3dControlOptions {\n /** Maptoolkit API key, added to the buildings source URL as `api_key`. */\n apiKey?: string;\n /**\n * The scene to show. Left out: the one the current style names in `metadata[\"maptoolkit:scene3d\"]`,\n * re-read on every style change. A manifest or its URL replaces it; `null` shows none.\n */\n scene?: Scene3dManifest | string | null;\n /** Show the scene right away (default `true`). */\n enabled?: boolean;\n /** Add a 3D button that switches the scene on and off (default `false`: the control has no UI). */\n button?: boolean;\n /** The 3D library is loaded once the map reaches this zoom; the buildings source has no tiles below 12 (default `12`). */\n minzoom?: number;\n /**\n * Style layers hidden while the scene's buildings are shown, e.g. a style's own 3D buildings (default the v2 ids\n * `building_3d`, `building_3d_multicolored`). Hidden only once the buildings source has loaded, so without a working\n * API key the style keeps them.\n */\n hideLayers?: string[];\n /** Base for relative model URLs (default the document's base URL). */\n modelBase?: string;\n /** Loads `@maptoolkit/maplibre-3d-layers` (default a dynamic import of the package). Pass another loader for its standalone build or a CDN. */\n library?: () => Promise<Scene3dLibrary>;\n /** Prefix of the source and layer ids the control adds (default `\"scene3d-\"`). */\n idPrefix?: string;\n}\n\n/** Fired via `control.on(\"scene.change\", ...)` whenever the shown scene is (re)built or removed. */\nexport type Scene3dControlEventType = {\n \"scene.change\": MapLibreEvent<\"scene.change\"> & { scene: Scene3dManifest | null };\n};\n\ntype ResolvedOptions = Required<Omit<Scene3dControlOptions, \"apiKey\" | \"scene\" | \"modelBase\">> & Pick<Scene3dControlOptions, \"apiKey\" | \"modelBase\">;\n\nconst DEFAULTS: Omit<ResolvedOptions, \"library\"> = {\n enabled: true,\n button: false,\n minzoom: 12,\n hideLayers: [\"building_3d\", \"building_3d_multicolored\"],\n idPrefix: \"scene3d-\",\n};\n\nconst CUBE_ICON =\n '<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"currentColor\" d=\"M12 2 3 7v10l9 5 9-5V7l-9-5Zm0 2.3L18.7 8 12 11.7 5.3 8 12 4.3ZM5 9.7l6 3.3v6.7l-6-3.4V9.7Zm8 10V13l6-3.3v6.6l-6 3.4Z\"/></svg>';\n\n// MapLibre's Style is private API; the control only reads whether it has loaded and its identity.\ntype StyleHandle = { _loaded?: boolean } | undefined;\nconst styleOf = (map: MaplibreMap) => (map as unknown as { style?: StyleHandle }).style;\n/** Compares scenes across style updates: the metadata comes as a new object each time. */\nconst sceneKeyOf = (scene: Scene3dManifest | null) => (scene ? JSON.stringify(scene) : null);\n\n/**\n * A MapLibre GL JS control plugin that adds the 3D scene of a Maptoolkit style: 3D buildings\n * (a `fill-extrusion` plus maplibre-3d-layers' `Fill3DLayer`) and glTF vegetation (`GltfLayer`).\n *\n * The scene comes from the style itself (`metadata[\"maptoolkit:scene3d\"]`, written by style-family-js),\n * so a style switch brings its own scene. The control keeps the tilt in the global state `pitch`\n * that the scene's opacity fades read, puts the layers under the style's labels, rebuilds them after\n * style and terrain changes and loads the 3D library only when the map gets close enough.\n */\nexport class Scene3dControl extends Evented<Scene3dControlEventType> implements IControl {\n readonly options: ResolvedOptions;\n\n private map?: MaplibreMap;\n private container?: HTMLElement;\n private button?: HTMLButtonElement;\n private enabled: boolean;\n /** undefined: the style's own scene. */\n private override: Scene3dManifest | null | undefined;\n private scene: Scene3dManifest | null = null;\n private lib?: Scene3dLibrary;\n private libPromise?: Promise<Scene3dLibrary>;\n private custom: CustomLayerInterface[] = [];\n private native: string[] = [];\n private hidden = new Map<string, \"visible\" | \"none\">();\n private loadedStyle: StyleHandle = undefined;\n private pitch: number | null = null;\n private building = false;\n private generation = 0;\n private warned = new Set<string>();\n /** Stops waiting for the buildings source (see hideOnceBuildingsLoad). */\n private stopWaiting?: () => void;\n /** The scene last read from the style or override (also an unsupported one), and as JSON; null for none. */\n private sceneRef: Scene3dManifest | null = null;\n private sceneKey: string | null = null;\n /** Whether the buildings source of the current scene has loaded (its TileJSON answered). */\n private sourceOk = false;\n /** Custom layers added with `position: \"top\"`. */\n private topIds = new Set<string>();\n\n constructor(options: Scene3dControlOptions = {}) {\n super();\n const { scene, ...rest } = options;\n this.options = {\n ...DEFAULTS,\n library: () => import(\"@maptoolkit/maplibre-3d-layers\") as unknown as Promise<Scene3dLibrary>,\n ...Object.fromEntries(Object.entries(rest).filter(([, v]) => v !== undefined)),\n } as ResolvedOptions;\n this.enabled = this.options.enabled;\n if (scene !== undefined) void this.setScene(scene);\n }\n\n getDefaultPosition(): ControlPosition {\n return \"top-right\";\n }\n\n onAdd(map: MaplibreMap): HTMLElement {\n this.map = map;\n const container = document.createElement(\"div\");\n container.className = \"maplibregl-ctrl maplibregl-ctrl-group maplibre-scene3d-control\";\n if (this.options.button) {\n const button = document.createElement(\"button\");\n button.type = \"button\";\n button.className = \"maplibre-scene3d-control-toggle\";\n button.title = \"3D\";\n button.setAttribute(\"aria-label\", \"3D\");\n button.innerHTML = CUBE_ICON;\n button.addEventListener(\"click\", () => this.setEnabled(!this.enabled));\n container.appendChild(button);\n this.button = button;\n this.showState();\n } else {\n container.classList.add(\"maplibre-scene3d-control-hidden\");\n }\n this.container = container;\n\n map.on(\"style.load\", this.onStyleLoad);\n map.on(\"styledata\", this.onStyleData);\n map.on(\"terrain\", this.onTerrain);\n map.on(\"pitch\", this.syncPitch);\n map.on(\"zoomend\", this.onZoom);\n // Added to a map whose style has already loaded: no style.load will come for it.\n if (styleOf(map)?._loaded) this.onStyleLoad();\n return container;\n }\n\n onRemove(): void {\n const map = this.map;\n if (!map) return;\n this.teardown(true);\n map.off(\"style.load\", this.onStyleLoad);\n map.off(\"styledata\", this.onStyleData);\n map.off(\"terrain\", this.onTerrain);\n map.off(\"pitch\", this.syncPitch);\n map.off(\"zoomend\", this.onZoom);\n this.container?.remove();\n this.container = this.button = undefined;\n this.map = undefined;\n this.loadedStyle = undefined;\n }\n\n /**\n * Replace the style's scene: a manifest, the URL of one, `null` for none, or `undefined` to go back\n * to the style's own scene. The same scene again keeps the layers.\n *\n * MapLibre ignores a diffed `setStyle` that changes nothing but the metadata, so a scene that changes\n * on its own never reaches the control that way; pass it here (or use `setStyle` with `diff: false`).\n */\n async setScene(scene: Scene3dManifest | string | null | undefined): Promise<void> {\n if (typeof scene === \"string\") {\n const response = await fetch(new URL(scene, document.baseURI).href);\n if (!response.ok) throw new Error(`Scene ${scene}: HTTP ${response.status}`);\n scene = (await response.json()) as Scene3dManifest;\n }\n // The same scene again (e.g. after every style update of an editor) keeps the layers.\n if (scene !== undefined && this.override !== undefined && sceneKeyOf(scene) === sceneKeyOf(this.override)) return;\n this.override = scene;\n this.refresh();\n }\n\n /** The scene shown now, or null. */\n getScene(): Scene3dManifest | null {\n return this.scene;\n }\n\n setEnabled(enabled: boolean): void {\n if (this.enabled === enabled) return;\n this.enabled = enabled;\n this.showState();\n this.refresh();\n }\n\n isEnabled(): boolean {\n return this.enabled;\n }\n\n /** The maplibre-3d-layers layers on the map (`Fill3DLayer`, `GltfLayer`s), e.g. to drive them frame by frame. */\n getLayers(): CustomLayerInterface[] {\n return [...this.custom];\n }\n\n /** The 3D library, once loaded. */\n getLibrary(): Scene3dLibrary | undefined {\n return this.lib;\n }\n\n /** Load the 3D library now instead of waiting for `minzoom`. */\n loadLibrary(): Promise<Scene3dLibrary> {\n this.libPromise ??= this.options.library().then(\n (lib) => (this.lib = lib),\n (err) => {\n this.libPromise = undefined;\n throw err;\n },\n );\n return this.libPromise;\n }\n\n // ---------------------------------------------------------------- map events\n\n private onStyleLoad = () => {\n if (!this.map) return;\n this.pitch = null; // a new style, or a diffed one, starts with its own global state\n // MapLibre 6 fires style.load after a diffed setStyle too; the Style object stays the same then.\n if (styleOf(this.map) === this.loadedStyle) {\n this.syncWithStyle();\n return;\n }\n this.loadedStyle = styleOf(this.map);\n this.teardown(false); // whatever of the old scene a style diff left behind\n this.refresh();\n };\n\n private onStyleData = () => this.syncWithStyle();\n\n // A diffed setStyle (setStyle without { diff: false }) keeps the Style object. It drops our source\n // and native layers as \"not in the new style\" but keeps the custom layers (MapLibre never serializes\n // them), and it may bring another scene or none. Same scene: put the source and native layers back\n // and keep the 3D layers. Another scene: rebuild.\n private syncWithStyle() {\n if (this.building || !this.map || !this.styleReady()) return;\n const map = this.map;\n const next = this.currentScene();\n if (next !== this.sceneRef) {\n if (sceneKeyOf(next) !== this.sceneKey) {\n this.refresh();\n return;\n }\n this.sceneRef = next; // the same scene in a new object\n }\n if (!this.scene) return;\n if (this.custom.some((l) => !map.getLayer(l.id))) this.refresh();\n else if (this.native.some((id) => !map.getLayer(id)) || !map.getSource(this.sourceId())) this.restoreNative();\n else this.syncPitch();\n }\n\n // The 3D layers take the terrain as it is when they are added.\n private onTerrain = () => {\n if (!this.map || !this.styleReady() || !this.custom.length || !this.scene) return;\n this.removeCustom();\n this.addCustom(this.scene, this.generation);\n };\n\n private onZoom = () => {\n if (!this.map || this.lib || !this.scene || this.map.getZoom() < this.options.minzoom) return;\n this.loadCustom(this.scene, this.generation);\n };\n\n /** `[\"global-state\", \"pitch\"]` for the scene's opacity fades. Whole degrees: each change is a style update. */\n private syncPitch = () => {\n if (!this.map || !this.styleReady()) return;\n const pitch = Math.round(this.map.getPitch());\n if (pitch === this.pitch) return;\n this.pitch = pitch;\n this.map.setGlobalStateProperty(\"pitch\", pitch);\n };\n\n // ---------------------------------------------------------------- building\n\n private styleReady(): boolean {\n return !!this.map && !!this.loadedStyle && styleOf(this.map) === this.loadedStyle;\n }\n\n private currentScene(): Scene3dManifest | null {\n if (!this.enabled) return null;\n if (this.override !== undefined) return this.override;\n // Straight from the stylesheet MapLibre keeps: this runs on every styledata (every whole degree of\n // tilt, see syncPitch), and getStyle() clones every layer. getStyle() only as a fallback.\n const sheet = (this.map as unknown as { style?: { stylesheet?: { metadata?: unknown } } } | undefined)?.style?.stylesheet;\n const metadata = (sheet ? sheet.metadata : this.map?.getStyle()?.metadata) as Record<string, unknown> | undefined;\n return (metadata?.[SCENE3D_METADATA_KEY] as Scene3dManifest | undefined) ?? null;\n }\n\n private refresh() {\n const map = this.map;\n if (!map || !this.styleReady()) return;\n this.building = true;\n try {\n this.teardown(true);\n const generation = ++this.generation;\n let scene = this.currentScene();\n this.sceneRef = scene;\n this.sceneKey = sceneKeyOf(scene);\n if (scene && scene.version !== 1) {\n this.warnOnce(`version-${String(scene.version)}`, `Scene3dControl: unsupported scene version ${String(scene.version)}`);\n scene = null;\n }\n this.scene = scene;\n if (scene) {\n this.syncPitch();\n if (scene.lod1 || scene.fill3d) this.hideOnceBuildingsLoad(generation);\n this.addNative(scene);\n if (this.lib) this.addCustom(scene, generation);\n else if (map.getZoom() >= this.options.minzoom) this.loadCustom(scene, generation);\n }\n } finally {\n this.building = false;\n }\n this.fire(\"scene.change\", { scene: this.scene });\n }\n\n private sourceId() {\n return `${this.options.idPrefix}buildings`;\n }\n\n /** The id of the style's first symbol layer: the scene goes right below it. */\n private labelsAnchor(): string | undefined {\n return this.map?.getStyle().layers.find((l) => l.type === \"symbol\" && !l.id.startsWith(this.options.idPrefix))?.id;\n }\n\n private beforeFor(position: Scene3dPosition | undefined, anchor: string | undefined) {\n return position === \"top\" ? undefined : anchor;\n }\n\n /** The buildings source and the native layers, before `anchor` (default: under the labels). */\n private addNative(scene: Scene3dManifest, anchor = this.labelsAnchor()) {\n const map = this.map!;\n const source = this.sourceId();\n if (!map.getSource(source)) map.addSource(source, { type: \"vector\", url: this.withKey(scene.source) });\n const p = this.options.idPrefix;\n if (scene.lod1) {\n const { position, ...lod1 } = scene.lod1;\n map.addLayer({ id: `${p}lod1`, type: \"fill-extrusion\", source, \"source-layer\": \"buildings2d\", ...lod1 } as never, this.beforeFor(position, anchor));\n this.native.push(`${p}lod1`);\n } else if (scene.fill3d) {\n // The Fill3DLayer reads tiles MapLibre only loads for a source a style layer uses.\n map.addLayer(\n { id: `${p}consumer`, type: \"fill\", source, \"source-layer\": \"buildings2d\", filter: [\"boolean\", false], paint: { \"fill-opacity\": 0 } },\n this.beforeFor(scene.fill3d.position, anchor),\n );\n this.native.push(`${p}consumer`);\n }\n }\n\n /** After a diffed setStyle with the same scene: put back the source and native layers, keep the 3D layers. */\n private restoreNative() {\n const map = this.map!;\n const scene = this.scene!;\n this.building = true;\n try {\n for (const id of this.native) if (map.getLayer(id)) map.removeLayer(id);\n this.native = [];\n // The new style set its own visibility on the layers we hide; remember that one.\n this.hidden.clear();\n // Under the 3D layers again, as in a full build.\n this.addNative(scene, this.custom.find((l) => !this.topIds.has(l.id))?.id ?? this.labelsAnchor());\n if (scene.lod1 || scene.fill3d) {\n if (this.sourceOk) this.hideStyleLayers();\n else {\n this.stopWaiting?.();\n this.hideOnceBuildingsLoad(this.generation);\n }\n }\n this.pitch = null;\n this.syncPitch();\n } finally {\n this.building = false;\n }\n }\n\n private loadCustom(scene: Scene3dManifest, generation: number) {\n this.loadLibrary().then(\n () => {\n if (generation === this.generation && this.scene === scene && !this.custom.length) this.addCustom(scene, generation);\n },\n (err) => console.error(\"Scene3dControl: could not load @maptoolkit/maplibre-3d-layers\", err),\n );\n }\n\n private addCustom(scene: Scene3dManifest, generation: number) {\n const map = this.map;\n const lib = this.lib;\n if (!map || !lib || generation !== this.generation || !this.styleReady()) return;\n const anchor = this.labelsAnchor();\n const p = this.options.idPrefix;\n const add = (layer: CustomLayerInterface, position: Scene3dPosition | undefined) => {\n map.addLayer(layer, this.beforeFor(position, anchor));\n this.custom.push(layer);\n if (position === \"top\") this.topIds.add(layer.id);\n };\n this.building = true;\n try {\n if (scene.fill3d) {\n const { position, ...fill3d } = scene.fill3d;\n add(new lib.Fill3DLayer({ id: `${p}fill3d`, source: this.sourceId(), \"source-layer\": \"buildings3d\", ...fill3d }), position);\n }\n const library = scene.models ?? {};\n for (const entry of scene.gltf ?? []) {\n const { id, position, models: ids, ...options } = entry;\n if (!map.getSource(options.source)) {\n this.warnOnce(`source-${options.source}`, `Scene3dControl: the style has no source \"${options.source}\", layer \"${id}\" left out`);\n continue;\n }\n const picked = ids ?? Object.keys(library);\n const models = Object.fromEntries(picked.filter((m) => library[m]).map((m) => [m, this.modelUrl(library[m])]));\n if (!Object.keys(models).length) continue;\n add(new lib.GltfLayer({ id: `${p}${id}`, models, ...options }), position);\n }\n } finally {\n this.building = false;\n }\n }\n\n private removeCustom() {\n const map = this.map;\n for (const layer of this.custom) {\n if (map?.getLayer(layer.id)) map.removeLayer(layer.id);\n // A replaced style never calls onRemove; without it the layer keeps listening to the map.\n else if (map) layer.onRemove?.(map, undefined as unknown as WebGL2RenderingContext);\n }\n this.custom = [];\n this.topIds.clear();\n }\n\n /** Remove everything the control added; `restore` puts hidden style layers back. */\n private teardown(restore: boolean) {\n const map = this.map;\n this.stopWaiting?.();\n this.building = true;\n try {\n this.removeCustom();\n if (map) {\n for (const id of this.native) if (map.getLayer(id)) map.removeLayer(id);\n if (map.getSource(this.sourceId()) && this.styleReady()) map.removeSource(this.sourceId());\n if (restore && this.styleReady()) {\n for (const [id, visibility] of this.hidden) if (map.getLayer(id)) map.setLayoutProperty(id, \"visibility\", visibility);\n }\n }\n this.native = [];\n this.hidden.clear();\n this.scene = null;\n this.sourceOk = false;\n } finally {\n this.building = false;\n }\n }\n\n /**\n * Hide the style's own 3D buildings (`hideLayers`) only once the scene's buildings source has\n * loaded. Without a working API key it answers 403, and the style keeps its buildings.\n */\n private hideOnceBuildingsLoad(generation: number) {\n const map = this.map!;\n const id = this.sourceId();\n const onData = (e: MapSourceDataEvent) => {\n // removeSource fires a metadata event too; the source is gone by then.\n if (e.sourceId !== id || e.sourceDataType !== \"metadata\" || !map.getSource(id)) return;\n this.stopWaiting?.();\n if (generation !== this.generation || !this.styleReady()) return;\n this.sourceOk = true;\n this.hideStyleLayers();\n };\n map.on(\"sourcedata\", onData);\n this.stopWaiting = () => {\n map.off(\"sourcedata\", onData);\n this.stopWaiting = undefined;\n };\n }\n\n private hideStyleLayers() {\n const map = this.map!;\n for (const id of this.options.hideLayers) {\n if (!map.getLayer(id)) continue;\n this.hidden.set(id, (map.getLayoutProperty(id, \"visibility\") as \"visible\" | \"none\" | undefined) ?? \"visible\");\n map.setLayoutProperty(id, \"visibility\", \"none\");\n }\n }\n\n private withKey(url: string): string {\n if (!this.options.apiKey) return url;\n const u = new URL(url, document.baseURI);\n if (!u.searchParams.has(\"api_key\")) u.searchParams.set(\"api_key\", this.options.apiKey);\n return u.href;\n }\n\n private modelUrl(url: string): string {\n return new URL(url, this.options.modelBase ?? document.baseURI).href;\n }\n\n private showState() {\n this.button?.setAttribute(\"aria-pressed\", String(this.enabled));\n }\n\n private warnOnce(key: string, message: string) {\n if (this.warned.has(key)) return;\n this.warned.add(key);\n console.warn(message);\n }\n}\n"],"mappings":";;AAIA,IAAaA,IAAuB,sBAuF9BC,IAA6C;CACjD,SAAS;CACT,QAAQ;CACR,SAAS;CACT,YAAY,CAAC,eAAe,0BAA0B;CACtD,UAAU;AACZ,GAEMC,IACJ,mNAIIC,KAAW,MAAsBC,EAA2C,OAE5EC,KAAc,MAAmCC,IAAQ,KAAK,UAAUA,CAAK,IAAI,MAW1EC,IAAb,cAAoCC,EAAqD;CACvF;CAEA;CACA;CACA;CACA;CAEA;CACA,QAAwC;CACxC;CACA;CACA,SAAyC,CAAC;CAC1C,SAA2B,CAAC;CAC5B,yBAAiB,IAAI,IAAgC;CACrD,cAAmC,KAAA;CACnC,QAA+B;CAC/B,WAAmB;CACnB,aAAqB;CACrB,yBAAiB,IAAI,IAAY;CAEjC;CAEA,WAA2C;CAC3C,WAAkC;CAElC,WAAmB;CAEnB,yBAAiB,IAAI,IAAY;CAEjC,YAAY,IAAiC,CAAC,GAAG;EAC/C,MAAM;EACN,IAAM,EAAE,UAAO,GAAGC,MAASC;EAO3B,AANA,KAAK,UAAU;GACb,GAAGT;GACH,eAAe,OAAO;GACtB,GAAG,OAAO,YAAY,OAAO,QAAQQ,CAAI,CAAC,CAAC,QAAQ,GAAGE,OAAOA,MAAM,KAAA,CAAS,CAAC;EAC/E,GACA,KAAK,UAAU,KAAK,QAAQ,SACxBL,MAAU,KAAA,KAAW,KAAU,SAASA,CAAK;CACnD;CAEA,qBAAsC;EACpC,OAAO;CACT;CAEA,MAAM,GAA+B;EACnC,KAAK,MAAMF;EACX,IAAMQ,IAAY,SAAS,cAAc,KAAK;EAE9C,IADA,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,cAAc,KAAA;EACrB;CACF;CAEA,kBAA0B;EACxB,IAAMpC,IAAM,KAAK;EACjB,KAAK,IAAMgB,KAAM,KAAK,QAAQ,YAC5B,AAAKhB,EAAI,SAASgB,CAAE,MACpB,KAAK,OAAO,IAAIA,GAAKhB,EAAI,kBAAkBgB,GAAI,YAAY,KAAwC,SAAS,GAC5GhB,EAAI,kBAAkBgB,GAAI,cAAc,MAAM;CAElD;CAEA,QAAgB,GAAqB;EACnC,IAAI,CAAC,KAAK,QAAQ,QAAQ,OAAOsB;EACjC,IAAMC,IAAI,IAAI,IAAID,GAAK,SAAS,OAAO;EAEvC,OADKC,EAAE,aAAa,IAAI,SAAS,KAAGA,EAAE,aAAa,IAAI,WAAW,KAAK,QAAQ,MAAM,GAC9EA,EAAE;CACX;CAEA,SAAiB,GAAqB;EACpC,OAAO,IAAI,IAAID,GAAK,KAAK,QAAQ,aAAa,SAAS,OAAO,CAAC,CAAC;CAClE;CAEA,YAAoB;EAClB,KAAK,QAAQ,aAAa,gBAAgB,OAAO,KAAK,OAAO,CAAC;CAChE;CAEA,SAAiB,GAAa,GAAiB;EAC7C,AAAI,KAAK,OAAO,IAAIE,CAAG,MACvB,KAAK,OAAO,IAAIA,CAAG,GACnB,QAAQ,KAAKC,CAAO;CACtB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maptoolkit/maplibre-scene3d-control",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A MapLibre GL JS control plugin that adds the 3D scene of a Maptoolkit style: 3D buildings and glTF vegetation.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/maptoolkit/maplibre-scene3d-control.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/maptoolkit/maplibre-scene3d-control#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/maptoolkit/maplibre-scene3d-control/issues"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"module": "./dist/maplibre-scene3d-control.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/maplibre-scene3d-control.js"
|
|
20
|
+
},
|
|
21
|
+
"./style.css": "./dist/maplibre-scene3d-control.css"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"sideEffects": [
|
|
30
|
+
"*.css"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"dev": "vite --config demo/vite.config.mts",
|
|
34
|
+
"build": "vite build",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"test:watch": "vitest",
|
|
37
|
+
"lint": "eslint .",
|
|
38
|
+
"format": "prettier --write .",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"changeset": "changeset",
|
|
41
|
+
"version": "changeset version",
|
|
42
|
+
"release": "npm run build && changeset publish"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@maptoolkit/maplibre-3d-layers": ">=0.5.1",
|
|
46
|
+
"maplibre-gl": ">=6.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@changesets/cli": "^3.0.3",
|
|
50
|
+
"@eslint/js": "^10.0.1",
|
|
51
|
+
"@maptoolkit/maplibre-3d-layers": "^0.5.1",
|
|
52
|
+
"@types/node": "^26.5.1",
|
|
53
|
+
"eslint": "^10.10.0",
|
|
54
|
+
"eslint-config-prettier": "^10.1.8",
|
|
55
|
+
"jsdom": "^30.0.1",
|
|
56
|
+
"maplibre-gl": "^6.9.1",
|
|
57
|
+
"prettier": "^3.9.6",
|
|
58
|
+
"three": "^0.185.1",
|
|
59
|
+
"typescript": "^6.0.3",
|
|
60
|
+
"typescript-eslint": "^8.70.0",
|
|
61
|
+
"vite": "^8.3.0",
|
|
62
|
+
"vite-plugin-dts": "^5.1.0",
|
|
63
|
+
"vitest": "^5.0.1"
|
|
64
|
+
},
|
|
65
|
+
"keywords": [
|
|
66
|
+
"maplibre",
|
|
67
|
+
"maplibre-gl",
|
|
68
|
+
"map",
|
|
69
|
+
"plugin",
|
|
70
|
+
"control",
|
|
71
|
+
"3d",
|
|
72
|
+
"buildings",
|
|
73
|
+
"gltf"
|
|
74
|
+
],
|
|
75
|
+
"author": "",
|
|
76
|
+
"license": "BSD-3-Clause"
|
|
77
|
+
}
|