kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
81 lines (76 loc) • 9.82 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBaseMapLibrary = void 0;
exports.isStyleUsingMapboxTiles = isStyleUsingMapboxTiles;
exports.isStyleUsingOpenStreetMapTiles = isStyleUsingOpenStreetMapTiles;
exports.transformRequest = void 0;
var _constants = require("@kepler.gl/constants");
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
// import {isMapboxURL, transformMapboxUrl} from 'maplibregl-mapbox-request-transformer';
/**
* Determines whether a Map Style is using Mapbox Tiles
* @param {any} mapStyle the mapStyle to check
* @returns true if the style is using Mapbox tiles
*/
function isStyleUsingMapboxTiles(mapStyle) {
var _mapStyle$stylesheet;
var sources = ((_mapStyle$stylesheet = mapStyle.stylesheet) === null || _mapStyle$stylesheet === void 0 ? void 0 : _mapStyle$stylesheet.sources) || {};
return Object.keys(sources).some(function (sourceId) {
var _ref = sources[sourceId] || {},
url = _ref.url,
tiles = _ref.tiles;
if (url) {
return url.toLowerCase().startsWith('mapbox://');
}
if (tiles) {
return tiles.some(function (tileUrl) {
return tileUrl.toLowerCase().startsWith('mapbox://');
});
}
return false;
});
}
function isStyleUsingOpenStreetMapTiles(mapStyle) {
var _mapStyle$stylesheet2;
var sources = (mapStyle === null || mapStyle === void 0 || (_mapStyle$stylesheet2 = mapStyle.stylesheet) === null || _mapStyle$stylesheet2 === void 0 ? void 0 : _mapStyle$stylesheet2.sources) || {};
return Object.keys(sources).some(function (sourceId) {
var _ref2 = sources[sourceId] || {},
attribution = _ref2.attribution;
if (typeof (attribution === null || attribution === void 0 ? void 0 : attribution.attribution) === 'string') {
return attribution.attribution.includes('openstreetmap.org');
}
return false;
});
}
/**
* Transform mapbox protocol so can be used with maplibre
* @param mapboxKey mapbox api key
* @returns transformed url
*/
var transformRequest = exports.transformRequest = function transformRequest(_mapboxKey) {
return function (url, _resourceType) {
/*
if (isMapboxURL(url)) {
// ! TODO - use MapBox directly?
return transformMapboxUrl(url, resourceType, mapboxKey);
}
*/
return {
url: url
};
};
};
var getBaseMapLibrary = exports.getBaseMapLibrary = function getBaseMapLibrary(baseMapStyle) {
if (baseMapStyle) {
var _baseMapStyle$url, _baseMapStyle$url2, _baseMapStyle$style;
if ((_baseMapStyle$url = baseMapStyle.url) !== null && _baseMapStyle$url !== void 0 && _baseMapStyle$url.startsWith('mapbox://') || (_baseMapStyle$url2 = baseMapStyle.url) !== null && _baseMapStyle$url2 !== void 0 && _baseMapStyle$url2.includes('mapbox.com')) {
return _constants.MAP_LIB_OPTIONS.MAPBOX;
}
if ((_baseMapStyle$style = baseMapStyle.style) !== null && _baseMapStyle$style !== void 0 && (_baseMapStyle$style = _baseMapStyle$style.sources) !== null && _baseMapStyle$style !== void 0 && _baseMapStyle$style['mapbox']) return _constants.MAP_LIB_OPTIONS.MAPBOX;
}
return _constants.MAP_LIB_OPTIONS.MAPLIBRE;
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfY29uc3RhbnRzIiwicmVxdWlyZSIsImlzU3R5bGVVc2luZ01hcGJveFRpbGVzIiwibWFwU3R5bGUiLCJfbWFwU3R5bGUkc3R5bGVzaGVldCIsInNvdXJjZXMiLCJzdHlsZXNoZWV0IiwiT2JqZWN0Iiwia2V5cyIsInNvbWUiLCJzb3VyY2VJZCIsIl9yZWYiLCJ1cmwiLCJ0aWxlcyIsInRvTG93ZXJDYXNlIiwic3RhcnRzV2l0aCIsInRpbGVVcmwiLCJpc1N0eWxlVXNpbmdPcGVuU3RyZWV0TWFwVGlsZXMiLCJfbWFwU3R5bGUkc3R5bGVzaGVldDIiLCJfcmVmMiIsImF0dHJpYnV0aW9uIiwiaW5jbHVkZXMiLCJ0cmFuc2Zvcm1SZXF1ZXN0IiwiZXhwb3J0cyIsIl9tYXBib3hLZXkiLCJfcmVzb3VyY2VUeXBlIiwiZ2V0QmFzZU1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