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

keplergl / kepler.gl / 12650563989

07 Jan 2025 11:20AM UTC coverage: 66.757% (-0.06%) from 66.819%
12650563989

push

github

web-flow
[feat] mapbox and maplibre simultaneous support (#2897)

- switch between basemap style libraries
- add back mapbox styles in Basemap Style tab

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>

5967 of 10394 branches covered (57.41%)

Branch coverage included in aggregate %.

26 of 46 new or added lines in 6 files covered. (56.52%)

1 existing line in 1 file now uncovered.

12243 of 16884 relevant lines covered (72.51%)

89.5 hits per line

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

60.87
/src/utils/src/map-style-utils/mapbox-utils.ts
1
// SPDX-License-Identifier: MIT
2
// Copyright contributors to the kepler.gl project
3

4
// import {isMapboxURL, transformMapboxUrl} from 'maplibregl-mapbox-request-transformer';
5

6
import {MAP_LIB_OPTIONS, BaseMapLibraryType} from '@kepler.gl/constants';
7

8
/**
9
 * Determines whether a Map Style is using Mapbox Tiles
10
 * @param {any} mapStyle the mapStyle to check
11
 * @returns true if the style is using Mapbox tiles
12
 */
13
export function isStyleUsingMapboxTiles(mapStyle) {
14
  const sources = mapStyle.stylesheet?.sources || {};
4✔
15

16
  return Object.keys(sources).some(sourceId => {
4✔
17
    const {url, tiles} = sources[sourceId] || {};
5!
18

19
    if (url) {
5✔
20
      return url.toLowerCase().startsWith('mapbox://');
3✔
21
    }
22

23
    if (tiles) {
2✔
24
      return tiles.some(tileUrl => tileUrl.toLowerCase().startsWith('mapbox://'));
1✔
25
    }
26

27
    return false;
1✔
28
  });
29
}
30

31
export function isStyleUsingOpenStreetMapTiles(mapStyle: any) {
NEW
32
  const sources = mapStyle?.stylesheet?.sources || {};
×
NEW
33
  return Object.keys(sources).some(sourceId => {
×
NEW
34
    const {attribution} = sources[sourceId] || {};
×
NEW
35
    if (typeof attribution?.attribution === 'string') {
×
NEW
36
      return attribution.attribution.includes('openstreetmap.org');
×
37
    }
NEW
38
    return false;
×
39
  });
40
}
41

42
/**
43
 * Transform mapbox protocol so can be used with maplibre
44
 * @param mapboxKey mapbox api key
45
 * @returns transformed url
46
 */
47
export const transformRequest = (
15✔
48
  mapboxKey: string
49
): ((url: string, resourceType: string) => {url: string}) => {
50
  return (url: string, resourceType: string) => {
29✔
51
    /*
52
    if (isMapboxURL(url)) {
53
      // ! TODO - use MapBox directly?
54
      return transformMapboxUrl(url, resourceType, mapboxKey);
55
    }
56
    */
57

58
    return {url};
×
59
  };
60
};
61

62
type StyleWithSources = {
63
  sources?: Record<string, any>;
64
};
65

66
export const getBaseMapLibrary = (baseMapStyle?: {
15✔
67
  url?: string | null;
68
  style?: any;
69
}): BaseMapLibraryType => {
70
  if (baseMapStyle) {
58✔
71
    if (baseMapStyle.url?.startsWith('mapbox://') || baseMapStyle.url?.includes('mapbox.com')) {
56!
NEW
72
      return MAP_LIB_OPTIONS.MAPBOX;
×
73
    }
74

75
    if ((baseMapStyle.style as StyleWithSources)?.sources?.['mapbox'])
56!
NEW
76
      return MAP_LIB_OPTIONS.MAPBOX;
×
77
  }
78

79
  return MAP_LIB_OPTIONS.MAPLIBRE;
58✔
80
};
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