• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visgl / loaders.gl / 25070233425

28 Apr 2026 06:20PM UTC coverage: 59.434% (+0.01%) from 59.423%
25070233425

push

github

web-flow
website: Add tabs for navigating between format docs (#3407)

11310 of 20887 branches covered (54.15%)

Branch coverage included in aggregate %.

89 of 136 new or added lines in 13 files covered. (65.44%)

1742 existing lines in 132 files now uncovered.

23500 of 37682 relevant lines covered (62.36%)

16296.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.36
/modules/deck-layers/src/tile-3d-source-layer.ts
1
// loaders.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4

5
import {Tile3DLayer, type Tile3DLayerProps} from '@deck.gl/geo-layers';
6
import {
7
  I3SSource,
8
  isTileset3DSource,
9
  Tiles3DSource,
10
  Tileset3D,
11
  type Tileset3DProps,
12
  type Tileset3DSource
13
} from '@loaders.gl/tiles';
14
import {coreApi} from '@loaders.gl/core';
15
import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
16
import {createSLPKArchiveResolver, createTiles3DArchiveResolver} from './archive-source-resolver';
17

18
/**
19
 * Props for {@link Tile3DSourceLayer}.
20
 */
21
export type Tile3DSourceLayerProps<DataT = unknown> = Omit<Tile3DLayerProps<DataT>, 'data'> & {
22
  /** Root tileset URL or a pre-constructed tileset source. */
23
  data: string | Blob | Tileset3DSource;
24
};
25

26
/**
27
 * Internal deck.gl `Tile3DLayer` adapter that constructs source-backed `Tileset3D` instances.
28
 *
29
 * This class is exported for internal repository use and examples, and is not documented
30
 * beyond these TSDoc comments.
31
 */
32
export class Tile3DSourceLayer<
33
  DataT = any,
34
  // eslint-disable-next-line @typescript-eslint/ban-types
35
  ExtraProps extends {} = {}
36
> extends Tile3DLayer<DataT, Tile3DSourceLayerProps<DataT> & ExtraProps> {
37
  /** deck.gl layer name used in debugging output. */
UNCOV
38
  static layerName = 'Tile3DSourceLayer';
6✔
39

40
  /** Default props inherited from `Tile3DLayer`. */
UNCOV
41
  static defaultProps = Tile3DLayer.defaultProps as any;
6✔
42

43
  /** Install source-backed loading hooks after the base layer initializes its state. */
44
  initializeState(): void {
45
    super.initializeState();
×
46
    (this as any)._loadTileset = this.loadSourceTileset.bind(this);
×
47
  }
48

49
  /**
50
   * Loads a tileset from either a URL or a pre-constructed tileset source.
51
   * @param data Tileset URL or fully constructed source.
52
   */
53
  private async loadSourceTileset(data: string | Blob | Tileset3DSource): Promise<void> {
54
    if (isTileset3DSource(data)) {
×
55
      data.coreApi ||= coreApi;
×
56
      const tileset3d = new Tileset3D(data, {
×
57
        onTileLoad: (this as any)._onTileLoad.bind(this),
58
        onTileUnload: (this as any)._onTileUnload.bind(this),
59
        onTileError: this.props.onTileError
60
      });
61

62
      this.setState({
×
63
        tileset3d,
64
        layerMap: {}
65
      });
66

67
      await tileset3d.tilesetInitializationPromise;
×
68
      (this as any)._updateTileset(this.state.activeViewports);
×
69
      this.props.onTilesetLoad?.(tileset3d);
×
70
      return;
×
71
    }
72

73
    const tilesetUrl = data;
×
74
    const {loadOptions = {}} = this.props;
×
75

76
    // TODO: deprecate `loader` in v9.0
77
    // @ts-ignore
78
    const loaders = this.props.loader || this.props.loaders;
×
79
    const loader = (Array.isArray(loaders) ? loaders[0] : loaders) as LoaderWithParser;
×
80

81
    const options: {loadOptions: LoaderOptions} & Partial<Tileset3DProps> = {
×
82
      loadOptions: {...loadOptions}
83
    };
84
    let actualTilesetUrl = tilesetUrl;
×
85

NEW
86
    if (typeof tilesetUrl === 'string' && loader.preload) {
×
87
      const preloadOptions = await loader.preload(tilesetUrl, loadOptions);
×
88
      if (preloadOptions.url) {
×
89
        actualTilesetUrl = preloadOptions.url;
×
90
      }
91

92
      if (preloadOptions.headers) {
×
93
        options.loadOptions.fetch = {
×
94
          ...options.loadOptions.fetch,
95
          headers: preloadOptions.headers
96
        };
97
      }
98
      Object.assign(options, preloadOptions);
×
99
    }
100

101
    const source = createSource(actualTilesetUrl, loader, options.loadOptions, coreApi);
×
102
    const tileset3d = new Tileset3D(source, {
×
103
      onTileLoad: (this as any)._onTileLoad.bind(this),
104
      onTileUnload: (this as any)._onTileUnload.bind(this),
105
      onTileError: this.props.onTileError,
106
      ...options
107
    });
108

109
    this.setState({
×
110
      tileset3d,
111
      layerMap: {}
112
    });
113

114
    await tileset3d.tilesetInitializationPromise;
×
115
    (this as any)._updateTileset(this.state.activeViewports);
×
116
    this.props.onTilesetLoad?.(tileset3d);
×
117
  }
118
}
119

120
/**
121
 * Creates the format-specific source for a deck.gl loader.
122
 * @param url Resolved root metadata URL.
123
 * @param loader Loader used by the deck.gl layer.
124
 * @param loadOptions Loader options forwarded to the source.
125
 * @returns A source implementation matching the loader format.
126
 */
127
export function createSource(
128
  url: string | Blob,
129
  loader: LoaderWithParser,
130
  loadOptions: LoaderOptions,
131
  injectedCoreApi = coreApi
8✔
132
): Tiles3DSource | I3SSource {
NEW
133
  const lowerCaseUrl = typeof url === 'string' ? url.toLowerCase() : '';
8!
134

UNCOV
135
  if (loader.id === 'slpk' || lowerCaseUrl.endsWith('.slpk')) {
8✔
136
    const archiveConfig =
UNCOV
137
      loader.id === 'slpk'
3✔
138
        ? createSLPKArchiveResolver(url)
139
        : createSLPKArchiveResolver(url, loader);
UNCOV
140
    return new I3SSource(
3✔
141
      {
142
        url,
143
        loader: archiveConfig.loader,
144
        basePath: url,
145
        resolver: archiveConfig.resolver,
146
        coreApi: injectedCoreApi
147
      },
148
      loadOptions
149
    );
150
  }
151

UNCOV
152
  if (loader.id === '3tz' || lowerCaseUrl.endsWith('.3tz')) {
5✔
153
    const archiveConfig =
UNCOV
154
      loader.id === '3tz'
3✔
155
        ? createTiles3DArchiveResolver(url)
156
        : createTiles3DArchiveResolver(url, loader);
UNCOV
157
    return new Tiles3DSource(
3✔
158
      {
159
        url,
160
        loader: archiveConfig.loader,
161
        basePath: url,
162
        resolver: archiveConfig.resolver,
163
        coreApi: injectedCoreApi
164
      },
165
      loadOptions
166
    );
167
  }
168

UNCOV
169
  if (loader.id === 'i3s') {
2✔
UNCOV
170
    return new I3SSource({url, loader, coreApi: injectedCoreApi}, loadOptions);
1✔
171
  }
172

UNCOV
173
  return new Tiles3DSource({url, loader, coreApi: injectedCoreApi}, loadOptions);
1✔
174
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc