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

visgl / deck.gl / 21049200541

15 Jan 2026 10:53PM UTC coverage: 90.937% (-0.2%) from 91.1%
21049200541

Pull #9939

github

web-flow
Merge 683e9f44b into 1975e2367
Pull Request #9939: fix(mapbox): MapboxOverlay: render deck layers in batches

6845 of 7515 branches covered (91.08%)

Branch coverage included in aggregate %.

79 of 206 new or added lines in 4 files covered. (38.35%)

4 existing lines in 1 file now uncovered.

56728 of 62394 relevant lines covered (90.92%)

14377.74 hits per line

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

19.78
/modules/mapbox/src/resolve-layer-groups.ts
1
// deck.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4

1✔
5
import {_flatten as flatten} from '@deck.gl/core';
1✔
6

1✔
7
import type {LayersList} from '@deck.gl/core';
1✔
8
import type {Map, OverlayLayer} from './types';
1✔
9
import MapboxLayerGroup from './mapbox-layer-group';
1✔
10

1✔
11
const UNDEFINED_BEFORE_ID = '__UNDEFINED__';
1✔
12

1✔
13
/** Group Deck layers into buckets (by beforeId or slot) and insert them
1✔
14
 *  into the mapbox Map according to the user-defined order
1✔
15
 **/
1✔
16
// eslint-disable-next-line complexity, max-statements
1✔
17
export function resolveLayerGroups(map?: Map, oldLayers?: LayersList, newLayers?: LayersList) {
1✔
NEW
18
  // Wait until map style is loaded
×
NEW
19
  // @ts-ignore non-public map property
×
NEW
20
  if (!map || !map.style || !map.style._loaded) {
×
NEW
21
    return;
×
NEW
22
  }
×
NEW
23

×
NEW
24
  const layers = flatten(newLayers, Boolean) as OverlayLayer[];
×
NEW
25

×
NEW
26
  function getGroupId(layer: OverlayLayer): string {
×
NEW
27
    const props = layer.props;
×
NEW
28
    if (props.beforeId) {
×
NEW
29
      return `before-${props.beforeId}`;
×
NEW
30
    }
×
NEW
31
    if (props.slot) {
×
NEW
32
      return `slot-${props.slot}`;
×
NEW
33
    }
×
NEW
34
    return UNDEFINED_BEFORE_ID;
×
NEW
35
  }
×
NEW
36

×
NEW
37
  if (oldLayers !== newLayers) {
×
NEW
38
    // Step 1: remove "group" layers that no longer exist
×
NEW
39
    const prevLayers = flatten(oldLayers, Boolean) as OverlayLayer[];
×
NEW
40
    const prevLayerGroupIds = new Set<string>(prevLayers.map(l => getGroupId(l)));
×
NEW
41
    const newLayerGroupIds = new Set<string>(layers.map(l => getGroupId(l)));
×
NEW
42

×
NEW
43
    for (const groupId of prevLayerGroupIds) {
×
NEW
44
      if (!newLayerGroupIds.has(groupId)) {
×
NEW
45
        if (map.getLayer(groupId)) {
×
NEW
46
          map.removeLayer(groupId);
×
NEW
47
        }
×
NEW
48
      }
×
NEW
49
    }
×
NEW
50
  }
×
NEW
51

×
NEW
52
  // Step 2: add missing "group" layers
×
NEW
53
  const layerGroups: Record<string, MapboxLayerGroup> = {};
×
NEW
54
  for (const layer of layers) {
×
NEW
55
    const groupId = getGroupId(layer);
×
NEW
56
    const mapboxGroup = map.getLayer(groupId) as MapboxLayerGroup;
×
NEW
57
    if (mapboxGroup) {
×
NEW
58
      // Mapbox's map.getLayer() had a breaking change in v3.6.0, see https://github.com/visgl/deck.gl/issues/9086
×
NEW
59
      // @ts-expect-error not typed
×
NEW
60
      const groupInstance = mapboxGroup.implementation || mapboxGroup;
×
NEW
61
      groupInstance.updateLayerProps(layer.id, layer.props);
×
NEW
62
      layerGroups[groupId] = mapboxGroup;
×
NEW
63
    } else {
×
NEW
64
      const newGroup = new MapboxLayerGroup({
×
NEW
65
        id: groupId,
×
NEW
66
        slot: layer.props.slot,
×
NEW
67
        beforeId: layer.props.beforeId
×
NEW
68
      });
×
NEW
69
      layerGroups[groupId] = newGroup;
×
NEW
70
      map.addLayer(newGroup, layer.props.beforeId);
×
NEW
71
    }
×
NEW
72
  }
×
NEW
73

×
NEW
74
  // Step 3: check the order of layers
×
NEW
75
  // If beforeId move "group" layers to proper position in the mapbox layer order
×
NEW
76
  // @ts-ignore non-public map property
×
NEW
77
  const mapLayers: string[] = map.style._order;
×
NEW
78

×
NEW
79
  for (const [groupId, group] of Object.entries(layerGroups)) {
×
NEW
80
    const beforeId = group.beforeId || UNDEFINED_BEFORE_ID;
×
NEW
81
    const expectedGroupIndex =
×
NEW
82
      beforeId === UNDEFINED_BEFORE_ID ? mapLayers.length : mapLayers.indexOf(beforeId);
×
NEW
83

×
NEW
84
    const currentGropupIndex = mapLayers.indexOf(groupId);
×
NEW
85
    if (currentGropupIndex !== expectedGroupIndex) {
×
NEW
86
      const moveBeforeId = beforeId === UNDEFINED_BEFORE_ID ? undefined : beforeId;
×
NEW
87
      map.moveLayer(groupId, moveBeforeId);
×
NEW
88
    }
×
NEW
89
  }
×
NEW
90
}
×
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