@maptoolkit/maplibre-scene3d-control 0.3.1 → 0.3.3
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 +3 -1
- package/dist/{maplibre-3d-layers-0.5.5.standalone.mjs → maplibre-3d-layers-0.5.6.standalone.mjs} +96 -88
- package/dist/maplibre-scene3d-control.js +3 -1
- package/dist/maplibre-scene3d-control.js.map +1 -1
- package/dist/maplibre-scene3d-control.standalone.js +4 -2
- package/dist/maplibre-scene3d-control.standalone.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ const map = new maplibregl.Map({
|
|
|
37
37
|
zoom: 16,
|
|
38
38
|
pitch: 70,
|
|
39
39
|
maxPitch: 85,
|
|
40
|
-
canvasContextAttributes: { antialias: true }, // soft edges on distant trees
|
|
40
|
+
canvasContextAttributes: { antialias: true }, // smooth edges on the buildings, soft edges on distant trees
|
|
41
41
|
});
|
|
42
42
|
map.addControl(new Scene3dControl({ apiKey: "YOUR_KEY" }));
|
|
43
43
|
```
|
|
@@ -114,6 +114,8 @@ MapLibre ignores a diffed `setStyle` that changes nothing but the metadata. A sc
|
|
|
114
114
|
|
|
115
115
|
## Requirements
|
|
116
116
|
|
|
117
|
+
- **Create the map with `canvasContextAttributes: { antialias: true }`.** MapLibre leaves multisampling off; without it the buildings and trees render with hard, pixelated edges, and the far trees lose their soft leaf edges (alpha to coverage). The control cannot switch it on itself, since the WebGL context exists before the control is added; it warns once in the console when it finds a context without multisampling. Multisampling costs GPU on every frame, which is why MapLibre's default is off.
|
|
118
|
+
|
|
117
119
|
- MapLibre GL JS ≥ 6 (peer dependency). `@maptoolkit/maplibre-3d-layers` and three.js ≥ 0.160 come with the control.
|
|
118
120
|
- A Maptoolkit API key with access to the buildings source.
|
|
119
121
|
- A style with a scene, or a scene passed with `scene`. Vegetation also needs the style's `mtk` source.
|
package/dist/{maplibre-3d-layers-0.5.5.standalone.mjs → maplibre-3d-layers-0.5.6.standalone.mjs}
RENAMED
|
@@ -18106,20 +18106,20 @@ function Zg(e) {
|
|
|
18106
18106
|
}
|
|
18107
18107
|
//#endregion
|
|
18108
18108
|
//#region src/GltfManager.ts
|
|
18109
|
-
var Qg = Math.PI / 180, $g = 25, e_ = .
|
|
18109
|
+
var Qg = Math.PI / 180, $g = 25, e_ = (e) => e.radius < $g && e.top - e.bottom < $g, t_ = .25, n_ = .1, r_ = 16, i_ = 1, a_ = 1.2, o_ = .1, s_ = 150, c_ = 1.5, l_ = 20, u_ = (e) => `\u0000impostor:${e}`, d_ = new G().makeScale(-1, 1, 1), f_ = 128, p_ = "\n#include <map_fragment>\n#ifdef USE_MAP\n diffuseColor.rgb /= max( sampledDiffuseColor.a, 0.0001 );\n#endif\n", m_ = 20, h_ = "\nuniform vec3 mtkRight;\n#include <common>\n", g_ = "\nvec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n mvPosition = vec4(\n instanceMatrix[ 3 ].xyz\n + mtkRight * transformed.x * length( instanceMatrix[ 0 ].xyz )\n + vec3( 0.0, transformed.y * length( instanceMatrix[ 1 ].xyz ), 0.0 ),\n 1.0\n );\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;\n", __ = "\n#include <color_pars_vertex>\n#ifdef MTK_INSTANCE_ALPHA\n attribute float instanceAlpha;\n varying float vInstanceAlpha;\n#endif\n", v_ = "\n#include <color_vertex>\n#ifdef MTK_INSTANCE_ALPHA\n vInstanceAlpha = instanceAlpha;\n#endif\n", y_ = "\n#include <color_pars_fragment>\n#if defined( USE_INSTANCING_COLOR ) && !defined( USE_COLOR ) && !defined( USE_COLOR_ALPHA )\n varying vec4 vColor;\n#endif\n#ifdef MTK_INSTANCE_ALPHA\n varying float vInstanceAlpha;\n#endif\n#ifdef MTK_OPACITY\n uniform float mtkOpacity;\n#endif\n", b_ = "\n#ifdef MTK_INSTANCE_ALPHA\n diffuseColor.a *= vInstanceAlpha;\n#endif\n#ifdef MTK_OPACITY\n diffuseColor.a *= mtkOpacity;\n#endif\n", x_ = `
|
|
18110
18110
|
#include <color_fragment>
|
|
18111
18111
|
#if defined( USE_INSTANCING_COLOR ) && !defined( USE_COLOR ) && !defined( USE_COLOR_ALPHA )
|
|
18112
18112
|
diffuseColor.rgb *= vColor.rgb;
|
|
18113
18113
|
#endif
|
|
18114
18114
|
#ifndef MTK_ALPHA_AFTER_TEST
|
|
18115
|
-
${
|
|
18115
|
+
${b_}
|
|
18116
18116
|
#endif
|
|
18117
|
-
`,
|
|
18117
|
+
`, S_ = `
|
|
18118
18118
|
#include <alphatest_fragment>
|
|
18119
18119
|
#ifdef MTK_ALPHA_AFTER_TEST
|
|
18120
|
-
${
|
|
18120
|
+
${b_}
|
|
18121
18121
|
#endif
|
|
18122
|
-
`,
|
|
18122
|
+
`, C_ = class {
|
|
18123
18123
|
origin;
|
|
18124
18124
|
map;
|
|
18125
18125
|
group;
|
|
@@ -18160,7 +18160,7 @@ ${y_}
|
|
|
18160
18160
|
sMat = new G();
|
|
18161
18161
|
sColor = new K();
|
|
18162
18162
|
constructor(e, t, n, r, i) {
|
|
18163
|
-
this.map = e, this.scene = t, this.terrainSourceId = r, this.config = i, this.origin =
|
|
18163
|
+
this.map = e, this.scene = t, this.terrainSourceId = r, this.config = i, this.origin = j_(n), this.filter = Zm(i.filter, "filter").filter, this.group = new On(), t.add(this.group);
|
|
18164
18164
|
let a = e.getSource(i.sourceId);
|
|
18165
18165
|
a || console.error(`GltfLayer: source '${i.sourceId}' not found — add it before the layer`), this.wholeDataset = a?.type === "geojson";
|
|
18166
18166
|
for (let [e, t] of Object.entries(i.models)) this.loadModel(e, t);
|
|
@@ -18196,7 +18196,7 @@ ${y_}
|
|
|
18196
18196
|
refreshSoon() {
|
|
18197
18197
|
this.disposed || (this.settleTimer !== void 0 && clearTimeout(this.settleTimer), this.settleTimer = setTimeout(() => {
|
|
18198
18198
|
this.settleTimer = void 0, this.map.isMoving() || this.refresh();
|
|
18199
|
-
},
|
|
18199
|
+
}, s_));
|
|
18200
18200
|
}
|
|
18201
18201
|
refresh() {
|
|
18202
18202
|
this.schedule(!0, !0);
|
|
@@ -18226,7 +18226,7 @@ ${y_}
|
|
|
18226
18226
|
let e = this.pendingDemRegions;
|
|
18227
18227
|
if (this.pendingDemRegions = [], e.length === 0) return;
|
|
18228
18228
|
let t = 0;
|
|
18229
|
-
for (let n of this.batches.values()) e.some((e) =>
|
|
18229
|
+
for (let n of this.batches.values()) e.some((e) => J_(e, n.bounds)) && (this.writeInstances(n), t++);
|
|
18230
18230
|
t && this.map.triggerRepaint();
|
|
18231
18231
|
}
|
|
18232
18232
|
hidden() {
|
|
@@ -18244,7 +18244,7 @@ ${y_}
|
|
|
18244
18244
|
return this.warnOnce("query", "GltfLayer: querySourceFeatures failed", t), e;
|
|
18245
18245
|
}
|
|
18246
18246
|
for (let n of t) {
|
|
18247
|
-
let t =
|
|
18247
|
+
let t = O_(n.geometry);
|
|
18248
18248
|
t && e.push({
|
|
18249
18249
|
geometry: n.geometry,
|
|
18250
18250
|
bbox: t,
|
|
@@ -18269,10 +18269,10 @@ ${y_}
|
|
|
18269
18269
|
zoom: this.map.getZoom(),
|
|
18270
18270
|
globalState: fu(this.map)
|
|
18271
18271
|
};
|
|
18272
|
-
for (let e of
|
|
18273
|
-
let t = e.properties ?? {}, i =
|
|
18272
|
+
for (let e of k_(t)) {
|
|
18273
|
+
let t = e.properties ?? {}, i = O_(e.geometry);
|
|
18274
18274
|
i && this.filter(r, {
|
|
18275
|
-
type:
|
|
18275
|
+
type: D_(e.geometry),
|
|
18276
18276
|
properties: t,
|
|
18277
18277
|
id: e.id
|
|
18278
18278
|
}) && n.push({
|
|
@@ -18292,7 +18292,7 @@ ${y_}
|
|
|
18292
18292
|
z: r.z,
|
|
18293
18293
|
s: r.meterInMercatorCoordinateUnits()
|
|
18294
18294
|
};
|
|
18295
|
-
let i =
|
|
18295
|
+
let i = F_(this.map), a = this.config.thinningDistance(e, {}, void 0, n), o = Number.isFinite(a) && a > 0 ? K_(this.map) : void 0, s = o ? a * 7 * o.s : Infinity, c = this.config.impostorDistance(e, {}, void 0, n), l = Number.isFinite(c) ? o ?? K_(this.map) : void 0, u = this.map.getCanvas(), d = Math.hypot(u.clientWidth, u.clientHeight) / 2 * 1.1 / (512 * 2 ** e);
|
|
18296
18296
|
if (o) {
|
|
18297
18297
|
let e = new t(o.x - s, o.y - s).toLngLat(), n = new t(o.x + s, o.y + s).toLngLat();
|
|
18298
18298
|
i = {
|
|
@@ -18307,13 +18307,13 @@ ${y_}
|
|
|
18307
18307
|
minY: Pg(i.south),
|
|
18308
18308
|
maxX: Ng(i.east),
|
|
18309
18309
|
maxY: Pg(i.north)
|
|
18310
|
-
}, p = this.maxReach(e, n), m = this.features.filter((e) =>
|
|
18311
|
-
let i = r.x === void 0 ?
|
|
18310
|
+
}, p = this.maxReach(e, n), m = this.features.filter((e) => J_(M_(i, p), e.bbox)), h = this.config.maxInstances, g = h * l_, { cells: _, keep: v } = this.planCells(m, e, n, i, g), y = V_(this.map, n_), b = this.viewMatrix ? P_(this.viewMatrix, n_) : void 0, x = this.map.terrain ? this.map.getCenterElevation() : 0, S = H_(this.map, n_, o, s), C = o ? Math.min(1, this.lastThinScale * c_) : 1, w = o ? (e, t, n) => L_(Math.hypot(Lg(e) - o.x, Rg(t) - o.y) / o.s, a, n) < C : void 0, T = /* @__PURE__ */ new Set(), E = Math.round(this.config.maxInstances * a_), D = 0, O = [], k = new globalThis.Map(), A = (t, r) => {
|
|
18311
|
+
let i = r.x === void 0 ? z_(r.lng) : Lg(r.x), s = r.y === void 0 ? B_(r.lat) : Rg(r.y), c = b ? this.reachOf(t, r.id, e, n) : void 0;
|
|
18312
18312
|
if (c && b) {
|
|
18313
18313
|
let e = this.origin.s;
|
|
18314
18314
|
if (!b(i, s, c.radius * e, (x + c.bottom) * e, (x + c.top) * e)) return !0;
|
|
18315
18315
|
} else if (y && !y(i, s)) return !0;
|
|
18316
|
-
let l = c && o ? Math.max(0, Math.hypot(i - o.x, s - o.y) - c.radius * o.s) : 0, u = o ?
|
|
18316
|
+
let l = c && o ? Math.max(0, Math.hypot(i - o.x, s - o.y) - c.radius * o.s) : 0, u = o ? L_((c ? l : Math.hypot(i - o.x, s - o.y)) / o.s, a, r.id) : 0;
|
|
18317
18317
|
return u >= C || (O.push({
|
|
18318
18318
|
f: t,
|
|
18319
18319
|
point: r,
|
|
@@ -18325,7 +18325,7 @@ ${y_}
|
|
|
18325
18325
|
let o = r.id, s = this.config.modelId(e, t.props, o, n), u = this.models.get(s);
|
|
18326
18326
|
if (!u) return this.warnOnce(`model:${s}`, `GltfLayer: no model '${s}' in \`models\` — feature skipped`), !0;
|
|
18327
18327
|
if (u.state !== "ready") return !0;
|
|
18328
|
-
let f = l !== void 0 && Math.hypot(i - l.x, a - l.y) / l.s >= c && Math.hypot(i - this.origin.x, a - this.origin.y) > d && this.models.get(
|
|
18328
|
+
let f = l !== void 0 && Math.hypot(i - l.x, a - l.y) / l.s >= c && Math.hypot(i - this.origin.x, a - this.origin.y) > d && this.models.get(u_(s))?.state === "ready" ? u_(s) : s, p = k.get(f);
|
|
18329
18329
|
return p || k.set(f, p = {
|
|
18330
18330
|
recs: [],
|
|
18331
18331
|
colors: this.config.color ? [] : void 0,
|
|
@@ -18347,7 +18347,7 @@ ${y_}
|
|
|
18347
18347
|
let t = m[e], n = _[e];
|
|
18348
18348
|
switch (this.placementFor(t)) {
|
|
18349
18349
|
case "point":
|
|
18350
|
-
for (let [e, n] of
|
|
18350
|
+
for (let [e, n] of w_(t.geometry)) {
|
|
18351
18351
|
let r = Kg(Ng(e), Pg(n));
|
|
18352
18352
|
if (!T.has(r) && (T.add(r), !A(t, {
|
|
18353
18353
|
lng: e,
|
|
@@ -18357,30 +18357,30 @@ ${y_}
|
|
|
18357
18357
|
}
|
|
18358
18358
|
break;
|
|
18359
18359
|
case "line":
|
|
18360
|
-
if (!Jg(
|
|
18360
|
+
if (!Jg(T_(t.geometry), n, f, T, (e) => A(t, e))) break outer;
|
|
18361
18361
|
break;
|
|
18362
|
-
case "fill": if (!Yg(
|
|
18362
|
+
case "fill": if (!Yg(E_(t.geometry), n, f, T, (e) => A(t, e), v, S, w)) break outer;
|
|
18363
18363
|
}
|
|
18364
18364
|
}
|
|
18365
18365
|
};
|
|
18366
18366
|
if (te(), C < 1 && O.length <= h && (C = 1, te()), O.length) {
|
|
18367
|
-
let e = o ?
|
|
18367
|
+
let e = o ? R_(O, h) : 1;
|
|
18368
18368
|
o && (this.lastThinScale = e);
|
|
18369
18369
|
let t = o ? 1 : Math.min(1, h / O.length);
|
|
18370
18370
|
t < 1 && this.warnOnce("budget", `GltfLayer: ${O.length} instances in view exceed maxInstances (${h}) — keeping ${(t * 100).toFixed(0)}% of them; raise maxInstances, use a zoom-driven model-spacing or set model-thinning-distance`);
|
|
18371
|
-
for (let n of O) if (!(o ? n.need >= e :
|
|
18371
|
+
for (let n of O) if (!(o ? n.need >= e : I_(n.point.id) >= t) && !ee(n.f, n.point, n.x, n.y)) break;
|
|
18372
18372
|
}
|
|
18373
18373
|
for (let [e, t] of this.batches) k.has(e) || this.disposeBatch(e, t);
|
|
18374
18374
|
this.instanceFading = [...k.values()].some((e) => e.alphas?.some((e) => e < 1)), this.setFading(this.instanceFading || this.uniformFading);
|
|
18375
18375
|
for (let [e, t] of k) {
|
|
18376
18376
|
let n = this.batchFor(e, t.recs.length);
|
|
18377
|
-
n.recs = t.recs, n.bounds =
|
|
18377
|
+
n.recs = t.recs, n.bounds = q_(t.recs), this.writeInstances(n, t.colors, t.alphas);
|
|
18378
18378
|
}
|
|
18379
18379
|
this.map.triggerRepaint();
|
|
18380
18380
|
}
|
|
18381
18381
|
reachOf(e, t, n, r) {
|
|
18382
18382
|
let i = this.models.get(this.config.modelId(n, e.props, t, r))?.extent;
|
|
18383
|
-
if (!i || i
|
|
18383
|
+
if (!i || e_(i)) return;
|
|
18384
18384
|
let a = this.config.scale(n, e.props, t, r), o = this.config.translation(n, e.props, t, r), s = this.config.rotation(n, e.props, t, r), c = Math.max(Math.abs(a[0]), Math.abs(a[2])), l = i.bottom * a[1], u = i.top * a[1], d = i.radius * c + Math.hypot(o[0], o[1]), f = Math.min(l, u) + o[2], p = Math.max(l, u) + o[2];
|
|
18385
18385
|
return (s[0] || s[1]) && (d = Math.max(d, Math.abs(f), Math.abs(p)), f = Math.min(f, -d), p = Math.max(p, d)), {
|
|
18386
18386
|
radius: d,
|
|
@@ -18389,12 +18389,20 @@ ${y_}
|
|
|
18389
18389
|
};
|
|
18390
18390
|
}
|
|
18391
18391
|
maxReach(e, t) {
|
|
18392
|
-
let n =
|
|
18392
|
+
let n = 0;
|
|
18393
18393
|
for (let e of this.models.values()) {
|
|
18394
18394
|
let t = e.extent;
|
|
18395
|
-
t && (
|
|
18395
|
+
t && !e_(t) && (n = Math.max(n, Math.hypot(t.radius, Math.max(Math.abs(t.top), Math.abs(t.bottom)))));
|
|
18396
18396
|
}
|
|
18397
|
-
|
|
18397
|
+
if (!n) return 0;
|
|
18398
|
+
let { scale: r, translation: i } = this.config, a = (a, o) => {
|
|
18399
|
+
let s = r(e, a, o, t), c = i(e, a, o, t);
|
|
18400
|
+
return n * Math.max(Math.abs(s[0]), Math.abs(s[1]), Math.abs(s[2])) + Math.hypot(c[0], c[1], c[2]);
|
|
18401
|
+
};
|
|
18402
|
+
if (r.featureConstant && i.featureConstant) return a({});
|
|
18403
|
+
let o = 0;
|
|
18404
|
+
for (let e of this.features) o = Math.max(o, a(e.props, e.id));
|
|
18405
|
+
return o;
|
|
18398
18406
|
}
|
|
18399
18407
|
placementFor(e) {
|
|
18400
18408
|
let t = e.geometry.type, n = this.config.placement === "auto" ? t === "Point" || t === "MultiPoint" ? "point" : t === "LineString" || t === "MultiLineString" ? "line" : t === "Polygon" || t === "MultiPolygon" ? "fill" : void 0 : this.config.placement;
|
|
@@ -18415,13 +18423,13 @@ ${y_}
|
|
|
18415
18423
|
continue;
|
|
18416
18424
|
}
|
|
18417
18425
|
if (c === "point") {
|
|
18418
|
-
a[i] = 0, o +=
|
|
18426
|
+
a[i] = 0, o += w_(s.geometry).length;
|
|
18419
18427
|
continue;
|
|
18420
18428
|
}
|
|
18421
|
-
let l = Math.max(
|
|
18429
|
+
let l = Math.max(i_, this.config.spacing(t, s.props, s.id, n));
|
|
18422
18430
|
a[i] = l;
|
|
18423
18431
|
let u = l * Vg((s.bbox.south + s.bbox.north) / 2);
|
|
18424
|
-
o += c === "fill" ? Xg(
|
|
18432
|
+
o += c === "fill" ? Xg(E_(s.geometry)) / (u * u) * G_(s.bbox, r) : Zg(T_(s.geometry)) / u;
|
|
18425
18433
|
}
|
|
18426
18434
|
if (o <= i) return {
|
|
18427
18435
|
cells: a,
|
|
@@ -18435,9 +18443,9 @@ ${y_}
|
|
|
18435
18443
|
}
|
|
18436
18444
|
batchFor(e, t) {
|
|
18437
18445
|
let n = this.batches.get(e);
|
|
18438
|
-
if (n && t <= n.capacity && (n.capacity <=
|
|
18446
|
+
if (n && t <= n.capacity && (n.capacity <= r_ || t * 4 >= n.capacity)) return n;
|
|
18439
18447
|
n && this.disposeBatch(e, n);
|
|
18440
|
-
let r = this.models.get(e), i = Math.max(
|
|
18448
|
+
let r = this.models.get(e), i = Math.max(r_, A_(t)), a = [], o;
|
|
18441
18449
|
this.instanceOpacity && (o = new bi(new Float32Array(i), 1));
|
|
18442
18450
|
for (let e of r.protos) {
|
|
18443
18451
|
let t = new Oi(e.geometry, e.material, i);
|
|
@@ -18504,7 +18512,7 @@ ${y_}
|
|
|
18504
18512
|
protos: []
|
|
18505
18513
|
};
|
|
18506
18514
|
this.models.set(e, n), this.loader.load(t, (e) => {
|
|
18507
|
-
this.disposed || (n.protos = this.flatten(e.scene), n.extent =
|
|
18515
|
+
this.disposed || (n.protos = this.flatten(e.scene), n.extent = N_(n.protos), n.state = "ready", this.schedule(!1, !0));
|
|
18508
18516
|
}, void 0, (r) => {
|
|
18509
18517
|
n.state = "error", console.error(`GltfLayer: failed to load model '${e}' (${t})`, r);
|
|
18510
18518
|
});
|
|
@@ -18524,15 +18532,15 @@ ${y_}
|
|
|
18524
18532
|
}
|
|
18525
18533
|
let i = Array.isArray(r.material) ? r.material : [r.material];
|
|
18526
18534
|
for (let e of i) this.patchMaterial(e);
|
|
18527
|
-
|
|
18535
|
+
U_(r.geometry, n), t.push({
|
|
18528
18536
|
geometry: r.geometry,
|
|
18529
18537
|
material: r.material,
|
|
18530
|
-
matrix:
|
|
18538
|
+
matrix: d_.clone().multiply(r.matrixWorld).multiply(d_)
|
|
18531
18539
|
});
|
|
18532
18540
|
}), this.config.doubleSided === void 0) {
|
|
18533
18541
|
let e = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
|
|
18534
18542
|
for (let r of t) {
|
|
18535
|
-
let t =
|
|
18543
|
+
let t = W_(r.geometry) <= o_;
|
|
18536
18544
|
for (let i of Array.isArray(r.material) ? r.material : [r.material]) n.add(i), t || e.add(i);
|
|
18537
18545
|
}
|
|
18538
18546
|
for (let t of n) t.side === 2 && !e.has(t) && (t.side = 0);
|
|
@@ -18552,11 +18560,11 @@ ${y_}
|
|
|
18552
18560
|
needsImpostors() {
|
|
18553
18561
|
let e = this.config.impostorDistance(this.map.getZoom(), {}, void 0, fu(this.map));
|
|
18554
18562
|
if (!Number.isFinite(e)) return !1;
|
|
18555
|
-
for (let [e, t] of this.models) if (t.state === "ready" && !e.startsWith("\0") && !this.models.has(
|
|
18563
|
+
for (let [e, t] of this.models) if (t.state === "ready" && !e.startsWith("\0") && !this.models.has(u_(e))) return !0;
|
|
18556
18564
|
return !1;
|
|
18557
18565
|
}
|
|
18558
18566
|
bakeImpostors(e, t) {
|
|
18559
|
-
for (let [n, r] of [...this.models]) r.state !== "ready" || n.startsWith("\0") || this.models.has(
|
|
18567
|
+
for (let [n, r] of [...this.models]) r.state !== "ready" || n.startsWith("\0") || this.models.has(u_(n)) || this.models.set(u_(n), this.bakeImpostor(e, r, t));
|
|
18560
18568
|
this.schedule(!1, !0);
|
|
18561
18569
|
}
|
|
18562
18570
|
bakeImpostor(e, t, n) {
|
|
@@ -18570,7 +18578,7 @@ ${y_}
|
|
|
18570
18578
|
}), n = new ni(e.geometry, Array.isArray(e.material) ? t : t[0]);
|
|
18571
18579
|
n.matrixAutoUpdate = !1, n.matrix.copy(e.matrix), i.add(n), e.geometry.computeBoundingBox(), a.union(e.geometry.boundingBox.clone().applyMatrix4(e.matrix));
|
|
18572
18580
|
}
|
|
18573
|
-
let s = a.getCenter(new H()), c = Math.max(a.max.x - a.min.x, a.max.z - a.min.z) / 2 || .5, l =
|
|
18581
|
+
let s = a.getCenter(new H()), c = Math.max(a.max.x - a.min.x, a.max.z - a.min.z) / 2 || .5, l = m_ * Math.PI / 180, u = c * 2 + (a.max.y - a.min.y) + 10, f = new bo(-1, 1, 1, -1, .1, u * 2);
|
|
18574
18582
|
f.position.set(s.x, s.y + Math.sin(l) * u, Math.cos(l) * u), f.lookAt(s.x, s.y, 0), f.updateMatrixWorld();
|
|
18575
18583
|
let p = new Zn(), m = new H();
|
|
18576
18584
|
for (let e of [s.x - c, s.x + c]) for (let t of [a.min.y, a.max.y]) for (let n of [-c, c]) p.expandByPoint(m.set(e, t, n).applyMatrix4(f.matrixWorldInverse));
|
|
@@ -18579,7 +18587,7 @@ ${y_}
|
|
|
18579
18587
|
r.add(new no(n.color, 10132122, n.ambient));
|
|
18580
18588
|
let v = new So(n.color, n.directional);
|
|
18581
18589
|
v.position.copy(n.direction).normalize().multiplyScalar(1e3), r.add(v, v.target), r.environment = n.environment, r.environmentIntensity = n.environmentIntensity;
|
|
18582
|
-
let y = new Zt(
|
|
18590
|
+
let y = new Zt(f_, Math.max(1, Math.round(f_ * g / h)), {
|
|
18583
18591
|
samples: 4,
|
|
18584
18592
|
colorSpace: Ue
|
|
18585
18593
|
});
|
|
@@ -18594,7 +18602,7 @@ ${y_}
|
|
|
18594
18602
|
alphaTest: .5
|
|
18595
18603
|
});
|
|
18596
18604
|
return C.alphaToCoverage = !0, C.onBeforeCompile = (e) => {
|
|
18597
|
-
e.uniforms.mtkRight = this.impostorRight, e.vertexShader = e.vertexShader.replace("#include <common>",
|
|
18605
|
+
e.uniforms.mtkRight = this.impostorRight, e.vertexShader = e.vertexShader.replace("#include <common>", h_).replace("#include <project_vertex>", g_), e.fragmentShader = e.fragmentShader.replace("#include <map_fragment>", p_);
|
|
18598
18606
|
}, this.patchMaterial(C), C.defines = {
|
|
18599
18607
|
...C.defines,
|
|
18600
18608
|
MTK_ALPHA_AFTER_TEST: ""
|
|
@@ -18627,7 +18635,7 @@ ${y_}
|
|
|
18627
18635
|
}, e.depthWrite = !0);
|
|
18628
18636
|
let t = e.onBeforeCompile;
|
|
18629
18637
|
e.onBeforeCompile = (n, r) => {
|
|
18630
|
-
t?.call(e, n, r), this.uniformOpacity && (n.uniforms.mtkOpacity = this.opacityUniform), n.vertexShader = n.vertexShader.replace("#include <color_pars_vertex>",
|
|
18638
|
+
t?.call(e, n, r), this.uniformOpacity && (n.uniforms.mtkOpacity = this.opacityUniform), n.vertexShader = n.vertexShader.replace("#include <color_pars_vertex>", __).replace("#include <color_vertex>", v_), n.fragmentShader = n.fragmentShader.replace("#include <color_pars_fragment>", y_).replace("#include <color_fragment>", x_).replace("#include <alphatest_fragment>", S_);
|
|
18631
18639
|
}, e.customProgramCacheKey = () => `mtk-gltf-${this.opacityKey}`, e.needsUpdate = !0;
|
|
18632
18640
|
}
|
|
18633
18641
|
get opacityKey() {
|
|
@@ -18651,19 +18659,19 @@ ${y_}
|
|
|
18651
18659
|
this.models.clear(), this.scene.remove(this.group);
|
|
18652
18660
|
}
|
|
18653
18661
|
};
|
|
18654
|
-
function
|
|
18662
|
+
function w_(e) {
|
|
18655
18663
|
return e.type === "Point" ? [e.coordinates] : e.coordinates;
|
|
18656
18664
|
}
|
|
18657
|
-
function
|
|
18665
|
+
function T_(e) {
|
|
18658
18666
|
return e.type === "LineString" ? [e.coordinates] : e.coordinates;
|
|
18659
18667
|
}
|
|
18660
|
-
function
|
|
18668
|
+
function E_(e) {
|
|
18661
18669
|
return e.type === "Polygon" ? [e.coordinates] : e.coordinates;
|
|
18662
18670
|
}
|
|
18663
|
-
function
|
|
18671
|
+
function D_(e) {
|
|
18664
18672
|
return e ? e.type === "LineString" || e.type === "MultiLineString" ? 2 : e.type === "Polygon" || e.type === "MultiPolygon" ? 3 : 1 : 1;
|
|
18665
18673
|
}
|
|
18666
|
-
function
|
|
18674
|
+
function O_(e) {
|
|
18667
18675
|
if (!e) return;
|
|
18668
18676
|
let t = {
|
|
18669
18677
|
west: Infinity,
|
|
@@ -18694,16 +18702,16 @@ function D_(e) {
|
|
|
18694
18702
|
}
|
|
18695
18703
|
return n ? t : void 0;
|
|
18696
18704
|
}
|
|
18697
|
-
function
|
|
18705
|
+
function k_(e) {
|
|
18698
18706
|
let t = e;
|
|
18699
18707
|
return t?.type === "FeatureCollection" ? t.features ?? [] : t?.type === "Feature" ? [t] : [];
|
|
18700
18708
|
}
|
|
18701
|
-
function
|
|
18709
|
+
function A_(e) {
|
|
18702
18710
|
let t = 1;
|
|
18703
18711
|
for (; t < e;) t *= 2;
|
|
18704
18712
|
return t;
|
|
18705
18713
|
}
|
|
18706
|
-
function
|
|
18714
|
+
function j_(e) {
|
|
18707
18715
|
let n = t.fromLngLat(e, 0);
|
|
18708
18716
|
return {
|
|
18709
18717
|
x: n.x,
|
|
@@ -18712,7 +18720,7 @@ function A_(e) {
|
|
|
18712
18720
|
s: n.meterInMercatorCoordinateUnits()
|
|
18713
18721
|
};
|
|
18714
18722
|
}
|
|
18715
|
-
function
|
|
18723
|
+
function M_(e, t) {
|
|
18716
18724
|
if (!(t > 0)) return e;
|
|
18717
18725
|
let n = t / 111320, r = n / Math.max(.01, Math.cos((e.north + e.south) / 2 * Math.PI / 180));
|
|
18718
18726
|
return {
|
|
@@ -18722,7 +18730,7 @@ function j_(e, t) {
|
|
|
18722
18730
|
north: e.north + n
|
|
18723
18731
|
};
|
|
18724
18732
|
}
|
|
18725
|
-
function
|
|
18733
|
+
function N_(e) {
|
|
18726
18734
|
let t = new Zn();
|
|
18727
18735
|
for (let n of e) n.geometry.boundingBox || n.geometry.computeBoundingBox(), t.union(n.geometry.boundingBox.clone().applyMatrix4(n.matrix));
|
|
18728
18736
|
if (t.isEmpty()) return;
|
|
@@ -18734,7 +18742,7 @@ function M_(e) {
|
|
|
18734
18742
|
top: t.max.y
|
|
18735
18743
|
};
|
|
18736
18744
|
}
|
|
18737
|
-
function
|
|
18745
|
+
function P_(e, t) {
|
|
18738
18746
|
let n = -1 - 2 * t, r = 1 + 2 * t;
|
|
18739
18747
|
return (t, i, a, o, s) => {
|
|
18740
18748
|
let c = Infinity, l = -Infinity, u = Infinity, d = -Infinity, f = !1, p = !1;
|
|
@@ -18751,8 +18759,8 @@ function N_(e, t) {
|
|
|
18751
18759
|
return p ? f ? !0 : l >= n && c <= r && d >= n && u <= 1 : !1;
|
|
18752
18760
|
};
|
|
18753
18761
|
}
|
|
18754
|
-
function
|
|
18755
|
-
let t = e.getBounds(), n = (t.getEast() - t.getWest()) *
|
|
18762
|
+
function F_(e) {
|
|
18763
|
+
let t = e.getBounds(), n = (t.getEast() - t.getWest()) * t_, r = (t.getNorth() - t.getSouth()) * t_;
|
|
18756
18764
|
return {
|
|
18757
18765
|
west: t.getWest() - n,
|
|
18758
18766
|
east: t.getEast() + n,
|
|
@@ -18760,13 +18768,13 @@ function P_(e) {
|
|
|
18760
18768
|
north: t.getNorth() + r
|
|
18761
18769
|
};
|
|
18762
18770
|
}
|
|
18763
|
-
function
|
|
18771
|
+
function I_(e) {
|
|
18764
18772
|
return Gg(e | 0, 20973) / 4294967296;
|
|
18765
18773
|
}
|
|
18766
|
-
function
|
|
18767
|
-
return e / (t * (1 - Math.log2(
|
|
18774
|
+
function L_(e, t, n) {
|
|
18775
|
+
return e / (t * (1 - Math.log2(I_(n))));
|
|
18768
18776
|
}
|
|
18769
|
-
function
|
|
18777
|
+
function R_(e, t) {
|
|
18770
18778
|
let n = 0;
|
|
18771
18779
|
for (let t of e) t.need < 1 && n++;
|
|
18772
18780
|
if (n <= t) return 1;
|
|
@@ -18774,13 +18782,13 @@ function L_(e, t) {
|
|
|
18774
18782
|
for (let t = 0; t < e.length; t++) r[t] = e[t].need;
|
|
18775
18783
|
return r.sort(), r[t];
|
|
18776
18784
|
}
|
|
18777
|
-
function
|
|
18785
|
+
function z_(e) {
|
|
18778
18786
|
return (180 + e) / 360;
|
|
18779
18787
|
}
|
|
18780
|
-
function
|
|
18788
|
+
function B_(e) {
|
|
18781
18789
|
return (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + e * Math.PI / 360))) / 360;
|
|
18782
18790
|
}
|
|
18783
|
-
function
|
|
18791
|
+
function V_(e, t) {
|
|
18784
18792
|
let n = e, r = n.transform ?? n._camera?.transform, i = e.terrain ? r?._pixelMatrix3D : r?._pixelMatrix;
|
|
18785
18793
|
if (!r || !i || !r.worldSize) return;
|
|
18786
18794
|
let a = e.terrain ? r.elevation ?? 0 : 0, o = r.worldSize, s = r.width * t, c = r.height * t;
|
|
@@ -18791,7 +18799,7 @@ function B_(e, t) {
|
|
|
18791
18799
|
return d >= -s && d <= r.width + s && f >= 0 && f <= r.height + c;
|
|
18792
18800
|
};
|
|
18793
18801
|
}
|
|
18794
|
-
function
|
|
18802
|
+
function H_(e, t, n, r) {
|
|
18795
18803
|
let i = e, a = i.transform ?? i._camera?.transform, o = e.terrain ? a?._pixelMatrix3D : a?._pixelMatrix;
|
|
18796
18804
|
if (!a || !o || !a.worldSize) return;
|
|
18797
18805
|
let s = new G().fromArray(Array.from(o)).invert(), c = e.terrain ? a.elevation ?? 0 : 0, l = a.worldSize, u = new Yt(), d = new Yt(), f = (e, t) => {
|
|
@@ -18824,7 +18832,7 @@ function V_(e, t, n, r) {
|
|
|
18824
18832
|
return n <= r ? [n, r] : null;
|
|
18825
18833
|
};
|
|
18826
18834
|
}
|
|
18827
|
-
function
|
|
18835
|
+
function U_(e, t) {
|
|
18828
18836
|
let n = (e, t) => !e.has(t) && !!e.add(t);
|
|
18829
18837
|
for (let r of [
|
|
18830
18838
|
"position",
|
|
@@ -18846,7 +18854,7 @@ function H_(e, t) {
|
|
|
18846
18854
|
}
|
|
18847
18855
|
e.boundingBox = null, e.boundingSphere = null;
|
|
18848
18856
|
}
|
|
18849
|
-
function
|
|
18857
|
+
function W_(e) {
|
|
18850
18858
|
let t = e.getAttribute("position");
|
|
18851
18859
|
if (!t) return 1;
|
|
18852
18860
|
let n = e.getIndex(), r = n ? n.count : t.count;
|
|
@@ -18873,13 +18881,13 @@ function U_(e) {
|
|
|
18873
18881
|
for (let e of s.values()) e !== 0 && l++;
|
|
18874
18882
|
return l / s.size;
|
|
18875
18883
|
}
|
|
18876
|
-
function
|
|
18884
|
+
function G_(e, t) {
|
|
18877
18885
|
let n = Math.min(e.east, t.east) - Math.max(e.west, t.west), r = Math.min(e.north, t.north) - Math.max(e.south, t.south);
|
|
18878
18886
|
if (n <= 0 || r <= 0) return 0;
|
|
18879
18887
|
let i = (e.east - e.west) * (e.north - e.south);
|
|
18880
18888
|
return i > 0 ? Math.min(1, n * r / i) : 1;
|
|
18881
18889
|
}
|
|
18882
|
-
function
|
|
18890
|
+
function K_(e) {
|
|
18883
18891
|
let n = e, r = (n.transform ?? n._camera?.transform)?.getCameraLngLat?.() ?? e.getCenter(), i = t.fromLngLat(r, 0);
|
|
18884
18892
|
return {
|
|
18885
18893
|
x: i.x,
|
|
@@ -18887,7 +18895,7 @@ function G_(e) {
|
|
|
18887
18895
|
s: i.meterInMercatorCoordinateUnits()
|
|
18888
18896
|
};
|
|
18889
18897
|
}
|
|
18890
|
-
function
|
|
18898
|
+
function q_(e) {
|
|
18891
18899
|
let t = {
|
|
18892
18900
|
west: 180,
|
|
18893
18901
|
east: -180,
|
|
@@ -18897,16 +18905,16 @@ function K_(e) {
|
|
|
18897
18905
|
for (let n of e) n.lng < t.west && (t.west = n.lng), n.lng > t.east && (t.east = n.lng), n.lat < t.south && (t.south = n.lat), n.lat > t.north && (t.north = n.lat);
|
|
18898
18906
|
return t;
|
|
18899
18907
|
}
|
|
18900
|
-
function
|
|
18908
|
+
function J_(e, t) {
|
|
18901
18909
|
return e.west <= t.east && e.east >= t.west && e.south <= t.north && e.north >= t.south;
|
|
18902
18910
|
}
|
|
18903
18911
|
//#endregion
|
|
18904
18912
|
//#region src/GltfLayer.ts
|
|
18905
|
-
var
|
|
18913
|
+
var Y_ = 1, X_ = {
|
|
18906
18914
|
ambient: 1.5,
|
|
18907
18915
|
directional: 2.5,
|
|
18908
18916
|
environment: .7
|
|
18909
|
-
},
|
|
18917
|
+
}, Z_ = 25, Q_ = 2e4, $_ = [
|
|
18910
18918
|
"interpolate",
|
|
18911
18919
|
["exponential", .5],
|
|
18912
18920
|
["zoom"],
|
|
@@ -18914,7 +18922,7 @@ var J_ = 1, Y_ = {
|
|
|
18914
18922
|
4e4,
|
|
18915
18923
|
20,
|
|
18916
18924
|
156.25
|
|
18917
|
-
],
|
|
18925
|
+
], ev = [
|
|
18918
18926
|
"interpolate",
|
|
18919
18927
|
["exponential", .5],
|
|
18920
18928
|
["zoom"],
|
|
@@ -18922,12 +18930,12 @@ var J_ = 1, Y_ = {
|
|
|
18922
18930
|
12800,
|
|
18923
18931
|
20,
|
|
18924
18932
|
50
|
|
18925
|
-
],
|
|
18933
|
+
], tv = [
|
|
18926
18934
|
"auto",
|
|
18927
18935
|
"point",
|
|
18928
18936
|
"line",
|
|
18929
18937
|
"fill"
|
|
18930
|
-
],
|
|
18938
|
+
], nv = class {
|
|
18931
18939
|
id;
|
|
18932
18940
|
type = "custom";
|
|
18933
18941
|
renderingMode = "3d";
|
|
@@ -18958,11 +18966,11 @@ var J_ = 1, Y_ = {
|
|
|
18958
18966
|
if (!e.source) throw Error("GltfLayer: `source` (a source id) is required");
|
|
18959
18967
|
if (!e.models || Object.keys(e.models).length === 0) throw Error("GltfLayer: `models` must hold at least one { id: url } entry");
|
|
18960
18968
|
this.id = e.id, this.minzoom = e.minzoom, this.maxzoom = e.maxzoom, this.options = e, this.visible = e.layout?.visibility !== "none", this.lighting = {
|
|
18961
|
-
...
|
|
18969
|
+
...X_,
|
|
18962
18970
|
...e.lighting
|
|
18963
18971
|
};
|
|
18964
18972
|
let t = e.layout?.["model-placement"] ?? "auto";
|
|
18965
|
-
if (!
|
|
18973
|
+
if (!tv.includes(t)) throw Error(`GltfLayer: model-placement must be one of ${tv.join(", ")} — got '${t}'`);
|
|
18966
18974
|
this.placement = t;
|
|
18967
18975
|
}
|
|
18968
18976
|
onAdd(t, n) {
|
|
@@ -18974,42 +18982,42 @@ var J_ = 1, Y_ = {
|
|
|
18974
18982
|
antialias: !0
|
|
18975
18983
|
}), this.renderer.autoClear = !1;
|
|
18976
18984
|
let i = this.options.paint ?? {}, a = this.options.layout ?? {}, o = Object.keys(this.options.models);
|
|
18977
|
-
this.manager = new
|
|
18985
|
+
this.manager = new C_(t, this.scene, e.convert(t.getCenter()), r, {
|
|
18978
18986
|
sourceId: this.options.source,
|
|
18979
18987
|
sourceLayer: this.options["source-layer"],
|
|
18980
18988
|
filter: this.options.filter,
|
|
18981
18989
|
minzoom: this.options.minzoom,
|
|
18982
18990
|
maxzoom: this.options.maxzoom,
|
|
18983
18991
|
models: this.options.models,
|
|
18984
|
-
modelId: yh(a["model-id"], "model-id", o[0],
|
|
18992
|
+
modelId: yh(a["model-id"], "model-id", o[0], Y_),
|
|
18985
18993
|
placement: this.placement,
|
|
18986
|
-
spacing: vh(a["model-spacing"], "model-spacing",
|
|
18987
|
-
thinningDistance: vh(a["model-thinning-distance"] ??
|
|
18988
|
-
impostorDistance: vh(a["model-impostor-distance"] ??
|
|
18989
|
-
maxInstances: this.options.maxInstances ??
|
|
18994
|
+
spacing: vh(a["model-spacing"], "model-spacing", Z_, Y_),
|
|
18995
|
+
thinningDistance: vh(a["model-thinning-distance"] ?? $_, "model-thinning-distance", Infinity, Y_),
|
|
18996
|
+
impostorDistance: vh(a["model-impostor-distance"] ?? ev, "model-impostor-distance", Infinity, Y_),
|
|
18997
|
+
maxInstances: this.options.maxInstances ?? Q_,
|
|
18990
18998
|
doubleSided: this.options.doubleSided,
|
|
18991
18999
|
rotation: bh(i["model-rotation"], "model-rotation", [
|
|
18992
19000
|
0,
|
|
18993
19001
|
0,
|
|
18994
19002
|
0
|
|
18995
|
-
],
|
|
19003
|
+
], Y_),
|
|
18996
19004
|
scale: bh(i["model-scale"], "model-scale", [
|
|
18997
19005
|
1,
|
|
18998
19006
|
1,
|
|
18999
19007
|
1
|
|
19000
|
-
],
|
|
19008
|
+
], Y_),
|
|
19001
19009
|
translation: bh(i["model-translation"], "model-translation", [
|
|
19002
19010
|
0,
|
|
19003
19011
|
0,
|
|
19004
19012
|
0
|
|
19005
|
-
],
|
|
19013
|
+
], Y_),
|
|
19006
19014
|
color: i["model-color"] === void 0 ? void 0 : _h(i["model-color"], "model-color", [
|
|
19007
19015
|
1,
|
|
19008
19016
|
1,
|
|
19009
19017
|
1,
|
|
19010
19018
|
1
|
|
19011
|
-
],
|
|
19012
|
-
opacity: i["model-opacity"] === void 0 ? void 0 : vh(i["model-opacity"], "model-opacity", 1,
|
|
19019
|
+
], Y_),
|
|
19020
|
+
opacity: i["model-opacity"] === void 0 ? void 0 : vh(i["model-opacity"], "model-opacity", 1, Y_)
|
|
19013
19021
|
});
|
|
19014
19022
|
}
|
|
19015
19023
|
render(e, t) {
|
|
@@ -19060,4 +19068,4 @@ var J_ = 1, Y_ = {
|
|
|
19060
19068
|
}
|
|
19061
19069
|
};
|
|
19062
19070
|
//#endregion
|
|
19063
|
-
export { wh as Fill3DLayer,
|
|
19071
|
+
export { wh as Fill3DLayer, nv as GltfLayer };
|
|
@@ -49,7 +49,9 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
49
49
|
let e = document.createElement("button");
|
|
50
50
|
e.type = "button", e.className = "maplibre-scene3d-control-toggle", e.title = "3D", e.setAttribute("aria-label", "3D"), e.innerHTML = r, e.addEventListener("click", () => this.setEnabled(!this.enabled)), t.appendChild(e), this.button = e, this.showState();
|
|
51
51
|
} else t.classList.add("maplibre-scene3d-control-hidden");
|
|
52
|
-
|
|
52
|
+
this.container = t;
|
|
53
|
+
let n = e.getCanvas?.(), a = n?.getContext?.("webgl2") ?? n?.getContext?.("webgl");
|
|
54
|
+
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;
|
|
53
55
|
}
|
|
54
56
|
onRemove() {
|
|
55
57
|
let e = this.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","Scene3dControl","Evented","rest","options","v","container","button","response","enabled","lib","err","next","l","id","pitch","sheet","generation","position","anchor","before","source","p","place","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/**\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 /** `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 /** 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 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 /** 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 (!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 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 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 before(scene.fill3d.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 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.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,sBA4F9BC,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,MAEz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AAK,cAAc,KAAA;EACrB;CACF;CAEA,kBAA0B;EACxB,IAAMzC,IAAM,KAAK;EACjB,KAAK,IAAMmB,KAAM,KAAK,QAAQ,YAC5B,AAAKnB,EAAI,SAASmB,CAAE,MACpB,KAAK,OAAO,IAAIA,GAAKnB,EAAI,kBAAkBmB,GAAI,YAAY,KAAwC,SAAS,GAC5GnB,EAAI,kBAAkBmB,GAAI,cAAc,MAAM;CAElD;CAEA,QAAgB,GAAqB;EACnC,IAAI,CAAC,KAAK,QAAQ,QAAQ,OAAOwB;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","canvas","gl","response","enabled","lib","err","next","l","id","pitch","sheet","generation","position","anchor","before","source","p","place","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/**\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 /** `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 /** 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)) || (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 /** 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 (!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 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 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 before(scene.fill3d.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 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.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,sBA4F9BC,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,iCAAyB,IAAI,IAA6B;CAE1D,aAAoC;CAEpC,YAAY,IAAiC,CAAC,GAAG;EAC/C,MAAM;EACN,IAAM,EAAE,UAAO,GAAGC,MAASC;EAO3B,AANA,KAAK,UAAU;GACb,GAAGZ;GACH,eAAe,OAAO;GACtB,GAAG,OAAO,YAAY,OAAO,QAAQW,CAAI,CAAC,CAAC,QAAQ,GAAGE,OAAOA,MAAM,KAAA,CAAS,CAAC;EAC/E,GACA,KAAK,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AAK,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"}
|
|
@@ -49,7 +49,9 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
49
49
|
let e = document.createElement("button");
|
|
50
50
|
e.type = "button", e.className = "maplibre-scene3d-control-toggle", e.title = "3D", e.setAttribute("aria-label", "3D"), e.innerHTML = r, e.addEventListener("click", () => this.setEnabled(!this.enabled)), t.appendChild(e), this.button = e, this.showState();
|
|
51
51
|
} else t.classList.add("maplibre-scene3d-control-hidden");
|
|
52
|
-
|
|
52
|
+
this.container = t;
|
|
53
|
+
let n = e.getCanvas?.(), a = n?.getContext?.("webgl2") ?? n?.getContext?.("webgl");
|
|
54
|
+
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;
|
|
53
55
|
}
|
|
54
56
|
onRemove() {
|
|
55
57
|
let e = this.map;
|
|
@@ -266,7 +268,7 @@ var t = "maptoolkit:scene3d", n = {
|
|
|
266
268
|
}
|
|
267
269
|
}, l = () => import(
|
|
268
270
|
/* @vite-ignore */
|
|
269
|
-
new URL("./maplibre-3d-layers-0.5.
|
|
271
|
+
new URL("./maplibre-3d-layers-0.5.6.standalone.mjs", import.meta.url).href
|
|
270
272
|
), u = class extends c {
|
|
271
273
|
constructor(e = {}) {
|
|
272
274
|
super({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maplibre-scene3d-control.standalone.js","names":["Scene3dControl","BaseControl","SCENE3D_METADATA_KEY","DEFAULTS","CUBE_ICON","styleOf","map","sceneKeyOf","scene","terrainKeyOf","terrain","hasBuildings","Scene3dControl$1","Evented","rest","options","v","container","button","response","enabled","lib","err","next","l","id","pitch","sheet","generation","position","anchor","before","source","p","place","lod1","add","layer","fill3d","library","entry","ids","picked","models","m","restore","visibility","onData","e","url","u","key","message","bundledLibrary","Scene3dControl"],"sources":["../src/Scene3dControl.ts","../src/standalone.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 /** `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 /** 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 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 /** 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 (!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 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 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 before(scene.fill3d.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 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.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","// The standalone build: the control together with the 3D library it was built against, which lies next to it in\n// dist/. A page without a bundler imports only this file (plus an import map for \"maplibre-gl\", like every MapLibre 6\n// plugin) and passes no `library`. The library is fetched relative to this file once the map reaches `minzoom`; its\n// file name carries its version, so a new release is a new URL for every cache.\nimport { Scene3dControl as BaseControl, type Scene3dControlOptions, type Scene3dLibrary } from \"./Scene3dControl\";\n\n/**\n * Loads the standalone build of maplibre-3d-layers (three.js included) that ships next to this file. A concatenated\n * string, not a template literal: Vite turns `new URL(\\`./${...}\\`, import.meta.url)` into a glob over src/.\n */\nexport const bundledLibrary = (): Promise<Scene3dLibrary> =>\n import(/* @vite-ignore */ new URL(\"./\" + __BUNDLED_LIBRARY__, import.meta.url).href) as Promise<Scene3dLibrary>;\n\n/** The control, loading the bundled 3D library unless `library` names another one. */\nexport class Scene3dControl extends BaseControl {\n constructor(options: Scene3dControlOptions = {}) {\n super({ ...options, library: options.library ?? bundledLibrary });\n }\n}\n\nexport { SCENE3D_METADATA_KEY } from \"./Scene3dControl\";\nexport type { Scene3dControlOptions, Scene3dManifest, Scene3dGltfLayer, Scene3dLibrary, Scene3dPosition, Scene3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CrD,EAAY;CAC9C,YAAY,IAAiC,CAAC,GAAG;EAC/C,MAAM;GAAE,GAAGc;GAAS,SAASA,EAAQ,WAAWsC;EAAe,CAAC;CAClE;AACF"}
|
|
1
|
+
{"version":3,"file":"maplibre-scene3d-control.standalone.js","names":["Scene3dControl","BaseControl","SCENE3D_METADATA_KEY","DEFAULTS","CUBE_ICON","styleOf","map","sceneKeyOf","scene","terrainKeyOf","terrain","hasBuildings","Scene3dControl$1","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","fill3d","library","entry","ids","picked","models","m","restore","visibility","onData","e","url","u","key","message","bundledLibrary","Scene3dControl"],"sources":["../src/Scene3dControl.ts","../src/standalone.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 /** `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 /** 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)) || (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 /** 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 (!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 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 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 before(scene.fill3d.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 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.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","// The standalone build: the control together with the 3D library it was built against, which lies next to it in\n// dist/. A page without a bundler imports only this file (plus an import map for \"maplibre-gl\", like every MapLibre 6\n// plugin) and passes no `library`. The library is fetched relative to this file once the map reaches `minzoom`; its\n// file name carries its version, so a new release is a new URL for every cache.\nimport { Scene3dControl as BaseControl, type Scene3dControlOptions, type Scene3dLibrary } from \"./Scene3dControl\";\n\n/**\n * Loads the standalone build of maplibre-3d-layers (three.js included) that ships next to this file. A concatenated\n * string, not a template literal: Vite turns `new URL(\\`./${...}\\`, import.meta.url)` into a glob over src/.\n */\nexport const bundledLibrary = (): Promise<Scene3dLibrary> =>\n import(/* @vite-ignore */ new URL(\"./\" + __BUNDLED_LIBRARY__, import.meta.url).href) as Promise<Scene3dLibrary>;\n\n/** The control, loading the bundled 3D library unless `library` names another one. */\nexport class Scene3dControl extends BaseControl {\n constructor(options: Scene3dControlOptions = {}) {\n super({ ...options, library: options.library ?? bundledLibrary });\n }\n}\n\nexport { SCENE3D_METADATA_KEY } from \"./Scene3dControl\";\nexport type { Scene3dControlOptions, Scene3dManifest, Scene3dGltfLayer, Scene3dLibrary, Scene3dPosition, Scene3dControlEventType } from \"./Scene3dControl\";\n"],"mappings":";;AAIA,IAAaE,IAAuB,sBA4F9BC,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,SAW3DR,IAAb,cAAoCa,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,GAAGZ;GACH,eAAe,OAAO;GACtB,GAAG,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,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,GCxkBaC,UACX;;CAA0B,IAAI,IAAI,6CAA4B,YAAY,GAAG,CAAC,CAAC;GAGpEC,IAAb,cAAoCvD,EAAY;CAC9C,YAAY,IAAiC,CAAC,GAAG;EAC/C,MAAM;GAAE,GAAGc;GAAS,SAASA,EAAQ,WAAWwC;EAAe,CAAC;CAClE;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maptoolkit/maplibre-scene3d-control",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A MapLibre GL JS control plugin that adds the 3D scene of a Maptoolkit style: 3D buildings and glTF vegetation.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"maplibre-gl": ">=6.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@maptoolkit/maplibre-3d-layers": "^0.5.
|
|
52
|
+
"@maptoolkit/maplibre-3d-layers": "^0.5.6",
|
|
53
53
|
"three": ">=0.160.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|