mobility-toolbox-js
Version:
Toolbox for JavaScript applications in the domains of mobility and logistics.
33 lines (32 loc) • 1.1 kB
JavaScript
import removeDuplicate from './removeDuplicate';
/**
* Return the copyright a Maplibre map.
* @param {maplibregl.Map} map A Maplibre map
* @private
*/
const getMapGlCopyrights = (map) => {
if (!map) {
return [];
}
const { style } = map;
if (!style) {
return [];
}
// @ts-expect-error - sourceCaches exists in maplibre-gl < 5.11.0
const { sourceCaches, tileManagers } = style;
let copyrights = [];
const sourceCacheObj = tileManagers || sourceCaches || {};
Object.values(sourceCacheObj).forEach((value) => {
var _a;
if (value.used) {
const source = value.getSource();
const attribution = (source === null || source === void 0 ? void 0 : source.attribution) ||
((_a = source.options) === null || _a === void 0 ? void 0 : _a.attribution);
if (attribution) {
copyrights = copyrights.concat(attribution.replace(/©/g, '©').split(/(<a.*?<\/a>)/));
}
}
});
return removeDuplicate(copyrights);
};
export default getMapGlCopyrights;