@maptoolkit/maplibre-scene3d-control 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,11 +6,11 @@ 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 = (e) => e ? JSON.stringify(e) : null, o = (e) => e ? `${e.source}|${e.exaggeration ?? 1}` : null, s = (e) => !!(e.lod1 || e.fill3d), c = (e) => s(e) || !!e.landmarks, l = [
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.lod1 || e.fill3d), s = (e) => o(e) || !!e.landmarks, c = [
10
10
  "==",
11
11
  ["get", "source"],
12
12
  "landmark"
13
- ], u = class extends e {
13
+ ], l = class extends e {
14
14
  options;
15
15
  map;
16
16
  container;
@@ -33,7 +33,6 @@ var t = "maptoolkit:scene3d", n = {
33
33
  sceneKey = null;
34
34
  sourceOk = !1;
35
35
  customPosition = /* @__PURE__ */ new Map();
36
- terrainKey = null;
37
36
  constructor(e = {}) {
38
37
  super();
39
38
  let { scene: t, ...r } = e;
@@ -55,11 +54,11 @@ var t = "maptoolkit:scene3d", n = {
55
54
  } else t.classList.add("maplibre-scene3d-control-hidden");
56
55
  this.container = t;
57
56
  let n = e.getCanvas?.(), a = n?.getContext?.("webgl2") ?? n?.getContext?.("webgl");
58
- return a && a.getContextAttributes?.()?.antialias === !1 && this.warnOnce("antialias", "Scene3dControl: the map's WebGL context has no multisampling, so the 3D buildings and trees get pixelated edges. Create the map with canvasContextAttributes: { antialias: true }."), 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;
57
+ return a && a.getContextAttributes?.()?.antialias === !1 && this.warnOnce("antialias", "Scene3dControl: the map's WebGL context has no multisampling, so the 3D buildings and trees get pixelated edges. Create the map with canvasContextAttributes: { antialias: true }."), e.on("style.load", this.onStyleLoad), e.on("styledata", this.onStyleData), e.on("pitch", this.syncPitch), e.on("zoomend", this.onZoom), i(e)?._loaded && this.onStyleLoad(), t;
59
58
  }
60
59
  onRemove() {
61
60
  let e = this.map;
62
- 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);
61
+ e && (this.teardown(!0), e.off("style.load", this.onStyleLoad), e.off("styledata", this.onStyleData), 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);
63
62
  }
64
63
  async setScene(e) {
65
64
  if (typeof e == "string") {
@@ -103,11 +102,8 @@ var t = "maptoolkit:scene3d", n = {
103
102
  }
104
103
  this.sceneRef = t;
105
104
  }
106
- this.scene && (this.custom.some((t) => !e.getLayer(t.id)) ? this.refresh() : this.native.some((t) => !e.getLayer(t)) || c(this.scene) && !e.getSource(this.sourceId()) ? this.restoreNative() : this.syncPitch());
105
+ 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());
107
106
  }
108
- onTerrain = () => {
109
- this.map && this.styleReady() && this.custom.length && this.scene && o(this.map.getTerrain()) !== this.terrainKey && (this.removeCustom(), this.addCustom(this.scene, this.generation));
110
- };
111
107
  onZoom = () => {
112
108
  !this.map || this.lib || !this.scene || this.map.getZoom() < this.options.minzoom || this.loadCustom(this.scene, this.generation);
113
109
  };
@@ -132,7 +128,7 @@ var t = "maptoolkit:scene3d", n = {
132
128
  try {
133
129
  this.teardown(!0);
134
130
  let t = ++this.generation, n = this.currentScene();
135
- 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));
131
+ 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(), o(n) && this.hideOnceBuildingsLoad(t), this.addNative(n), this.lib ? this.addCustom(n, t) : e.getZoom() >= this.options.minzoom && this.loadCustom(n, t));
136
132
  } finally {
137
133
  this.building = !1;
138
134
  }
@@ -150,7 +146,7 @@ var t = "maptoolkit:scene3d", n = {
150
146
  }
151
147
  addNative(e, t = (e, t) => t) {
152
148
  let n = this.map, r = this.sourceId();
153
- if (!c(e)) return;
149
+ if (!s(e)) return;
154
150
  n.getSource(r) || n.addSource(r, {
155
151
  type: "vector",
156
152
  url: this.withKey(e.source)
@@ -179,7 +175,7 @@ var t = "maptoolkit:scene3d", n = {
179
175
  this.building = !0;
180
176
  try {
181
177
  for (let t of this.native) e.getLayer(t) && e.removeLayer(t);
182
- this.native = [], this.hidden.clear(), this.addNative(t, (e, t) => this.custom.find((t) => this.customPosition.get(t.id) === e)?.id ?? t), s(t) && (this.sourceOk ? this.hideStyleLayers() : (this.stopWaiting?.(), this.hideOnceBuildingsLoad(this.generation))), this.pitch = null, this.syncPitch();
178
+ this.native = [], this.hidden.clear(), this.addNative(t, (e, t) => this.custom.find((t) => this.customPosition.get(t.id) === e)?.id ?? t), o(t) && (this.sourceOk ? this.hideStyleLayers() : (this.stopWaiting?.(), this.hideOnceBuildingsLoad(this.generation))), this.pitch = null, this.syncPitch();
183
179
  } finally {
184
180
  this.building = !1;
185
181
  }
@@ -192,31 +188,29 @@ var t = "maptoolkit:scene3d", n = {
192
188
  addCustom(e, t) {
193
189
  let n = this.map, r = this.lib;
194
190
  if (!n || !r || t !== this.generation || !this.styleReady()) return;
195
- let i = this.labelsAnchor(), a = this.options.idPrefix;
196
- this.terrainKey = o(n.getTerrain());
197
- let s = (e, t) => {
191
+ let i = this.labelsAnchor(), a = this.options.idPrefix, o = (e, t) => {
198
192
  n.addLayer(e, this.beforeFor(t, i)), this.custom.push(e), this.customPosition.set(e.id, t ?? "below-labels");
199
193
  };
200
194
  this.building = !0;
201
195
  try {
202
- let t = e.landmarks ? e.landmarks.filter ?? l : void 0;
196
+ let t = e.landmarks ? e.landmarks.filter ?? c : void 0;
203
197
  if (e.fill3d) {
204
- let { position: n, ...i } = e.fill3d, o = t && [
198
+ let { position: n, ...i } = e.fill3d, s = t && [
205
199
  "all",
206
200
  ...i.filter ? [i.filter] : [],
207
201
  ["!", t]
208
202
  ];
209
- s(new r.Fill3DLayer({
203
+ o(new r.Fill3DLayer({
210
204
  id: `${a}fill3d`,
211
205
  source: this.sourceId(),
212
206
  "source-layer": "buildings3d",
213
207
  ...i,
214
- ...o ? { filter: o } : {}
208
+ ...s ? { filter: s } : {}
215
209
  }), n);
216
210
  }
217
211
  if (e.landmarks) {
218
212
  let { position: n, ...i } = e.landmarks;
219
- s(new r.Fill3DLayer({
213
+ o(new r.Fill3DLayer({
220
214
  id: `${a}landmarks`,
221
215
  source: this.sourceId(),
222
216
  "source-layer": "buildings3d",
@@ -226,17 +220,17 @@ var t = "maptoolkit:scene3d", n = {
226
220
  }
227
221
  let i = e.models ?? {};
228
222
  for (let t of e.gltf ?? []) {
229
- let { id: e, position: o, models: c, ...l } = t;
223
+ let { id: e, position: s, models: c, ...l } = t;
230
224
  if (!n.getSource(l.source)) {
231
225
  this.warnOnce(`source-${l.source}`, `Scene3dControl: the style has no source "${l.source}", layer "${e}" left out`);
232
226
  continue;
233
227
  }
234
228
  let u = c ?? Object.keys(i), d = Object.fromEntries(u.filter((e) => i[e]).map((e) => [e, this.modelUrl(i[e])]));
235
- Object.keys(d).length && s(new r.GltfLayer({
229
+ Object.keys(d).length && o(new r.GltfLayer({
236
230
  id: `${a}${e}`,
237
231
  models: d,
238
232
  ...l
239
- }), o);
233
+ }), s);
240
234
  }
241
235
  } finally {
242
236
  this.building = !1;
@@ -287,6 +281,6 @@ var t = "maptoolkit:scene3d", n = {
287
281
  this.warned.has(e) || (this.warned.add(e), console.warn(t));
288
282
  }
289
283
  };
290
- export { t as SCENE3D_METADATA_KEY, u as Scene3dControl };
284
+ export { t as SCENE3D_METADATA_KEY, l as Scene3dControl };
291
285
 
292
286
  //# 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","sceneKeyOf","scene","terrainKeyOf","terrain","hasBuildings","usesBuildingsSource","LANDMARKS_FILTER","Scene3dControl","Evented","rest","options","v","container","button","canvas","gl","response","enabled","lib","err","next","l","id","pitch","sheet","generation","position","anchor","before","source","p","place","lod1","add","layer","landmarksFilter","fill3d","filter","landmarks","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/**\n * Where a layer of the scene goes: under the style's labels (`\"below-labels\"`, the default: right below its first\n * symbol layer), on top of everything (`\"top\"`), or right below the style layer with that id. The position only\n * decides what draws over the 3D among symbol layers (labels, icons); fills and lines always end up under it. A\n * layer id the style lacks falls back to `\"below-labels\"`.\n */\nexport type Scene3dPosition = \"below-labels\" | \"top\" | (string & {});\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 /**\n * `Fill3DLayer` on the source layer `buildings3d`. With `extrusion` it also extrudes the 2D footprints of a source\n * layer of the same tiles (maplibre-3d-layers ≥ 0.6.0, experimental), so that they get its shading and fake ambient\n * occlusion; hide the same footprints in `lod1` where it does, e.g. by zoom.\n */\n fill3d?: {\n position?: Scene3dPosition;\n filter?: FilterSpecification;\n paint?: Record<string, Expression>;\n extrusion?: { \"source-layer\": string; filter?: FilterSpecification; height?: Expression; base?: Expression };\n };\n /**\n * The landmarks in the source layer `buildings3d`, as a `Fill3DLayer` of their own: with their own paint and their\n * own place among the style's layers. `filter` picks them (default `[\"==\", [\"get\", \"source\"], \"landmark\"]`), and\n * `fill3d` then leaves those features out.\n */\n landmarks?: { 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, in place of the style's own 3D buildings (`hideLayers`). */\nconst hasBuildings = (scene: Scene3dManifest) => !!(scene.lod1 || scene.fill3d);\n/** Whether a scene reads the buildings source: for its buildings or its landmarks. */\nconst usesBuildingsSource = (scene: Scene3dManifest) => hasBuildings(scene) || !!scene.landmarks;\n/** The landmarks among the features of the source layer `buildings3d`, unless the scene names another filter. */\nconst LANDMARKS_FILTER = [\"==\", [\"get\", \"source\"], \"landmark\"] as unknown as FilterSpecification;\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`), the landmarks among them (a `Fill3DLayer`\n * of their own) 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 /** The position each custom layer was added with (`\"below-labels\"` when the scene names none). */\n private customPosition = new Map<string, Scene3dPosition>();\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 // Multisampling is decided when the map creates its WebGL context; a control added later cannot switch it on.\n // Without it the buildings and trees get hard, pixelated edges, and the far trees lose their soft leaf edges.\n const canvas = map.getCanvas?.();\n const gl = canvas?.getContext?.(\"webgl2\") ?? canvas?.getContext?.(\"webgl\");\n if (gl && (gl as WebGLRenderingContext).getContextAttributes?.()?.antialias === false) {\n this.warnOnce(\n \"antialias\",\n \"Scene3dControl: the map's WebGL context has no multisampling, so the 3D buildings and trees get pixelated edges. Create the map with canvasContextAttributes: { antialias: true }.\",\n );\n }\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)) || (usesBuildingsSource(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 /** The layer a scene layer goes below for `position`: none for \"top\", the style layer it names, else `anchor`. */\n private beforeFor(position: Scene3dPosition | undefined, anchor: string | undefined) {\n if (position === \"top\") return undefined;\n if (!position || position === \"below-labels\") return anchor;\n if (!position.startsWith(this.options.idPrefix) && this.map?.getLayer(position)) return position;\n this.warnOnce(`position-${position}`, `Scene3dControl: the style has no layer \"${position}\", the scene goes under the labels`);\n return anchor;\n }\n\n /**\n * The buildings source and the native layers, each below the layer its position names. `place` can pick another\n * layer for a position (restoreNative: the 3D layers with the same position).\n */\n private addNative(scene: Scene3dManifest, place = (_position: Scene3dPosition, before: string | undefined) => before) {\n const map = this.map!;\n const source = this.sourceId();\n if (!usesBuildingsSource(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 const anchor = this.labelsAnchor();\n const before = (position: Scene3dPosition | undefined) => place(position ?? \"below-labels\", this.beforeFor(position, anchor));\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, before(position));\n this.native.push(`${p}lod1`);\n } else {\n // The Fill3DLayers (buildings, landmarks) read 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 before((scene.fill3d ?? scene.landmarks)?.position),\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 with the same position again, as in a full build.\n this.addNative(scene, (position, before) => this.custom.find((l) => this.customPosition.get(l.id) === position)?.id ?? before);\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 this.customPosition.set(layer.id, position ?? \"below-labels\");\n };\n this.building = true;\n try {\n // The landmarks have a layer of their own, so the buildings' layer leaves them out. A scene without\n // `landmarks` keeps them in `fill3d`: drawn as plain buildings rather than missing.\n const landmarksFilter = scene.landmarks ? (scene.landmarks.filter ?? LANDMARKS_FILTER) : undefined;\n if (scene.fill3d) {\n const { position, ...fill3d } = scene.fill3d;\n const filter = landmarksFilter && [\"all\", ...(fill3d.filter ? [fill3d.filter] : []), [\"!\", landmarksFilter]];\n add(\n new lib.Fill3DLayer({ id: `${p}fill3d`, source: this.sourceId(), \"source-layer\": \"buildings3d\", ...fill3d, ...(filter ? { filter } : {}) }),\n position,\n );\n }\n if (scene.landmarks) {\n const { position, ...landmarks } = scene.landmarks;\n add(\n new lib.Fill3DLayer({ id: `${p}landmarks`, source: this.sourceId(), \"source-layer\": \"buildings3d\", ...landmarks, filter: landmarksFilter }),\n position,\n );\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.customPosition.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,sBA2G9BC,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,SAElEI,KAAuB,MAA2BD,EAAaH,CAAK,KAAK,CAAC,CAACA,EAAM,WAEjFK,IAAmB;CAAC;CAAM,CAAC,OAAO,QAAQ;CAAG;AAAU,GAYhDC,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,iCAAyB,IAAI,IAA6B;CAE1D,aAAoC;CAEpC,YAAY,IAAiC,CAAC,GAAG;EAC/C,MAAM;EACN,IAAM,EAAE,UAAO,GAAGC,MAASC;EAO3B,AANA,KAAK,UAAU;GACb,GAAGd;GACH,eAAe,OAAO;GACtB,GAAG,OAAO,YAAY,OAAO,QAAQa,CAAI,CAAC,CAAC,QAAQ,GAAGE,OAAOA,MAAM,KAAA,C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D,EAAI,IAAI,cAAcgD,CAAM,GAC5B,KAAK,cAAc,KAAA;EACrB;CACF;CAEA,kBAA0B;EACxB,IAAMhD,IAAM,KAAK;EACjB,KAAK,IAAMuB,KAAM,KAAK,QAAQ,YAC5B,AAAKvB,EAAI,SAASuB,CAAE,MACpB,KAAK,OAAO,IAAIA,GAAKvB,EAAI,kBAAkBuB,GAAI,YAAY,KAAwC,SAAS,GAC5GvB,EAAI,kBAAkBuB,GAAI,cAAc,MAAM;CAElD;CAEA,QAAgB,GAAqB;EACnC,IAAI,CAAC,KAAK,QAAQ,QAAQ,OAAO2B;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","hasBuildings","usesBuildingsSource","LANDMARKS_FILTER","Scene3dControl","Evented","rest","options","v","container","button","canvas","gl","response","enabled","lib","err","next","l","id","pitch","sheet","generation","position","anchor","before","source","p","place","lod1","add","layer","landmarksFilter","fill3d","filter","landmarks","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/**\n * Where a layer of the scene goes: under the style's labels (`\"below-labels\"`, the default: right below its first\n * symbol layer), on top of everything (`\"top\"`), or right below the style layer with that id. The position only\n * decides what draws over the 3D among symbol layers (labels, icons); fills and lines always end up under it. A\n * layer id the style lacks falls back to `\"below-labels\"`.\n */\nexport type Scene3dPosition = \"below-labels\" | \"top\" | (string & {});\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 /**\n * `Fill3DLayer` on the source layer `buildings3d`. With `extrusion` it also extrudes the 2D footprints of a source\n * layer of the same tiles (maplibre-3d-layers ≥ 0.6.0, experimental), so that they get its shading and fake ambient\n * occlusion; leave the same footprints out of `lod1` where it does, by a filter on the tile zoom (not `maxzoom`).\n */\n fill3d?: {\n position?: Scene3dPosition;\n filter?: FilterSpecification;\n paint?: Record<string, Expression>;\n extrusion?: { \"source-layer\": string; filter?: FilterSpecification; height?: Expression; base?: Expression };\n };\n /**\n * The landmarks in the source layer `buildings3d`, as a `Fill3DLayer` of their own: with their own paint and their\n * own place among the style's layers. `filter` picks them (default `[\"==\", [\"get\", \"source\"], \"landmark\"]`), and\n * `fill3d` then leaves those features out.\n */\n landmarks?: { 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/** Whether a scene draws buildings, in place of the style's own 3D buildings (`hideLayers`). */\nconst hasBuildings = (scene: Scene3dManifest) => !!(scene.lod1 || scene.fill3d);\n/** Whether a scene reads the buildings source: for its buildings or its landmarks. */\nconst usesBuildingsSource = (scene: Scene3dManifest) => hasBuildings(scene) || !!scene.landmarks;\n/** The landmarks among the features of the source layer `buildings3d`, unless the scene names another filter. */\nconst LANDMARKS_FILTER = [\"==\", [\"get\", \"source\"], \"landmark\"] as unknown as FilterSpecification;\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`), the landmarks among them (a `Fill3DLayer`\n * of their own) 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 * a style change and loads the 3D library only when the map gets close enough. A terrain that is\n * switched on, off or changed leaves the 3D layers as they are: they move onto it themselves.\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 /** The position each custom layer was added with (`\"below-labels\"` when the scene names none). */\n private customPosition = new Map<string, Scene3dPosition>();\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 // Multisampling is decided when the map creates its WebGL context; a control added later cannot switch it on.\n // Without it the buildings and trees get hard, pixelated edges, and the far trees lose their soft leaf edges.\n const canvas = map.getCanvas?.();\n const gl = canvas?.getContext?.(\"webgl2\") ?? canvas?.getContext?.(\"webgl\");\n if (gl && (gl as WebGLRenderingContext).getContextAttributes?.()?.antialias === false) {\n this.warnOnce(\n \"antialias\",\n \"Scene3dControl: the map's WebGL context has no multisampling, so the 3D buildings and trees get pixelated edges. Create the map with canvasContextAttributes: { antialias: true }.\",\n );\n }\n\n map.on(\"style.load\", this.onStyleLoad);\n map.on(\"styledata\", this.onStyleData);\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(\"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)) || (usesBuildingsSource(this.scene) && !map.getSource(this.sourceId()))) this.restoreNative();\n else this.syncPitch();\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 /** The layer a scene layer goes below for `position`: none for \"top\", the style layer it names, else `anchor`. */\n private beforeFor(position: Scene3dPosition | undefined, anchor: string | undefined) {\n if (position === \"top\") return undefined;\n if (!position || position === \"below-labels\") return anchor;\n if (!position.startsWith(this.options.idPrefix) && this.map?.getLayer(position)) return position;\n this.warnOnce(`position-${position}`, `Scene3dControl: the style has no layer \"${position}\", the scene goes under the labels`);\n return anchor;\n }\n\n /**\n * The buildings source and the native layers, each below the layer its position names. `place` can pick another\n * layer for a position (restoreNative: the 3D layers with the same position).\n */\n private addNative(scene: Scene3dManifest, place = (_position: Scene3dPosition, before: string | undefined) => before) {\n const map = this.map!;\n const source = this.sourceId();\n if (!usesBuildingsSource(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 const anchor = this.labelsAnchor();\n const before = (position: Scene3dPosition | undefined) => place(position ?? \"below-labels\", this.beforeFor(position, anchor));\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, before(position));\n this.native.push(`${p}lod1`);\n } else {\n // The Fill3DLayers (buildings, landmarks) read 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 before((scene.fill3d ?? scene.landmarks)?.position),\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 with the same position again, as in a full build.\n this.addNative(scene, (position, before) => this.custom.find((l) => this.customPosition.get(l.id) === position)?.id ?? before);\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 const add = (layer: CustomLayerInterface, position: Scene3dPosition | undefined) => {\n map.addLayer(layer, this.beforeFor(position, anchor));\n this.custom.push(layer);\n this.customPosition.set(layer.id, position ?? \"below-labels\");\n };\n this.building = true;\n try {\n // The landmarks have a layer of their own, so the buildings' layer leaves them out. A scene without\n // `landmarks` keeps them in `fill3d`: drawn as plain buildings rather than missing.\n const landmarksFilter = scene.landmarks ? (scene.landmarks.filter ?? LANDMARKS_FILTER) : undefined;\n if (scene.fill3d) {\n const { position, ...fill3d } = scene.fill3d;\n const filter = landmarksFilter && [\"all\", ...(fill3d.filter ? [fill3d.filter] : []), [\"!\", landmarksFilter]];\n add(\n new lib.Fill3DLayer({ id: `${p}fill3d`, source: this.sourceId(), \"source-layer\": \"buildings3d\", ...fill3d, ...(filter ? { filter } : {}) }),\n position,\n );\n }\n if (scene.landmarks) {\n const { position, ...landmarks } = scene.landmarks;\n add(\n new lib.Fill3DLayer({ id: `${p}landmarks`, source: this.sourceId(), \"source-layer\": \"buildings3d\", ...landmarks, filter: landmarksFilter }),\n position,\n );\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.customPosition.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,sBA2G9BC,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,MAA2B,CAAC,EAAED,EAAM,QAAQA,EAAM,SAElEE,KAAuB,MAA2BD,EAAaD,CAAK,KAAK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  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 = (e) => e ? `${e.source}|${e.exaggeration ?? 1}` : null, s = (e) => !!(e.lod1 || e.fill3d), c = (e) => s(e) || !!e.landmarks, l = [
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.lod1 || e.fill3d), s = (e) => o(e) || !!e.landmarks, c = [
10
10
  "==",
11
11
  ["get", "source"],
12
12
  "landmark"
13
- ], u = class extends e {
13
+ ], l = class extends e {
14
14
  options;
15
15
  map;
16
16
  container;
@@ -33,7 +33,6 @@ var t = "maptoolkit:scene3d", n = {
33
33
  sceneKey = null;
34
34
  sourceOk = !1;
35
35
  customPosition = /* @__PURE__ */ new Map();
36
- terrainKey = null;
37
36
  constructor(e = {}) {
38
37
  super();
39
38
  let { scene: t, ...r } = e;
@@ -55,11 +54,11 @@ var t = "maptoolkit:scene3d", n = {
55
54
  } else t.classList.add("maplibre-scene3d-control-hidden");
56
55
  this.container = t;
57
56
  let n = e.getCanvas?.(), a = n?.getContext?.("webgl2") ?? n?.getContext?.("webgl");
58
- return a && a.getContextAttributes?.()?.antialias === !1 && this.warnOnce("antialias", "Scene3dControl: the map's WebGL context has no multisampling, so the 3D buildings and trees get pixelated edges. Create the map with canvasContextAttributes: { antialias: true }."), 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;
57
+ return a && a.getContextAttributes?.()?.antialias === !1 && this.warnOnce("antialias", "Scene3dControl: the map's WebGL context has no multisampling, so the 3D buildings and trees get pixelated edges. Create the map with canvasContextAttributes: { antialias: true }."), e.on("style.load", this.onStyleLoad), e.on("styledata", this.onStyleData), e.on("pitch", this.syncPitch), e.on("zoomend", this.onZoom), i(e)?._loaded && this.onStyleLoad(), t;
59
58
  }
60
59
  onRemove() {
61
60
  let e = this.map;
62
- 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);
61
+ e && (this.teardown(!0), e.off("style.load", this.onStyleLoad), e.off("styledata", this.onStyleData), 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);
63
62
  }
64
63
  async setScene(e) {
65
64
  if (typeof e == "string") {
@@ -103,11 +102,8 @@ var t = "maptoolkit:scene3d", n = {
103
102
  }
104
103
  this.sceneRef = t;
105
104
  }
106
- this.scene && (this.custom.some((t) => !e.getLayer(t.id)) ? this.refresh() : this.native.some((t) => !e.getLayer(t)) || c(this.scene) && !e.getSource(this.sourceId()) ? this.restoreNative() : this.syncPitch());
105
+ 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());
107
106
  }
108
- onTerrain = () => {
109
- this.map && this.styleReady() && this.custom.length && this.scene && o(this.map.getTerrain()) !== this.terrainKey && (this.removeCustom(), this.addCustom(this.scene, this.generation));
110
- };
111
107
  onZoom = () => {
112
108
  !this.map || this.lib || !this.scene || this.map.getZoom() < this.options.minzoom || this.loadCustom(this.scene, this.generation);
113
109
  };
@@ -132,7 +128,7 @@ var t = "maptoolkit:scene3d", n = {
132
128
  try {
133
129
  this.teardown(!0);
134
130
  let t = ++this.generation, n = this.currentScene();
135
- 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));
131
+ 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(), o(n) && this.hideOnceBuildingsLoad(t), this.addNative(n), this.lib ? this.addCustom(n, t) : e.getZoom() >= this.options.minzoom && this.loadCustom(n, t));
136
132
  } finally {
137
133
  this.building = !1;
138
134
  }
@@ -150,7 +146,7 @@ var t = "maptoolkit:scene3d", n = {
150
146
  }
151
147
  addNative(e, t = (e, t) => t) {
152
148
  let n = this.map, r = this.sourceId();
153
- if (!c(e)) return;
149
+ if (!s(e)) return;
154
150
  n.getSource(r) || n.addSource(r, {
155
151
  type: "vector",
156
152
  url: this.withKey(e.source)
@@ -179,7 +175,7 @@ var t = "maptoolkit:scene3d", n = {
179
175
  this.building = !0;
180
176
  try {
181
177
  for (let t of this.native) e.getLayer(t) && e.removeLayer(t);
182
- this.native = [], this.hidden.clear(), this.addNative(t, (e, t) => this.custom.find((t) => this.customPosition.get(t.id) === e)?.id ?? t), s(t) && (this.sourceOk ? this.hideStyleLayers() : (this.stopWaiting?.(), this.hideOnceBuildingsLoad(this.generation))), this.pitch = null, this.syncPitch();
178
+ this.native = [], this.hidden.clear(), this.addNative(t, (e, t) => this.custom.find((t) => this.customPosition.get(t.id) === e)?.id ?? t), o(t) && (this.sourceOk ? this.hideStyleLayers() : (this.stopWaiting?.(), this.hideOnceBuildingsLoad(this.generation))), this.pitch = null, this.syncPitch();
183
179
  } finally {
184
180
  this.building = !1;
185
181
  }
@@ -192,31 +188,29 @@ var t = "maptoolkit:scene3d", n = {
192
188
  addCustom(e, t) {
193
189
  let n = this.map, r = this.lib;
194
190
  if (!n || !r || t !== this.generation || !this.styleReady()) return;
195
- let i = this.labelsAnchor(), a = this.options.idPrefix;
196
- this.terrainKey = o(n.getTerrain());
197
- let s = (e, t) => {
191
+ let i = this.labelsAnchor(), a = this.options.idPrefix, o = (e, t) => {
198
192
  n.addLayer(e, this.beforeFor(t, i)), this.custom.push(e), this.customPosition.set(e.id, t ?? "below-labels");
199
193
  };
200
194
  this.building = !0;
201
195
  try {
202
- let t = e.landmarks ? e.landmarks.filter ?? l : void 0;
196
+ let t = e.landmarks ? e.landmarks.filter ?? c : void 0;
203
197
  if (e.fill3d) {
204
- let { position: n, ...i } = e.fill3d, o = t && [
198
+ let { position: n, ...i } = e.fill3d, s = t && [
205
199
  "all",
206
200
  ...i.filter ? [i.filter] : [],
207
201
  ["!", t]
208
202
  ];
209
- s(new r.Fill3DLayer({
203
+ o(new r.Fill3DLayer({
210
204
  id: `${a}fill3d`,
211
205
  source: this.sourceId(),
212
206
  "source-layer": "buildings3d",
213
207
  ...i,
214
- ...o ? { filter: o } : {}
208
+ ...s ? { filter: s } : {}
215
209
  }), n);
216
210
  }
217
211
  if (e.landmarks) {
218
212
  let { position: n, ...i } = e.landmarks;
219
- s(new r.Fill3DLayer({
213
+ o(new r.Fill3DLayer({
220
214
  id: `${a}landmarks`,
221
215
  source: this.sourceId(),
222
216
  "source-layer": "buildings3d",
@@ -226,17 +220,17 @@ var t = "maptoolkit:scene3d", n = {
226
220
  }
227
221
  let i = e.models ?? {};
228
222
  for (let t of e.gltf ?? []) {
229
- let { id: e, position: o, models: c, ...l } = t;
223
+ let { id: e, position: s, models: c, ...l } = t;
230
224
  if (!n.getSource(l.source)) {
231
225
  this.warnOnce(`source-${l.source}`, `Scene3dControl: the style has no source "${l.source}", layer "${e}" left out`);
232
226
  continue;
233
227
  }
234
228
  let u = c ?? Object.keys(i), d = Object.fromEntries(u.filter((e) => i[e]).map((e) => [e, this.modelUrl(i[e])]));
235
- Object.keys(d).length && s(new r.GltfLayer({
229
+ Object.keys(d).length && o(new r.GltfLayer({
236
230
  id: `${a}${e}`,
237
231
  models: d,
238
232
  ...l
239
- }), o);
233
+ }), s);
240
234
  }
241
235
  } finally {
242
236
  this.building = !1;
@@ -286,17 +280,17 @@ var t = "maptoolkit:scene3d", n = {
286
280
  warnOnce(e, t) {
287
281
  this.warned.has(e) || (this.warned.add(e), console.warn(t));
288
282
  }
289
- }, d = () => import(
283
+ }, u = () => import(
290
284
  /* @vite-ignore */
291
- new URL("./maplibre-3d-layers-0.6.0.standalone.mjs", import.meta.url).href
292
- ), f = class extends u {
285
+ new URL("./maplibre-3d-layers-0.7.0.standalone.mjs", import.meta.url).href
286
+ ), d = class extends l {
293
287
  constructor(e = {}) {
294
288
  super({
295
289
  ...e,
296
- library: e.library ?? d
290
+ library: e.library ?? u
297
291
  });
298
292
  }
299
293
  };
300
- export { t as SCENE3D_METADATA_KEY, f as Scene3dControl, d as bundledLibrary };
294
+ export { t as SCENE3D_METADATA_KEY, d as Scene3dControl, u as bundledLibrary };
301
295
 
302
296
  //# sourceMappingURL=maplibre-scene3d-control.standalone.js.map