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

keplergl / kepler.gl / 25295226964

04 May 2026 12:28AM UTC coverage: 58.931% (-0.1%) from 59.067%
25295226964

push

github

web-flow
fix: fix for open streat map attribution (#3411)

* fix: fix for open streat map attribution

Signed-off-by: Ihor Dykhta <ihordykhta@Ihors-MacBook-Pro.local>

* follow ups

Signed-off-by: Ihor Dykhta <ihordykhta@Ihors-MacBook-Pro.local>

---------

Signed-off-by: Ihor Dykhta <ihordykhta@Ihors-MacBook-Pro.local>
Co-authored-by: Ihor Dykhta <ihordykhta@Ihors-MacBook-Pro.local>

6939 of 14146 branches covered (49.05%)

Branch coverage included in aggregate %.

6 of 63 new or added lines in 2 files covered. (9.52%)

133 existing lines in 2 files now uncovered.

14294 of 21884 relevant lines covered (65.32%)

79.62 hits per line

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

46.67
/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) {
32
  const sources = mapStyle?.stylesheet?.sources || {};
×
33
  return Object.keys(sources).some(sourceId => {
×
34
    const {attribution} = sources[sourceId] || {};
×
NEW
35
    if (typeof attribution === 'string') {
×
NEW
36
      return attribution.includes('openstreetmap.org');
×
37
    }
38
    return false;
×
39
  });
40
}
41

42
/**
43
 * Checks resolved map sources for OpenStreetMap attribution.
44
 * CARTO basemaps don't have attribution in the raw style JSON;
45
 * it only appears after MapLibre resolves the TileJSON.
46
 * Uses map.getSource() to access the resolved source with TileJSON metadata.
47
 */
48
export function mapHasOpenStreetMapAttribution(map: any): boolean {
NEW
49
  try {
×
NEW
50
    const style = map?.getStyle?.();
×
NEW
51
    if (!style?.sources) return false;
×
NEW
52
    return Object.keys(style.sources).some(sourceId => {
×
NEW
53
      const source = map.getSource?.(sourceId);
×
NEW
54
      const attribution = source?.attribution;
×
NEW
55
      if (typeof attribution === 'string') {
×
NEW
56
        return attribution.toLowerCase().includes('openstreetmap');
×
57
      }
NEW
58
      return false;
×
59
    });
60
  } catch {
NEW
61
    return false;
×
62
  }
63
}
64

65
/**
66
 * Transform mapbox protocol so can be used with maplibre
67
 * @param mapboxKey mapbox api key
68
 * @returns transformed url
69
 */
70
export const transformRequest = (
17✔
71
  _mapboxKey: string
72
): ((url: string, resourceType: string) => {url: string}) => {
73
  return (url: string, _resourceType: string) => {
29✔
74
    /*
75
    if (isMapboxURL(url)) {
76
      // ! TODO - use MapBox directly?
77
      return transformMapboxUrl(url, resourceType, mapboxKey);
78
    }
79
    */
80

81
    return {url};
×
82
  };
83
};
84

85
type StyleWithSources = {
86
  sources?: Record<string, any>;
87
};
88

89
export const getBaseMapLibrary = (baseMapStyle?: {
17✔
90
  url?: string | null;
91
  style?: any;
92
}): BaseMapLibraryType => {
93
  if (baseMapStyle) {
58✔
94
    if (baseMapStyle.url?.startsWith('mapbox://') || baseMapStyle.url?.includes('mapbox.com')) {
56!
95
      return MAP_LIB_OPTIONS.MAPBOX;
×
96
    }
97

98
    if ((baseMapStyle.style as StyleWithSources)?.sources?.['mapbox'])
56!
99
      return MAP_LIB_OPTIONS.MAPBOX;
×
100
  }
101

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