@maptoolkit/maplibre-scene3d-control 0.1.0 → 0.1.2
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
|
@@ -7,10 +7,10 @@ A [MapLibre GL JS](https://maplibre.org/maplibre-gl-js/docs/) control plugin tha
|
|
|
7
7
|
|
|
8
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
9
|
|
|
10
|
-
- adds the buildings source with your API key,
|
|
10
|
+
- adds the buildings source with your API key (only for a scene with buildings),
|
|
11
11
|
- puts the layers under the style's labels,
|
|
12
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,
|
|
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
14
|
- loads the 3D library (with three.js) only once the map reaches zoom 12.
|
|
15
15
|
|
|
16
16
|
## Install
|
|
@@ -78,13 +78,13 @@ The package is ESM-only. With an [import map](https://developer.mozilla.org/en-U
|
|
|
78
78
|
|
|
79
79
|
## Methods
|
|
80
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. |
|
|
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.
|
|
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
88
|
|
|
89
89
|
## Events
|
|
90
90
|
|
|
@@ -109,6 +109,8 @@ All values are plain MapLibre or maplibre-3d-layers options. Maptoolkit styles g
|
|
|
109
109
|
|
|
110
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
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
|
+
|
|
112
114
|
## Requirements
|
|
113
115
|
|
|
114
116
|
- MapLibre GL JS ≥ 6, `@maptoolkit/maplibre-3d-layers` ≥ 0.5.1 and three.js ≥ 0.160 (peer dependencies of the 3D library).
|
package/dist/Scene3dControl.d.ts
CHANGED
|
@@ -118,13 +118,25 @@ export declare class Scene3dControl extends Evented<Scene3dControlEventType> imp
|
|
|
118
118
|
private warned;
|
|
119
119
|
/** Stops waiting for the buildings source (see hideOnceBuildingsLoad). */
|
|
120
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
|
+
/** The terrain the 3D layers were built with (source and exaggeration), see onTerrain. */
|
|
129
|
+
private terrainKey;
|
|
121
130
|
constructor(options?: Scene3dControlOptions);
|
|
122
131
|
getDefaultPosition(): ControlPosition;
|
|
123
132
|
onAdd(map: MaplibreMap): HTMLElement;
|
|
124
133
|
onRemove(): void;
|
|
125
134
|
/**
|
|
126
135
|
* Replace the style's scene: a manifest, the URL of one, `null` for none, or `undefined` to go back
|
|
127
|
-
* to the style's own scene.
|
|
136
|
+
* to the style's own scene. The same scene again keeps the layers.
|
|
137
|
+
*
|
|
138
|
+
* MapLibre ignores a diffed `setStyle` that changes nothing but the metadata, so a scene that changes
|
|
139
|
+
* on its own never reaches the control that way; pass it here (or use `setStyle` with `diff: false`).
|
|
128
140
|
*/
|
|
129
141
|
setScene(scene: Scene3dManifest | string | null | undefined): Promise<void>;
|
|
130
142
|
/** The scene shown now, or null. */
|
|
@@ -139,6 +151,7 @@ export declare class Scene3dControl extends Evented<Scene3dControlEventType> imp
|
|
|
139
151
|
loadLibrary(): Promise<Scene3dLibrary>;
|
|
140
152
|
private onStyleLoad;
|
|
141
153
|
private onStyleData;
|
|
154
|
+
private syncWithStyle;
|
|
142
155
|
private onTerrain;
|
|
143
156
|
private onZoom;
|
|
144
157
|
/** `["global-state", "pitch"]` for the scene's opacity fades. Whole degrees: each change is a style update. */
|
|
@@ -150,7 +163,10 @@ export declare class Scene3dControl extends Evented<Scene3dControlEventType> imp
|
|
|
150
163
|
/** The id of the style's first symbol layer: the scene goes right below it. */
|
|
151
164
|
private labelsAnchor;
|
|
152
165
|
private beforeFor;
|
|
166
|
+
/** The buildings source and the native layers, before `anchor` (default: under the labels). */
|
|
153
167
|
private addNative;
|
|
168
|
+
/** After a diffed setStyle with the same scene: put back the source and native layers, keep the 3D layers. */
|
|
169
|
+
private restoreNative;
|
|
154
170
|
private loadCustom;
|
|
155
171
|
private addCustom;
|
|
156
172
|
private removeCustom;
|
|
@@ -6,7 +6,7 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
6
6
|
minzoom: 12,
|
|
7
7
|
hideLayers: ["building_3d", "building_3d_multicolored"],
|
|
8
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 = class extends e {
|
|
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 = (e) => e ? `${e.source}|${e.exaggeration ?? 1}` : null, s = (e) => !!(e.lod1 || e.fill3d), c = class extends e {
|
|
10
10
|
options;
|
|
11
11
|
map;
|
|
12
12
|
container;
|
|
@@ -25,6 +25,11 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
25
25
|
generation = 0;
|
|
26
26
|
warned = /* @__PURE__ */ new Set();
|
|
27
27
|
stopWaiting;
|
|
28
|
+
sceneRef = null;
|
|
29
|
+
sceneKey = null;
|
|
30
|
+
sourceOk = !1;
|
|
31
|
+
topIds = /* @__PURE__ */ new Set();
|
|
32
|
+
terrainKey = null;
|
|
28
33
|
constructor(e = {}) {
|
|
29
34
|
super();
|
|
30
35
|
let { scene: t, ...r } = e;
|
|
@@ -56,7 +61,7 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
56
61
|
if (!t.ok) throw Error(`Scene ${e}: HTTP ${t.status}`);
|
|
57
62
|
e = await t.json();
|
|
58
63
|
}
|
|
59
|
-
this.override = e, this.refresh();
|
|
64
|
+
(e === void 0 || this.override === void 0 || a(e) !== a(this.override)) && (this.override = e, this.refresh());
|
|
60
65
|
}
|
|
61
66
|
getScene() {
|
|
62
67
|
return this.scene;
|
|
@@ -79,13 +84,23 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
79
84
|
}), this.libPromise;
|
|
80
85
|
}
|
|
81
86
|
onStyleLoad = () => {
|
|
82
|
-
this.map && (this.
|
|
83
|
-
};
|
|
84
|
-
onStyleData = () => {
|
|
85
|
-
!this.building && this.map && this.styleReady() && this.scene && [...this.native, ...this.custom.map((e) => e.id)].some((e) => !this.map.getLayer(e)) && this.refresh();
|
|
87
|
+
this.map && (this.pitch = null, i(this.map) === this.loadedStyle ? this.syncWithStyle() : (this.loadedStyle = i(this.map), this.teardown(!1), this.refresh()));
|
|
86
88
|
};
|
|
89
|
+
onStyleData = () => this.syncWithStyle();
|
|
90
|
+
syncWithStyle() {
|
|
91
|
+
if (this.building || !this.map || !this.styleReady()) return;
|
|
92
|
+
let e = this.map, t = this.currentScene();
|
|
93
|
+
if (t !== this.sceneRef) {
|
|
94
|
+
if (a(t) !== this.sceneKey) {
|
|
95
|
+
this.refresh();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
this.sceneRef = t;
|
|
99
|
+
}
|
|
100
|
+
this.scene && (this.custom.some((t) => !e.getLayer(t.id)) ? this.refresh() : this.native.some((t) => !e.getLayer(t)) || s(this.scene) && !e.getSource(this.sourceId()) ? this.restoreNative() : this.syncPitch());
|
|
101
|
+
}
|
|
87
102
|
onTerrain = () => {
|
|
88
|
-
this.map && this.styleReady() && this.custom.length && this.scene && (this.removeCustom(), this.addCustom(this.scene, this.generation));
|
|
103
|
+
this.map && this.styleReady() && this.custom.length && this.scene && o(this.map.getTerrain()) !== this.terrainKey && (this.removeCustom(), this.addCustom(this.scene, this.generation));
|
|
89
104
|
};
|
|
90
105
|
onZoom = () => {
|
|
91
106
|
!this.map || this.lib || !this.scene || this.map.getZoom() < this.options.minzoom || this.loadCustom(this.scene, this.generation);
|
|
@@ -99,7 +114,10 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
99
114
|
return !!this.map && !!this.loadedStyle && i(this.map) === this.loadedStyle;
|
|
100
115
|
}
|
|
101
116
|
currentScene() {
|
|
102
|
-
|
|
117
|
+
if (!this.enabled) return null;
|
|
118
|
+
if (this.override !== void 0) return this.override;
|
|
119
|
+
let e = this.map?.style?.stylesheet;
|
|
120
|
+
return (e ? e.metadata : this.map?.getStyle()?.metadata)?.["maptoolkit:scene3d"] ?? null;
|
|
103
121
|
}
|
|
104
122
|
refresh() {
|
|
105
123
|
let e = this.map;
|
|
@@ -108,7 +126,7 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
108
126
|
try {
|
|
109
127
|
this.teardown(!0);
|
|
110
128
|
let t = ++this.generation, n = this.currentScene();
|
|
111
|
-
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
|
|
129
|
+
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(), s(n) && this.hideOnceBuildingsLoad(t), this.addNative(n), this.lib ? this.addCustom(n, t) : e.getZoom() >= this.options.minzoom && this.loadCustom(n, t));
|
|
112
130
|
} finally {
|
|
113
131
|
this.building = !1;
|
|
114
132
|
}
|
|
@@ -124,30 +142,41 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
124
142
|
beforeFor(e, t) {
|
|
125
143
|
return e === "top" ? void 0 : t;
|
|
126
144
|
}
|
|
127
|
-
addNative(e) {
|
|
128
|
-
let
|
|
129
|
-
|
|
145
|
+
addNative(e, t = this.labelsAnchor()) {
|
|
146
|
+
let n = this.map, r = this.sourceId();
|
|
147
|
+
if (!s(e)) return;
|
|
148
|
+
n.getSource(r) || n.addSource(r, {
|
|
130
149
|
type: "vector",
|
|
131
150
|
url: this.withKey(e.source)
|
|
132
151
|
});
|
|
133
|
-
let
|
|
152
|
+
let i = this.options.idPrefix;
|
|
134
153
|
if (e.lod1) {
|
|
135
154
|
let { position: a, ...o } = e.lod1;
|
|
136
|
-
|
|
155
|
+
n.addLayer({
|
|
137
156
|
id: `${i}lod1`,
|
|
138
157
|
type: "fill-extrusion",
|
|
139
|
-
source:
|
|
158
|
+
source: r,
|
|
140
159
|
"source-layer": "buildings2d",
|
|
141
160
|
...o
|
|
142
|
-
}, this.beforeFor(a,
|
|
143
|
-
} else e.fill3d && (
|
|
161
|
+
}, this.beforeFor(a, t)), this.native.push(`${i}lod1`);
|
|
162
|
+
} else e.fill3d && (n.addLayer({
|
|
144
163
|
id: `${i}consumer`,
|
|
145
164
|
type: "fill",
|
|
146
|
-
source:
|
|
165
|
+
source: r,
|
|
147
166
|
"source-layer": "buildings2d",
|
|
148
167
|
filter: ["boolean", !1],
|
|
149
168
|
paint: { "fill-opacity": 0 }
|
|
150
|
-
}, this.beforeFor(e.fill3d.position,
|
|
169
|
+
}, this.beforeFor(e.fill3d.position, t)), this.native.push(`${i}consumer`));
|
|
170
|
+
}
|
|
171
|
+
restoreNative() {
|
|
172
|
+
let e = this.map, t = this.scene;
|
|
173
|
+
this.building = !0;
|
|
174
|
+
try {
|
|
175
|
+
for (let t of this.native) e.getLayer(t) && e.removeLayer(t);
|
|
176
|
+
this.native = [], this.hidden.clear(), this.addNative(t, this.custom.find((e) => !this.topIds.has(e.id))?.id ?? this.labelsAnchor()), s(t) && (this.sourceOk ? this.hideStyleLayers() : (this.stopWaiting?.(), this.hideOnceBuildingsLoad(this.generation))), this.pitch = null, this.syncPitch();
|
|
177
|
+
} finally {
|
|
178
|
+
this.building = !1;
|
|
179
|
+
}
|
|
151
180
|
}
|
|
152
181
|
loadCustom(e, t) {
|
|
153
182
|
this.loadLibrary().then(() => {
|
|
@@ -157,14 +186,16 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
157
186
|
addCustom(e, t) {
|
|
158
187
|
let n = this.map, r = this.lib;
|
|
159
188
|
if (!n || !r || t !== this.generation || !this.styleReady()) return;
|
|
160
|
-
let i = this.labelsAnchor(), a = this.options.idPrefix
|
|
161
|
-
|
|
189
|
+
let i = this.labelsAnchor(), a = this.options.idPrefix;
|
|
190
|
+
this.terrainKey = o(n.getTerrain());
|
|
191
|
+
let s = (e, t) => {
|
|
192
|
+
n.addLayer(e, this.beforeFor(t, i)), this.custom.push(e), t === "top" && this.topIds.add(e.id);
|
|
162
193
|
};
|
|
163
194
|
this.building = !0;
|
|
164
195
|
try {
|
|
165
196
|
if (e.fill3d) {
|
|
166
197
|
let { position: t, ...n } = e.fill3d;
|
|
167
|
-
|
|
198
|
+
s(new r.Fill3DLayer({
|
|
168
199
|
id: `${a}fill3d`,
|
|
169
200
|
source: this.sourceId(),
|
|
170
201
|
"source-layer": "buildings3d",
|
|
@@ -173,17 +204,17 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
173
204
|
}
|
|
174
205
|
let t = e.models ?? {};
|
|
175
206
|
for (let i of e.gltf ?? []) {
|
|
176
|
-
let { id: e, position:
|
|
207
|
+
let { id: e, position: o, models: c, ...l } = i;
|
|
177
208
|
if (!n.getSource(l.source)) {
|
|
178
209
|
this.warnOnce(`source-${l.source}`, `Scene3dControl: the style has no source "${l.source}", layer "${e}" left out`);
|
|
179
210
|
continue;
|
|
180
211
|
}
|
|
181
212
|
let u = c ?? Object.keys(t), d = Object.fromEntries(u.filter((e) => t[e]).map((e) => [e, this.modelUrl(t[e])]));
|
|
182
|
-
Object.keys(d).length &&
|
|
213
|
+
Object.keys(d).length && s(new r.GltfLayer({
|
|
183
214
|
id: `${a}${e}`,
|
|
184
215
|
models: d,
|
|
185
216
|
...l
|
|
186
|
-
}),
|
|
217
|
+
}), o);
|
|
187
218
|
}
|
|
188
219
|
} finally {
|
|
189
220
|
this.building = !1;
|
|
@@ -192,7 +223,7 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
192
223
|
removeCustom() {
|
|
193
224
|
let e = this.map;
|
|
194
225
|
for (let t of this.custom) e?.getLayer(t.id) ? e.removeLayer(t.id) : e && t.onRemove?.(e, void 0);
|
|
195
|
-
this.custom = [];
|
|
226
|
+
this.custom = [], this.topIds.clear();
|
|
196
227
|
}
|
|
197
228
|
teardown(e) {
|
|
198
229
|
let t = this.map;
|
|
@@ -202,14 +233,14 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
202
233
|
for (let e of this.native) t.getLayer(e) && t.removeLayer(e);
|
|
203
234
|
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);
|
|
204
235
|
}
|
|
205
|
-
this.native = [], this.hidden.clear(), this.scene = null;
|
|
236
|
+
this.native = [], this.hidden.clear(), this.scene = null, this.sourceOk = !1;
|
|
206
237
|
} finally {
|
|
207
238
|
this.building = !1;
|
|
208
239
|
}
|
|
209
240
|
}
|
|
210
241
|
hideOnceBuildingsLoad(e) {
|
|
211
242
|
let t = this.map, n = this.sourceId(), r = (r) => {
|
|
212
|
-
r.sourceId === n && r.sourceDataType === "metadata" && t.getSource(n) && (this.stopWaiting?.(), e === this.generation && this.styleReady() && this.hideStyleLayers());
|
|
243
|
+
r.sourceId === n && r.sourceDataType === "metadata" && t.getSource(n) && (this.stopWaiting?.(), e === this.generation && this.styleReady() && (this.sourceOk = !0, this.hideStyleLayers()));
|
|
213
244
|
};
|
|
214
245
|
t.on("sourcedata", r), this.stopWaiting = () => {
|
|
215
246
|
t.off("sourcedata", r), this.stopWaiting = void 0;
|
|
@@ -234,6 +265,6 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
234
265
|
this.warned.has(e) || (this.warned.add(e), console.warn(t));
|
|
235
266
|
}
|
|
236
267
|
};
|
|
237
|
-
export { t as SCENE3D_METADATA_KEY,
|
|
268
|
+
export { t as SCENE3D_METADATA_KEY, c as Scene3dControl };
|
|
238
269
|
|
|
239
270
|
//# sourceMappingURL=maplibre-scene3d-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maplibre-scene3d-control.js","names":["SCENE3D_METADATA_KEY","DEFAULTS","CUBE_ICON","styleOf","map","Scene3dControl","Evented","rest","options","v","scene","container","button","response","enabled","lib","err","l","id","pitch","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\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\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.\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 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.loadedStyle = styleOf(this.map);\n this.pitch = null; // a new style starts with its own global state\n this.teardown(false); // whatever of the old scene a style diff left behind\n this.refresh();\n };\n\n // A style switch with diff (setStyle without { diff: false }) keeps the Style object, fires no\n // style.load and drops our layers as \"not in the new style\": rebuild from the new style.\n private onStyleData = () => {\n if (this.building || !this.map || !this.styleReady() || !this.scene) return;\n const ids = [...this.native, ...this.custom.map((l) => l.id)];\n if (ids.some((id) => !this.map!.getLayer(id))) this.refresh();\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 const scene = this.map?.getStyle()?.metadata as Record<string, unknown> | undefined;\n return (scene?.[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 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 private addNative(scene: Scene3dManifest) {\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 anchor = this.labelsAnchor();\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 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 };\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 }\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 } 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()) 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,OAWrEC,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,YAAY,IAAiC,CAAC,GAAG;EAC/C,MAAM;EACN,IAAM,EAAE,UAAO,GAAGC,MAASC;EAO3B,AANA,KAAK,UAAU;GACb,GAAGP;GACH,eAAe,OAAO;GACtB,GAAG,OAAO,YAAY,OAAO,QAAQM,CAAI,CAAC,CAAC,QAAQ,GAAGE,OAAOA,MAAM,KAAA,CAAS,CAAC;EAC/E,GACA,KAAK,UAAU,KAAK,QAAQ,SACxBC,MAAU,KAAA,KAAW,KAAU,SAASA,CAAK;CACnD;CAEA,qBAAsC;EACpC,OAAO;CACT;CAEA,MAAM,GAA+B;EACnC,KAAK,MAAMN;EACX,IAAMO,IAAY,SAAS,cAAc,KAAK;EAE9C,IADA,EAAU,YAAY,kEAClB,KAAK,QAAQ,QAAQ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SAASc,CAAE,MACpB,KAAK,OAAO,IAAIA,GAAKd,EAAI,kBAAkBc,GAAI,YAAY,KAAwC,SAAS,GAC5Gd,EAAI,kBAAkBc,GAAI,cAAc,MAAM;CAElD;CAEA,QAAgB,GAAqB;EACnC,IAAI,CAAC,KAAK,QAAQ,QAAQ,OAAOqB;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"}
|
|
1
|
+
{"version":3,"file":"maplibre-scene3d-control.js","names":["SCENE3D_METADATA_KEY","DEFAULTS","CUBE_ICON","styleOf","map","sceneKeyOf","scene","terrainKeyOf","terrain","hasBuildings","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/** Source and exaggeration of a terrain, to tell a real change from a repeated setTerrain. */\nconst terrainKeyOf = (terrain: { source: string; exaggeration?: number } | null | undefined) =>\n terrain ? `${terrain.source}|${terrain.exaggeration ?? 1}` : null;\n/** Whether a scene draws buildings, i.e. needs its buildings source. */\nconst hasBuildings = (scene: Scene3dManifest) => !!(scene.lod1 || scene.fill3d);\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 /** The terrain the 3D layers were built with (source and exaggeration), see onTerrain. */\n private terrainKey: string | null = null;\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)) || (hasBuildings(this.scene) && !map.getSource(this.sourceId()))) this.restoreNative();\n else this.syncPitch();\n }\n\n // The 3D layers take the terrain source and exaggeration as they are when they are added (heights\n // are sampled from the current terrain each pass). MapLibre fires `terrain` on every setTerrain, also\n // with the same options; rebuilding then would restart model loading each time (an app re-applying\n // its terrain after every style update kept the models loading for good).\n private onTerrain = () => {\n if (!this.map || !this.styleReady() || !this.custom.length || !this.scene) return;\n if (terrainKeyOf(this.map.getTerrain()) === this.terrainKey) 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 (hasBuildings(scene)) 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 (!hasBuildings(scene)) return; // trees only: no buildings source to load (or to answer 403 without a key)\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 (hasBuildings(scene)) {\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 this.terrainKey = terrainKeyOf(map.getTerrain());\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,MAEjFC,KAAgB,MACpBC,IAAU,GAAGA,EAAQ,OAAO,GAAGA,EAAQ,gBAAgB,MAAM,MAEzDC,KAAgB,MAA2B,CAAC,EAAEH,EAAM,QAAQA,EAAM,SAW3DI,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;C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