maplibre-gl-3d-tiles 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,6 +39,7 @@ const map = new maplibregl.Map({
39
39
  map.on('load', () => {
40
40
  const control = new ThreeDTilesControl({
41
41
  collapsed: false,
42
+ layerName: 'AGI Headquarters',
42
43
  tilesetUrl: 'https://pelican-public.s3.amazonaws.com/3dtiles/agi-hq/tileset.json',
43
44
  altitudeOffset: -300,
44
45
  });
@@ -46,6 +47,8 @@ map.on('load', () => {
46
47
  map.addControl(control, 'top-right');
47
48
  void control.loadTileset();
48
49
  void control.loadTileset('https://example.com/another/tileset.json', {
50
+ layerName: 'Second tileset',
51
+ beforeId: 'place-labels',
49
52
  altitudeOffset: 0,
50
53
  });
51
54
  });
@@ -108,6 +111,8 @@ Constructor options include:
108
111
  | Option | Type | Default |
109
112
  | --- | --- | --- |
110
113
  | `tilesetUrl` | `string` | MapLibre example tileset |
114
+ | `layerName` | `string` | `3D Tiles` |
115
+ | `beforeId` | `string` | `undefined` |
111
116
  | `altitudeOffset` | `number` | `-300` |
112
117
  | `flyToOnLoad` | `boolean` | `true` |
113
118
  | `visible` | `boolean` | `true` |
@@ -37054,6 +37054,8 @@ const DEFAULT_OPTIONS = {
37054
37054
  collapseOnClickOutside: true,
37055
37055
  layerId: "maplibre-gl-3d-tiles",
37056
37056
  tilesetUrl: DEFAULT_TILESET_URL,
37057
+ layerName: "3D Tiles",
37058
+ beforeId: void 0,
37057
37059
  altitudeOffset: -300,
37058
37060
  flyToOnLoad: true,
37059
37061
  opacity: 1,
@@ -37068,7 +37070,9 @@ class ThreeDTilesControl {
37068
37070
  __publicField(this, "_container");
37069
37071
  __publicField(this, "_panel");
37070
37072
  __publicField(this, "_content");
37073
+ __publicField(this, "_layerNameInput");
37071
37074
  __publicField(this, "_urlInput");
37075
+ __publicField(this, "_beforeIdInput");
37072
37076
  __publicField(this, "_altitudeInput");
37073
37077
  __publicField(this, "_flyToCheckbox");
37074
37078
  __publicField(this, "_visibleCheckbox");
@@ -37089,6 +37093,8 @@ class ThreeDTilesControl {
37089
37093
  collapsed: this._options.collapsed,
37090
37094
  panelWidth: this._options.panelWidth,
37091
37095
  tilesetUrl: this._options.tilesetUrl,
37096
+ layerName: this._options.layerName,
37097
+ beforeId: this._options.beforeId,
37092
37098
  altitudeOffset: this._options.altitudeOffset,
37093
37099
  flyToOnLoad: this._options.flyToOnLoad,
37094
37100
  opacity: this._options.opacity,
@@ -37162,11 +37168,15 @@ class ThreeDTilesControl {
37162
37168
  const flyToOnLoad = (options == null ? void 0 : options.flyToOnLoad) ?? Boolean((_a2 = this._flyToCheckbox) == null ? void 0 : _a2.checked);
37163
37169
  const opacity = (options == null ? void 0 : options.opacity) ?? this._state.opacity;
37164
37170
  const visible = (options == null ? void 0 : options.visible) ?? Boolean((_b = this._visibleCheckbox) == null ? void 0 : _b.checked);
37171
+ const layerName = (options == null ? void 0 : options.layerName) ?? this._getLayerName();
37172
+ const beforeId = (options == null ? void 0 : options.beforeId) ?? this._getBeforeId();
37165
37173
  const id = this._createTilesetId();
37166
37174
  const layerId = this._createLayerId(id);
37167
37175
  const item = {
37168
37176
  id,
37169
37177
  layerId,
37178
+ layerName,
37179
+ beforeId,
37170
37180
  tilesetUrl: url,
37171
37181
  altitudeOffset,
37172
37182
  opacity,
@@ -37176,6 +37186,8 @@ class ThreeDTilesControl {
37176
37186
  this._state = {
37177
37187
  ...this._state,
37178
37188
  tilesetUrl: url,
37189
+ layerName,
37190
+ beforeId,
37179
37191
  altitudeOffset,
37180
37192
  flyToOnLoad,
37181
37193
  opacity,
@@ -37206,7 +37218,7 @@ class ThreeDTilesControl {
37206
37218
  this._layers.set(id, layer);
37207
37219
  await this._waitForStyle();
37208
37220
  if (!this._map || !this._layers.has(id)) return void 0;
37209
- this._map.addLayer(layer);
37221
+ this._map.addLayer(layer, beforeId);
37210
37222
  return id;
37211
37223
  }
37212
37224
  removeTileset(id, emit = true) {
@@ -37230,6 +37242,8 @@ class ThreeDTilesControl {
37230
37242
  altitude: activeTileset == null ? void 0 : activeTileset.altitude,
37231
37243
  visible: (activeTileset == null ? void 0 : activeTileset.visible) ?? this._state.visible,
37232
37244
  tilesetUrl: (activeTileset == null ? void 0 : activeTileset.tilesetUrl) ?? this._state.tilesetUrl,
37245
+ layerName: (activeTileset == null ? void 0 : activeTileset.layerName) ?? this._state.layerName,
37246
+ beforeId: activeTileset == null ? void 0 : activeTileset.beforeId,
37233
37247
  altitudeOffset: (activeTileset == null ? void 0 : activeTileset.altitudeOffset) ?? this._state.altitudeOffset,
37234
37248
  opacity: (activeTileset == null ? void 0 : activeTileset.opacity) ?? this._state.opacity,
37235
37249
  activeTilesetId: activeTileset == null ? void 0 : activeTileset.id,
@@ -37380,7 +37394,9 @@ class ThreeDTilesControl {
37380
37394
  event.preventDefault();
37381
37395
  void this.loadTileset();
37382
37396
  });
37397
+ this._layerNameInput = this._createInput("Layer name", "text", this._state.layerName);
37383
37398
  this._urlInput = this._createInput("Tileset URL", "url", this._state.tilesetUrl);
37399
+ this._beforeIdInput = this._createInput("Before layer ID", "text", this._state.beforeId ?? "");
37384
37400
  this._altitudeInput = this._createInput(
37385
37401
  "Altitude offset",
37386
37402
  "number",
@@ -37401,6 +37417,8 @@ class ThreeDTilesControl {
37401
37417
  this._tilesetList = document.createElement("div");
37402
37418
  this._tilesetList.className = "three-d-tiles-list";
37403
37419
  form.appendChild(this._wrapField("Tileset URL", this._urlInput));
37420
+ form.appendChild(this._wrapField("Layer name", this._layerNameInput));
37421
+ form.appendChild(this._wrapField("Before layer ID", this._beforeIdInput));
37404
37422
  form.appendChild(this._wrapField("Altitude offset", this._altitudeInput));
37405
37423
  form.appendChild(this._flyToCheckbox.parentElement);
37406
37424
  form.appendChild(this._visibleCheckbox.parentElement);
@@ -37464,7 +37482,7 @@ class ThreeDTilesControl {
37464
37482
  const title = document.createElement("button");
37465
37483
  title.className = "three-d-tiles-list-title";
37466
37484
  title.type = "button";
37467
- title.textContent = `Tileset ${index + 1}`;
37485
+ title.textContent = tileset.layerName || `Tileset ${index + 1}`;
37468
37486
  title.addEventListener("click", () => this._setActiveTileset(tileset.id));
37469
37487
  const url = document.createElement("span");
37470
37488
  url.className = "three-d-tiles-list-url";
@@ -37472,7 +37490,7 @@ class ThreeDTilesControl {
37472
37490
  const status = document.createElement("span");
37473
37491
  status.className = "three-d-tiles-list-status";
37474
37492
  status.dataset.status = tileset.status;
37475
- status.textContent = tileset.error ?? tileset.status;
37493
+ status.textContent = tileset.error ?? this._formatTilesetStatus(tileset);
37476
37494
  meta.appendChild(title);
37477
37495
  meta.appendChild(url);
37478
37496
  meta.appendChild(status);
@@ -37588,6 +37606,16 @@ class ThreeDTilesControl {
37588
37606
  const value = Number(((_a = this._altitudeInput) == null ? void 0 : _a.value) ?? this._state.altitudeOffset);
37589
37607
  return Number.isFinite(value) ? value : this._state.altitudeOffset;
37590
37608
  }
37609
+ _getLayerName() {
37610
+ var _a;
37611
+ const value = ((_a = this._layerNameInput) == null ? void 0 : _a.value.trim()) || this._state.layerName;
37612
+ return value || "3D Tiles";
37613
+ }
37614
+ _getBeforeId() {
37615
+ var _a;
37616
+ const value = ((_a = this._beforeIdInput) == null ? void 0 : _a.value.trim()) || this._state.beforeId;
37617
+ return value || void 0;
37618
+ }
37591
37619
  _handleTilesetLoaded(id, metadata) {
37592
37620
  if (!this._layers.has(id)) return;
37593
37621
  this._state = {
@@ -37633,6 +37661,8 @@ class ThreeDTilesControl {
37633
37661
  }
37634
37662
  _syncFormFromState() {
37635
37663
  if (this._urlInput) this._urlInput.value = this._state.tilesetUrl;
37664
+ if (this._layerNameInput) this._layerNameInput.value = this._state.layerName;
37665
+ if (this._beforeIdInput) this._beforeIdInput.value = this._state.beforeId ?? "";
37636
37666
  if (this._altitudeInput) this._altitudeInput.value = String(this._state.altitudeOffset);
37637
37667
  if (this._flyToCheckbox) this._flyToCheckbox.checked = this._state.flyToOnLoad;
37638
37668
  if (this._visibleCheckbox) this._visibleCheckbox.checked = this._state.visible;
@@ -37663,6 +37693,8 @@ class ThreeDTilesControl {
37663
37693
  this._state = {
37664
37694
  ...this._state,
37665
37695
  tilesetUrl: activeTileset.tilesetUrl,
37696
+ layerName: activeTileset.layerName,
37697
+ beforeId: activeTileset.beforeId,
37666
37698
  altitudeOffset: activeTileset.altitudeOffset,
37667
37699
  opacity: activeTileset.opacity,
37668
37700
  visible: activeTileset.visible,
@@ -37678,6 +37710,12 @@ class ThreeDTilesControl {
37678
37710
  _getTileset(id) {
37679
37711
  return this._state.tilesets.find((tileset) => tileset.id === id);
37680
37712
  }
37713
+ _formatTilesetStatus(tileset) {
37714
+ if (tileset.beforeId) {
37715
+ return `${tileset.status} before ${tileset.beforeId}`;
37716
+ }
37717
+ return tileset.status;
37718
+ }
37681
37719
  _createTilesetId() {
37682
37720
  this._tilesetCounter += 1;
37683
37721
  return `tileset-${this._tilesetCounter}`;
@@ -37697,4 +37735,4 @@ exports.DEFAULT_TILESET_URL = DEFAULT_TILESET_URL;
37697
37735
  exports.ThreeDTilesControl = ThreeDTilesControl;
37698
37736
  exports.ThreeDTilesLayer = ThreeDTilesLayer;
37699
37737
  exports.ecefToLngLatAlt = ecefToLngLatAlt;
37700
- //# sourceMappingURL=ThreeDTilesControl-Cz5v6sGw.cjs.map
37738
+ //# sourceMappingURL=ThreeDTilesControl-BcJIWra6.cjs.map