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

visgl / loaders.gl / 24283398526

11 Apr 2026 01:24PM UTC coverage: 55.094% (-0.08%) from 55.17%
24283398526

push

github

web-flow
 feat(tiles) Add Tiles3DSource and I3SSource (#3365)

8881 of 17385 branches covered (51.08%)

Branch coverage included in aggregate %.

401 of 602 new or added lines in 11 files covered. (66.61%)

1 existing line in 1 file now uncovered.

18531 of 32370 relevant lines covered (57.25%)

5152.09 hits per line

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

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

5
import {CompositeLayer, type CompositeLayerProps, type LayersList} from '@deck.gl/core';
6
import type {Tile3DLayerProps} from '@deck.gl/geo-layers';
7
import {createDataSource} from '@loaders.gl/core';
8
import type {
9
  DataSource,
10
  DataSourceOptions,
11
  Source,
12
  TileSourceMetadata
13
} from '@loaders.gl/loader-utils';
14
import {isTileset3DSource, type Tileset3DSource} from '@loaders.gl/tiles';
15
import {Tile3DSourceLayer} from './tile-3d-source-layer';
16
import {
17
  TileSourceLayer,
18
  type TileSourceLayerProps,
19
  type TileSourceRuntime
20
} from './tile-source-layer';
21

22
/**
23
 * Props for `SourceLayer`.
24
 *
25
 * `data` may be a concrete tile source, a concrete tileset source, or a URL/blob that can be
26
 * resolved using `sources` or the 3D layer loader props.
27
 */
28
export type SourceLayerProps<DataT = unknown> = CompositeLayerProps &
29
  Partial<Omit<TileSourceLayerProps, 'data'>> &
30
  Partial<Omit<Tile3DLayerProps<DataT>, 'data'>> & {
31
    /** A tile source, tileset source, or URL/blob from which one can be created. */
32
    data: string | Blob | TileSourceRuntime | Tileset3DSource;
33
    /** Source factories used to auto-create tile sources from a URL/blob. */
34
    sources?: Readonly<Source[]>;
35
    /** Options forwarded to `createDataSource` when `sources` are supplied. */
36
    sourceOptions?: DataSourceOptions;
37
    /** Optional metadata for `TileSourceLayer`. */
38
    metadata?: TileSourceMetadata | null;
39
  };
40

41
/**
42
 * Internal union of source values that can be rendered once `data` resolution finishes.
43
 */
44
type ResolvedSourceData =
45
  | string
46
  | TileSourceRuntime
47
  | DataSource<any, any>
48
  | Tileset3DSource
49
  | null;
50

51
/**
52
 * Generic layer that dispatches to the appropriate source-backed layer based on its input.
53
 */
54
export class SourceLayer<
55
  DataT = any,
56
  ExtraProps extends Record<string, unknown> = Record<string, unknown>
57
> extends CompositeLayer<SourceLayerProps<DataT> & ExtraProps> {
58
  /** deck.gl layer name used in debugging output. */
NEW
59
  static layerName = 'SourceLayer';
×
60

61
  /** Initialize resolved source state. */
62
  initializeState(): void {
NEW
63
    this.setState({
×
64
      resolvedData: null
65
    });
66
  }
67

68
  /** Resolve URL/blob inputs to concrete source instances when props change. */
69
  updateState({props, oldProps, changeFlags}: any): void {
NEW
70
    if (
×
71
      changeFlags.dataChanged ||
×
72
      props.sources !== oldProps.sources ||
73
      props.sourceOptions !== oldProps.sourceOptions
74
    ) {
NEW
75
      this.setState({
×
76
        resolvedData: this._resolveData(props)
77
      });
78
    }
79
  }
80

81
  /** Render either `TileSourceLayer` or `Tile3DSourceLayer` based on the resolved source type. */
82
  renderLayers(): LayersList | null {
NEW
83
    const {resolvedData} = this.state as {resolvedData: ResolvedSourceData};
×
NEW
84
    if (!resolvedData) {
×
NEW
85
      return null;
×
86
    }
87

NEW
88
    const {sources, sourceOptions, metadata, ...layerProps} = this.props;
×
NEW
89
    if (isTileSourceRuntime(resolvedData)) {
×
NEW
90
      return [
×
91
        new TileSourceLayer({
92
          ...layerProps,
93
          data: resolvedData,
94
          metadata
95
        } as unknown as TileSourceLayerProps)
96
      ];
97
    }
98

NEW
99
    return [
×
100
      new Tile3DSourceLayer({
101
        ...layerProps,
102
        data: resolvedData
103
      } as any)
104
    ];
105
  }
106

107
  /**
108
   * Resolves the `data` prop to a tile source or tileset source.
109
   */
110
  private _resolveData(props: SourceLayerProps<DataT>): ResolvedSourceData {
NEW
111
    const {data, sources, sourceOptions = {}} = props;
×
112

NEW
113
    if (isTileSourceRuntime(data) || isTileset3DSource(data)) {
×
NEW
114
      return data;
×
115
    }
116

NEW
117
    if ((typeof data === 'string' || data instanceof Blob) && sources?.length) {
×
NEW
118
      return createDataSource(data, sources, sourceOptions) as unknown as TileSourceRuntime;
×
119
    }
120

NEW
121
    if (typeof data === 'string') {
×
NEW
122
      return data;
×
123
    }
124

NEW
125
    throw new Error('SourceLayer requires `sources` to resolve Blob inputs');
×
126
  }
127
}
128

129
/**
130
 * Detects whether a resolved `data` value is a loaders.gl tile source runtime.
131
 * @param value Value to test.
132
 * @returns `true` when the value matches the runtime tile source shape.
133
 */
134
function isTileSourceRuntime(value: unknown): value is TileSourceRuntime {
NEW
135
  return Boolean(
×
136
    value &&
×
137
      typeof value === 'object' &&
138
      'getTileData' in value &&
139
      'getMetadata' in value &&
140
      !('initialize' in value)
141
  );
142
}
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