• 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

1.82
/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
  SourceLoader,
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<SourceLoader[]>;
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
  | Blob
47
  | TileSourceRuntime
48
  | DataSource<any, any>
49
  | Tileset3DSource
50
  | null;
51

52
/**
53
 * Internal deck.gl dispatcher that selects the appropriate source-backed layer for an input.
54
 *
55
 * This class is exported for internal repository use and examples, and is not documented
56
 * beyond these TSDoc comments.
57
 */
58
export class SourceLayer<
59
  DataT = any,
60
  ExtraProps extends Record<string, unknown> = Record<string, unknown>
61
> extends CompositeLayer<SourceLayerProps<DataT> & ExtraProps> {
62
  /** deck.gl layer name used in debugging output. */
UNCOV
63
  static layerName = 'SourceLayer';
6✔
64

65
  /** Initialize resolved source state. */
66
  initializeState(): void {
67
    this.setState({
×
68
      resolvedData: null
69
    });
70
  }
71

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

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

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

103
    return [
×
104
      new Tile3DSourceLayer({
105
        ...layerProps,
106
        data: resolvedData
107
      } as any)
108
    ];
109
  }
110

111
  /**
112
   * Resolves the `data` prop to a tile source or tileset source.
113
   */
114
  private _resolveData(props: SourceLayerProps<DataT>): ResolvedSourceData {
115
    const {data, sources, sourceOptions = {}} = props;
×
NEW
116
    const loaders = props.loader || props.loaders;
×
117

118
    if (isTileSourceRuntime(data) || isTileset3DSource(data)) {
×
119
      return data;
×
120
    }
121

122
    if ((typeof data === 'string' || data instanceof Blob) && sources?.length) {
×
123
      return createDataSource(data, sources, sourceOptions) as unknown as TileSourceRuntime;
×
124
    }
125

126
    if (typeof data === 'string') {
×
127
      return data;
×
128
    }
129

NEW
130
    if (data instanceof Blob && loaders) {
×
NEW
131
      return data;
×
132
    }
133

NEW
134
    throw new Error('SourceLayer requires `sources` or 3D loaders to resolve Blob inputs');
×
135
  }
136
}
137

138
/**
139
 * Detects whether a resolved `data` value is a loaders.gl tile source runtime.
140
 * @param value Value to test.
141
 * @returns `true` when the value matches the runtime tile source shape.
142
 */
143
function isTileSourceRuntime(value: unknown): value is TileSourceRuntime {
144
  return Boolean(
×
145
    value &&
×
146
      typeof value === 'object' &&
147
      'getTileData' in value &&
148
      'getMetadata' in value &&
149
      !('initialize' in value)
150
  );
151
}
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