@kepler.gl/utils 3.3.0-alpha.2 → 3.3.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application-config.d.ts +180 -1
- package/dist/arrow-data-container.d.ts +55 -2
- package/dist/camera-tour.d.ts +11 -0
- package/dist/camera-utils.d.ts +7 -0
- package/dist/cjs/aggregation.js +84 -0
- package/dist/cjs/aggregation.js.map +1 -0
- package/dist/cjs/application-config-types.js +6 -0
- package/dist/cjs/application-config-types.js.map +1 -0
- package/dist/cjs/application-config.js +178 -0
- package/dist/cjs/application-config.js.map +1 -0
- package/dist/cjs/arrow-data-container.js +1152 -0
- package/dist/cjs/arrow-data-container.js.map +1 -0
- package/dist/cjs/browser-utils.js +17 -0
- package/dist/cjs/browser-utils.js.map +1 -0
- package/dist/cjs/camera-tour.js +99 -0
- package/dist/cjs/camera-tour.js.map +1 -0
- package/dist/cjs/camera-utils.js +81 -0
- package/dist/cjs/camera-utils.js.map +1 -0
- package/dist/cjs/color-utils.js +462 -0
- package/dist/cjs/color-utils.js.map +1 -0
- package/dist/cjs/column-statistics.js +115 -0
- package/dist/cjs/column-statistics.js.map +1 -0
- package/dist/cjs/data-container-interface.js +6 -0
- package/dist/cjs/data-container-interface.js.map +1 -0
- package/dist/cjs/data-container-utils.js +76 -0
- package/dist/cjs/data-container-utils.js.map +1 -0
- package/dist/cjs/data-row.js +110 -0
- package/dist/cjs/data-row.js.map +1 -0
- package/dist/cjs/data-scale-utils.js +634 -0
- package/dist/cjs/data-scale-utils.js.map +1 -0
- package/dist/cjs/data-utils.js +538 -0
- package/dist/cjs/data-utils.js.map +1 -0
- package/dist/cjs/dataset-utils.js +361 -0
- package/dist/cjs/dataset-utils.js.map +1 -0
- package/dist/cjs/dom-to-image.js +433 -0
- package/dist/cjs/dom-to-image.js.map +1 -0
- package/dist/cjs/dom-utils.js +349 -0
- package/dist/cjs/dom-utils.js.map +1 -0
- package/dist/cjs/editor-feature-utils.js +177 -0
- package/dist/cjs/editor-feature-utils.js.map +1 -0
- package/dist/cjs/effect-utils.js +340 -0
- package/dist/cjs/effect-utils.js.map +1 -0
- package/dist/cjs/export-map-html.js +112 -0
- package/dist/cjs/export-map-html.js.map +1 -0
- package/dist/cjs/export-utils.js +318 -0
- package/dist/cjs/export-utils.js.map +1 -0
- package/dist/cjs/extract-dataset-utils.js +218 -0
- package/dist/cjs/extract-dataset-utils.js.map +1 -0
- package/dist/cjs/filter-utils.js +1762 -0
- package/dist/cjs/filter-utils.js.map +1 -0
- package/dist/cjs/format.js +38 -0
- package/dist/cjs/format.js.map +1 -0
- package/dist/cjs/gl-utils.js +118 -0
- package/dist/cjs/gl-utils.js.map +1 -0
- package/dist/{index.js → cjs/index.js} +391 -10
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/indexed-data-container.js +214 -0
- package/dist/cjs/indexed-data-container.js.map +1 -0
- package/dist/cjs/jenks.js +156 -0
- package/dist/cjs/jenks.js.map +1 -0
- package/dist/cjs/locale-utils.js +39 -0
- package/dist/cjs/locale-utils.js.map +1 -0
- package/dist/cjs/map-info-utils.js +41 -0
- package/dist/cjs/map-info-utils.js.map +1 -0
- package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js +198 -0
- package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
- package/dist/cjs/map-style-utils/mapbox-utils.js +155 -0
- package/dist/cjs/map-style-utils/mapbox-utils.js.map +1 -0
- package/dist/cjs/map-utils.js +76 -0
- package/dist/cjs/map-utils.js.map +1 -0
- package/dist/cjs/mapbox-utils.js +19 -0
- package/dist/cjs/mapbox-utils.js.map +1 -0
- package/dist/cjs/notifications-utils.js +69 -0
- package/dist/cjs/notifications-utils.js.map +1 -0
- package/dist/cjs/observe-dimensions.js +136 -0
- package/dist/cjs/observe-dimensions.js.map +1 -0
- package/dist/cjs/plot.js +1502 -0
- package/dist/cjs/plot.js.map +1 -0
- package/dist/cjs/position-utils.js +29 -0
- package/dist/cjs/position-utils.js.map +1 -0
- package/dist/cjs/projection-utils.js +141 -0
- package/dist/cjs/projection-utils.js.map +1 -0
- package/dist/cjs/quick-insertion-sort.js +132 -0
- package/dist/cjs/quick-insertion-sort.js.map +1 -0
- package/dist/cjs/row-data-container.js +291 -0
- package/dist/cjs/row-data-container.js.map +1 -0
- package/dist/cjs/slider-scale-utils.js +138 -0
- package/dist/cjs/slider-scale-utils.js.map +1 -0
- package/dist/cjs/split-map-utils.js +117 -0
- package/dist/cjs/split-map-utils.js.map +1 -0
- package/dist/cjs/strings.js +16 -0
- package/dist/cjs/strings.js.map +1 -0
- package/dist/cjs/theme-utils.js +46 -0
- package/dist/cjs/theme-utils.js.map +1 -0
- package/dist/cjs/time.js +321 -0
- package/dist/cjs/time.js.map +1 -0
- package/dist/cjs/types.js +6 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.js +224 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/column-statistics.d.ts +54 -0
- package/dist/data-container-interface.d.ts +16 -1
- package/dist/data-container-utils.d.ts +2 -1
- package/dist/data-scale-utils.d.ts +5 -0
- package/dist/data-utils.d.ts +3 -3
- package/dist/dataset-utils.d.ts +11 -28
- package/dist/editor-feature-utils.d.ts +30 -0
- package/dist/esm/aggregation.js +75 -0
- package/dist/esm/aggregation.js.map +1 -0
- package/dist/esm/application-config-types.js +3 -0
- package/dist/esm/application-config-types.js.map +1 -0
- package/dist/esm/application-config.js +167 -0
- package/dist/esm/application-config.js.map +1 -0
- package/dist/esm/arrow-data-container.js +1136 -0
- package/dist/esm/arrow-data-container.js.map +1 -0
- package/dist/esm/browser-utils.js +11 -0
- package/dist/esm/browser-utils.js.map +1 -0
- package/dist/esm/camera-tour.js +92 -0
- package/dist/esm/camera-tour.js.map +1 -0
- package/dist/esm/camera-utils.js +74 -0
- package/dist/esm/camera-utils.js.map +1 -0
- package/dist/esm/color-utils.js +435 -0
- package/dist/esm/color-utils.js.map +1 -0
- package/dist/esm/column-statistics.js +105 -0
- package/dist/esm/column-statistics.js.map +1 -0
- package/dist/esm/data-container-interface.js +3 -0
- package/dist/esm/data-container-interface.js.map +1 -0
- package/dist/esm/data-container-utils.js +68 -0
- package/dist/esm/data-container-utils.js.map +1 -0
- package/dist/esm/data-row.js +106 -0
- package/dist/esm/data-row.js.map +1 -0
- package/dist/esm/data-scale-utils.js +602 -0
- package/dist/esm/data-scale-utils.js.map +1 -0
- package/dist/esm/data-utils.js +504 -0
- package/dist/esm/data-utils.js.map +1 -0
- package/dist/esm/dataset-utils.js +352 -0
- package/dist/esm/dataset-utils.js.map +1 -0
- package/dist/esm/dom-to-image.js +426 -0
- package/dist/esm/dom-to-image.js.map +1 -0
- package/dist/esm/dom-utils.js +323 -0
- package/dist/esm/dom-utils.js.map +1 -0
- package/dist/esm/editor-feature-utils.js +164 -0
- package/dist/esm/editor-feature-utils.js.map +1 -0
- package/dist/esm/effect-utils.js +333 -0
- package/dist/esm/effect-utils.js.map +1 -0
- package/dist/esm/export-map-html.js +107 -0
- package/dist/esm/export-map-html.js.map +1 -0
- package/dist/esm/export-utils.js +297 -0
- package/dist/esm/export-utils.js.map +1 -0
- package/dist/esm/extract-dataset-utils.js +206 -0
- package/dist/esm/extract-dataset-utils.js.map +1 -0
- package/dist/esm/filter-utils.js +1701 -0
- package/dist/esm/filter-utils.js.map +1 -0
- package/dist/esm/format.js +31 -0
- package/dist/esm/format.js.map +1 -0
- package/dist/esm/gl-utils.js +113 -0
- package/dist/esm/gl-utils.js.map +1 -0
- package/dist/esm/index.js +55 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/indexed-data-container.js +210 -0
- package/dist/esm/indexed-data-container.js.map +1 -0
- package/dist/esm/jenks.js +149 -0
- package/dist/esm/jenks.js.map +1 -0
- package/dist/esm/locale-utils.js +36 -0
- package/dist/esm/locale-utils.js.map +1 -0
- package/dist/esm/map-info-utils.js +35 -0
- package/dist/esm/map-info-utils.js.map +1 -0
- package/dist/esm/map-style-utils/mapbox-gl-style-editor.js +188 -0
- package/dist/esm/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
- package/dist/esm/map-style-utils/mapbox-utils.js +144 -0
- package/dist/esm/map-style-utils/mapbox-utils.js.map +1 -0
- package/dist/esm/map-utils.js +72 -0
- package/dist/esm/map-utils.js.map +1 -0
- package/dist/esm/mapbox-utils.js +13 -0
- package/dist/esm/mapbox-utils.js.map +1 -0
- package/dist/esm/notifications-utils.js +63 -0
- package/dist/esm/notifications-utils.js.map +1 -0
- package/dist/esm/observe-dimensions.js +128 -0
- package/dist/esm/observe-dimensions.js.map +1 -0
- package/dist/esm/plot.js +1460 -0
- package/dist/esm/plot.js.map +1 -0
- package/dist/esm/position-utils.js +22 -0
- package/dist/esm/position-utils.js.map +1 -0
- package/dist/esm/projection-utils.js +131 -0
- package/dist/esm/projection-utils.js.map +1 -0
- package/dist/esm/quick-insertion-sort.js +125 -0
- package/dist/esm/quick-insertion-sort.js.map +1 -0
- package/dist/esm/row-data-container.js +286 -0
- package/dist/esm/row-data-container.js.map +1 -0
- package/dist/esm/slider-scale-utils.js +129 -0
- package/dist/esm/slider-scale-utils.js.map +1 -0
- package/dist/esm/split-map-utils.js +109 -0
- package/dist/esm/split-map-utils.js.map +1 -0
- package/dist/esm/strings.js +10 -0
- package/dist/esm/strings.js.map +1 -0
- package/dist/esm/theme-utils.js +38 -0
- package/dist/esm/theme-utils.js.map +1 -0
- package/dist/esm/time.js +308 -0
- package/dist/esm/time.js.map +1 -0
- package/dist/esm/types.js +3 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.js +203 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/export-map-html.d.ts +5 -0
- package/dist/export-utils.d.ts +31 -3
- package/dist/extract-dataset-utils.d.ts +79 -0
- package/dist/filter-utils.d.ts +56 -7
- package/dist/index.d.ts +20 -9
- package/dist/jenks.d.ts +5 -0
- package/dist/map-info-utils.d.ts +11 -1
- package/dist/map-style-utils/mapbox-gl-style-editor.d.ts +11 -10
- package/dist/map-style-utils/mapbox-utils.d.ts +29 -1
- package/dist/plot.d.ts +187 -21
- package/dist/projection-utils.d.ts +6 -4
- package/dist/row-data-container.d.ts +19 -0
- package/dist/split-map-utils.d.ts +7 -0
- package/dist/theme-utils.d.ts +8 -0
- package/dist/time.d.ts +3 -3
- package/dist/types.d.ts +2 -0
- package/package.json +33 -26
- package/dist/aggregation.js +0 -84
- package/dist/application-config-types.js +0 -6
- package/dist/application-config.js +0 -113
- package/dist/arrow-data-container.js +0 -398
- package/dist/browser-utils.js +0 -17
- package/dist/color-utils.js +0 -462
- package/dist/data-container-interface.js +0 -6
- package/dist/data-container-utils.js +0 -75
- package/dist/data-row.js +0 -110
- package/dist/data-scale-utils.js +0 -620
- package/dist/data-utils.js +0 -532
- package/dist/dataset-utils.js +0 -330
- package/dist/dom-to-image.js +0 -433
- package/dist/dom-utils.js +0 -349
- package/dist/effect-utils.js +0 -318
- package/dist/export-map-html.js +0 -38
- package/dist/export-utils.js +0 -203
- package/dist/filter-utils.js +0 -1274
- package/dist/format.js +0 -38
- package/dist/gl-utils.js +0 -118
- package/dist/indexed-data-container.js +0 -214
- package/dist/locale-utils.js +0 -39
- package/dist/map-info-utils.js +0 -14
- package/dist/map-style-utils/mapbox-gl-style-editor.js +0 -194
- package/dist/map-style-utils/mapbox-utils.js +0 -107
- package/dist/map-utils.js +0 -72
- package/dist/mapbox-utils.js +0 -19
- package/dist/noop.d.ts +0 -1
- package/dist/noop.js +0 -13
- package/dist/notifications-utils.js +0 -69
- package/dist/observe-dimensions.js +0 -136
- package/dist/plot.js +0 -637
- package/dist/position-utils.js +0 -26
- package/dist/projection-utils.js +0 -91
- package/dist/quick-insertion-sort.js +0 -132
- package/dist/row-data-container.js +0 -206
- package/dist/searcher-utils.d.ts +0 -1
- package/dist/searcher-utils.js +0 -25
- package/dist/slider-scale-utils.js +0 -138
- package/dist/split-map-utils.js +0 -99
- package/dist/strings.js +0 -16
- package/dist/time.js +0 -325
- package/dist/types.js +0 -6
- package/dist/utils.js +0 -224
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.editTopMapStyle = exports.editBottomMapStyle = void 0;
|
|
8
|
+
exports.getDefaultLayerGroupVisibility = getDefaultLayerGroupVisibility;
|
|
9
|
+
exports.getStyleDownloadUrl = getStyleDownloadUrl;
|
|
10
|
+
exports.getStyleImageIcon = getStyleImageIcon;
|
|
11
|
+
exports.mergeLayerGroupVisibility = mergeLayerGroupVisibility;
|
|
12
|
+
exports.scaleMapStyleByResolution = scaleMapStyleByResolution;
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
+
var _memoize = _interopRequireDefault(require("es-toolkit/compat/memoize"));
|
|
15
|
+
var _cloneDeep = _interopRequireDefault(require("es-toolkit/compat/cloneDeep"));
|
|
16
|
+
var _constants = require("@kepler.gl/constants");
|
|
17
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // SPDX-License-Identifier: MIT
|
|
19
|
+
// Copyright contributors to the kepler.gl project
|
|
20
|
+
function getDefaultLayerGroupVisibility(_ref) {
|
|
21
|
+
var _ref$layerGroups = _ref.layerGroups,
|
|
22
|
+
layerGroups = _ref$layerGroups === void 0 ? [] : _ref$layerGroups;
|
|
23
|
+
return layerGroups.reduce(function (accu, layer) {
|
|
24
|
+
return _objectSpread(_objectSpread({}, accu), {}, (0, _defineProperty2["default"])({}, layer.slug, layer.defaultVisibility));
|
|
25
|
+
}, {});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Explicit function type so declaration emit does not need es-toolkit's unexported MemoizedFunction.
|
|
29
|
+
|
|
30
|
+
var resolver = function resolver(_ref2) {
|
|
31
|
+
var id = _ref2.id,
|
|
32
|
+
_ref2$visibleLayerGro = _ref2.visibleLayerGroups,
|
|
33
|
+
visibleLayerGroups = _ref2$visibleLayerGro === void 0 ? {} : _ref2$visibleLayerGro;
|
|
34
|
+
return "".concat(id, ":").concat(Object.keys(visibleLayerGroups).filter(function (d) {
|
|
35
|
+
return visibleLayerGroups[d];
|
|
36
|
+
}).sort().join('-'));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Edit preset map style to keep only visible layers
|
|
41
|
+
*
|
|
42
|
+
* @param mapStyle - preset map style
|
|
43
|
+
* @param visibleLayerGroups - visible layers of top map
|
|
44
|
+
* @returns top map style
|
|
45
|
+
*/
|
|
46
|
+
var editTopMapStyle = exports.editTopMapStyle = (0, _memoize["default"])(function (_ref3) {
|
|
47
|
+
var mapStyle = _ref3.mapStyle,
|
|
48
|
+
visibleLayerGroups = _ref3.visibleLayerGroups;
|
|
49
|
+
var visibleFilters = (mapStyle.layerGroups || []).filter(function (lg) {
|
|
50
|
+
return visibleLayerGroups[lg.slug];
|
|
51
|
+
}).map(function (lg) {
|
|
52
|
+
return lg.filter;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// if top map
|
|
56
|
+
// keep only visible layers
|
|
57
|
+
// @ts-expect-error
|
|
58
|
+
var filteredLayers = mapStyle.style.layers.filter(function (layer) {
|
|
59
|
+
return visibleFilters.some(function (match) {
|
|
60
|
+
return match(layer);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return _objectSpread(_objectSpread({}, mapStyle.style), {}, {
|
|
64
|
+
layers: filteredLayers
|
|
65
|
+
});
|
|
66
|
+
}, resolver);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Edit preset map style to filter out invisible layers
|
|
70
|
+
*
|
|
71
|
+
* @param {Object} mapStyle - preset map style
|
|
72
|
+
* @param {Object} visibleLayerGroups - visible layers of bottom map
|
|
73
|
+
* @returns {Object} bottom map style
|
|
74
|
+
*/
|
|
75
|
+
var editBottomMapStyle = exports.editBottomMapStyle = (0, _memoize["default"])(function (_ref4) {
|
|
76
|
+
var id = _ref4.id,
|
|
77
|
+
mapStyle = _ref4.mapStyle,
|
|
78
|
+
visibleLayerGroups = _ref4.visibleLayerGroups;
|
|
79
|
+
if (id === _constants.NO_MAP_ID) {
|
|
80
|
+
return _constants.EMPTY_MAPBOX_STYLE;
|
|
81
|
+
}
|
|
82
|
+
var invisibleFilters = (mapStyle.layerGroups || []).filter(function (lg) {
|
|
83
|
+
return !visibleLayerGroups[lg.slug];
|
|
84
|
+
}).map(function (lg) {
|
|
85
|
+
return lg.filter;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// if bottom map
|
|
89
|
+
// filter out invisible layers
|
|
90
|
+
// @ts-expect-error
|
|
91
|
+
var filteredLayers = mapStyle.style.layers.filter(function (layer) {
|
|
92
|
+
return invisibleFilters.every(function (match) {
|
|
93
|
+
return !match(layer);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
return _objectSpread(_objectSpread({}, mapStyle.style), {}, {
|
|
97
|
+
layers: filteredLayers
|
|
98
|
+
});
|
|
99
|
+
}, resolver);
|
|
100
|
+
function getStyleDownloadUrl(styleUrl, accessToken, mapboxApiUrl) {
|
|
101
|
+
if (styleUrl.startsWith('http')) {
|
|
102
|
+
return styleUrl;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// mapbox://styles/jckr/cjhcl0lxv13di2rpfoytdbdyj
|
|
106
|
+
if (styleUrl.startsWith('mapbox://styles')) {
|
|
107
|
+
var styleId = styleUrl.replace('mapbox://styles/', '');
|
|
108
|
+
|
|
109
|
+
// https://api.mapbox.com/styles/v1/heshan0131/cjg1bfumo1cwm2rlrjxkinfgw?pluginName=Keplergl&access_token=<token>
|
|
110
|
+
return "".concat(mapboxApiUrl || _constants.DEFAULT_MAPBOX_API_URL, "/styles/v1/").concat(styleId, "?pluginName=Keplergl&access_token=").concat(accessToken);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// style url not recognized
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Generate static map image from style Url to be used as icon
|
|
119
|
+
* @param param
|
|
120
|
+
* @param param.styleUrl
|
|
121
|
+
* @param param.mapboxApiAccessToken
|
|
122
|
+
* @param param.mapboxApiUrl
|
|
123
|
+
* @param param.mapState
|
|
124
|
+
* @param param.mapW
|
|
125
|
+
* @param param.mapH
|
|
126
|
+
*/
|
|
127
|
+
function getStyleImageIcon(_ref5) {
|
|
128
|
+
var styleUrl = _ref5.styleUrl,
|
|
129
|
+
mapboxApiAccessToken = _ref5.mapboxApiAccessToken,
|
|
130
|
+
_ref5$mapboxApiUrl = _ref5.mapboxApiUrl,
|
|
131
|
+
mapboxApiUrl = _ref5$mapboxApiUrl === void 0 ? _constants.DEFAULT_MAPBOX_API_URL : _ref5$mapboxApiUrl,
|
|
132
|
+
_ref5$mapState = _ref5.mapState,
|
|
133
|
+
mapState = _ref5$mapState === void 0 ? {
|
|
134
|
+
longitude: -122.3391,
|
|
135
|
+
latitude: 37.7922,
|
|
136
|
+
zoom: 9
|
|
137
|
+
} : _ref5$mapState,
|
|
138
|
+
_ref5$mapW = _ref5.mapW,
|
|
139
|
+
mapW = _ref5$mapW === void 0 ? 400 : _ref5$mapW,
|
|
140
|
+
_ref5$mapH = _ref5.mapH,
|
|
141
|
+
mapH = _ref5$mapH === void 0 ? 300 : _ref5$mapH;
|
|
142
|
+
var styleId = styleUrl.replace('mapbox://styles/', '');
|
|
143
|
+
return "".concat(mapboxApiUrl, "/styles/v1/").concat(styleId, "/static/") + "".concat(mapState.longitude, ",").concat(mapState.latitude, ",").concat(mapState.zoom, ",0,0/") + "".concat(mapW, "x").concat(mapH) + "?access_token=".concat(mapboxApiAccessToken, "&logo=false&attribution=false");
|
|
144
|
+
}
|
|
145
|
+
function scaleMapStyleByResolution(mapboxStyle, scale) {
|
|
146
|
+
if (scale !== 1 && mapboxStyle) {
|
|
147
|
+
var labelLayerGroup = _constants.DEFAULT_LAYER_GROUPS.find(function (lg) {
|
|
148
|
+
return lg.slug === 'label';
|
|
149
|
+
});
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
var labelLayerFilter = labelLayerGroup.filter;
|
|
152
|
+
var zoomOffset = Math.log2(scale);
|
|
153
|
+
var copyStyle = (0, _cloneDeep["default"])(mapboxStyle);
|
|
154
|
+
(copyStyle.layers || []).forEach(function (d) {
|
|
155
|
+
// edit minzoom and maxzoom
|
|
156
|
+
if (d.maxzoom) {
|
|
157
|
+
d.maxzoom = Math.max(d.maxzoom + zoomOffset, 1);
|
|
158
|
+
|
|
159
|
+
// The maximum zoom is 24
|
|
160
|
+
// https://github.com/visgl/react-map-gl/blob/master/docs/api-reference/map.md#maxzoom-number-maxzoom
|
|
161
|
+
if (d.maxzoom > 24) {
|
|
162
|
+
d.maxzoom = 24;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (d.minzoom) {
|
|
166
|
+
d.minzoom = Math.max(d.minzoom + zoomOffset, 1);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// edit text size
|
|
170
|
+
if (labelLayerFilter(d)) {
|
|
171
|
+
if (d.layout && d.layout['text-size'] && Array.isArray(d.layout['text-size'].stops)) {
|
|
172
|
+
d.layout['text-size'].stops.forEach(function (stop) {
|
|
173
|
+
// zoom
|
|
174
|
+
stop[0] = Math.max(stop[0] + zoomOffset, 1);
|
|
175
|
+
// size
|
|
176
|
+
stop[1] *= scale;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return copyStyle;
|
|
182
|
+
}
|
|
183
|
+
return mapboxStyle;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* When switch to a new style, try to keep current layer group visibility
|
|
188
|
+
* by merging default and current
|
|
189
|
+
* @param {Object} defaultLayerGroup
|
|
190
|
+
* @param {Object} currentLayerGroup
|
|
191
|
+
* @return {Object} mergedLayerGroups
|
|
192
|
+
*/
|
|
193
|
+
function mergeLayerGroupVisibility(defaultLayerGroup, currentLayerGroup) {
|
|
194
|
+
return Object.keys(defaultLayerGroup).reduce(function (accu, key) {
|
|
195
|
+
return _objectSpread(_objectSpread({}, accu), Object.prototype.hasOwnProperty.call(currentLayerGroup, key) ? (0, _defineProperty2["default"])({}, key, currentLayerGroup[key]) : {});
|
|
196
|
+
}, defaultLayerGroup);
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=mapbox-gl-style-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapbox-gl-style-editor.js","names":["_memoize","_interopRequireDefault","require","_cloneDeep","_constants","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","getDefaultLayerGroupVisibility","_ref","_ref$layerGroups","layerGroups","reduce","accu","layer","slug","defaultVisibility","resolver","_ref2","id","_ref2$visibleLayerGro","visibleLayerGroups","concat","d","sort","join","editTopMapStyle","exports","memoize","_ref3","mapStyle","visibleFilters","lg","map","filteredLayers","style","layers","some","match","editBottomMapStyle","_ref4","NO_MAP_ID","EMPTY_MAPBOX_STYLE","invisibleFilters","every","getStyleDownloadUrl","styleUrl","accessToken","mapboxApiUrl","startsWith","styleId","replace","DEFAULT_MAPBOX_API_URL","getStyleImageIcon","_ref5","mapboxApiAccessToken","_ref5$mapboxApiUrl","_ref5$mapState","mapState","longitude","latitude","zoom","_ref5$mapW","mapW","_ref5$mapH","mapH","scaleMapStyleByResolution","mapboxStyle","scale","labelLayerGroup","DEFAULT_LAYER_GROUPS","find","labelLayerFilter","zoomOffset","Math","log2","copyStyle","cloneDeep","maxzoom","max","minzoom","layout","Array","isArray","stops","stop","mergeLayerGroupVisibility","defaultLayerGroup","currentLayerGroup","key","prototype","hasOwnProperty","call"],"sources":["../../../src/map-style-utils/mapbox-gl-style-editor.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright contributors to the kepler.gl project\n\nimport memoize from 'es-toolkit/compat/memoize';\nimport cloneDeep from 'es-toolkit/compat/cloneDeep';\nimport {\n DEFAULT_LAYER_GROUPS,\n DEFAULT_MAPBOX_API_URL,\n NO_MAP_ID,\n EMPTY_MAPBOX_STYLE\n} from '@kepler.gl/constants';\nimport {BaseMapStyle, LayerGroup, MapState} from '@kepler.gl/types';\n\nexport function getDefaultLayerGroupVisibility({layerGroups = []}: {layerGroups: LayerGroup[]}) {\n return layerGroups.reduce(\n (accu, layer) => ({\n ...accu,\n [layer.slug]: layer.defaultVisibility\n }),\n {}\n );\n}\n\ntype EditMapStyleArgs = {\n id?: string;\n mapStyle: BaseMapStyle;\n visibleLayerGroups: {[id: string]: LayerGroup | boolean} | false;\n};\n\n// Explicit function type so declaration emit does not need es-toolkit's unexported MemoizedFunction.\ntype EditMapStyle = (args: EditMapStyleArgs) => object;\n\nconst resolver = ({id, visibleLayerGroups = {}}: EditMapStyleArgs) =>\n `${id}:${Object.keys(visibleLayerGroups)\n .filter(d => visibleLayerGroups[d])\n .sort()\n .join('-')}`;\n\n/**\n * Edit preset map style to keep only visible layers\n *\n * @param mapStyle - preset map style\n * @param visibleLayerGroups - visible layers of top map\n * @returns top map style\n */\nexport const editTopMapStyle: EditMapStyle = memoize(\n ({mapStyle, visibleLayerGroups}: EditMapStyleArgs) => {\n const visibleFilters = (mapStyle.layerGroups || [])\n .filter(lg => visibleLayerGroups[lg.slug])\n .map(lg => lg.filter);\n\n // if top map\n // keep only visible layers\n // @ts-expect-error\n const filteredLayers = mapStyle.style.layers.filter(layer =>\n visibleFilters.some(match => match(layer))\n );\n\n return {\n ...mapStyle.style,\n layers: filteredLayers\n };\n },\n resolver\n);\n\n/**\n * Edit preset map style to filter out invisible layers\n *\n * @param {Object} mapStyle - preset map style\n * @param {Object} visibleLayerGroups - visible layers of bottom map\n * @returns {Object} bottom map style\n */\nexport const editBottomMapStyle: EditMapStyle = memoize(({id, mapStyle, visibleLayerGroups}) => {\n if (id === NO_MAP_ID) {\n return EMPTY_MAPBOX_STYLE;\n }\n\n const invisibleFilters = (mapStyle.layerGroups || [])\n .filter(lg => !visibleLayerGroups[lg.slug])\n .map(lg => lg.filter);\n\n // if bottom map\n // filter out invisible layers\n // @ts-expect-error\n const filteredLayers = mapStyle.style.layers.filter(layer =>\n invisibleFilters.every(match => !match(layer))\n );\n\n return {\n ...mapStyle.style,\n layers: filteredLayers\n };\n}, resolver);\n\nexport function getStyleDownloadUrl(styleUrl, accessToken, mapboxApiUrl) {\n if (styleUrl.startsWith('http')) {\n return styleUrl;\n }\n\n // mapbox://styles/jckr/cjhcl0lxv13di2rpfoytdbdyj\n if (styleUrl.startsWith('mapbox://styles')) {\n const styleId = styleUrl.replace('mapbox://styles/', '');\n\n // https://api.mapbox.com/styles/v1/heshan0131/cjg1bfumo1cwm2rlrjxkinfgw?pluginName=Keplergl&access_token=<token>\n return `${\n mapboxApiUrl || DEFAULT_MAPBOX_API_URL\n }/styles/v1/${styleId}?pluginName=Keplergl&access_token=${accessToken}`;\n }\n\n // style url not recognized\n return null;\n}\n\n/**\n * Generate static map image from style Url to be used as icon\n * @param param\n * @param param.styleUrl\n * @param param.mapboxApiAccessToken\n * @param param.mapboxApiUrl\n * @param param.mapState\n * @param param.mapW\n * @param param.mapH\n */\nexport function getStyleImageIcon({\n styleUrl,\n mapboxApiAccessToken,\n mapboxApiUrl = DEFAULT_MAPBOX_API_URL,\n mapState = {\n longitude: -122.3391,\n latitude: 37.7922,\n zoom: 9\n },\n mapW = 400,\n mapH = 300\n}: {\n styleUrl: string;\n mapboxApiAccessToken: string;\n mapboxApiUrl?: string;\n mapState?: Partial<MapState>;\n mapW?: number;\n mapH?: number;\n}) {\n const styleId = styleUrl.replace('mapbox://styles/', '');\n\n return (\n `${mapboxApiUrl}/styles/v1/${styleId}/static/` +\n `${mapState.longitude},${mapState.latitude},${mapState.zoom},0,0/` +\n `${mapW}x${mapH}` +\n `?access_token=${mapboxApiAccessToken}&logo=false&attribution=false`\n );\n}\n\nexport function scaleMapStyleByResolution(mapboxStyle, scale) {\n if (scale !== 1 && mapboxStyle) {\n const labelLayerGroup = DEFAULT_LAYER_GROUPS.find(lg => lg.slug === 'label');\n // @ts-ignore\n const {filter: labelLayerFilter} = labelLayerGroup;\n const zoomOffset = Math.log2(scale);\n\n const copyStyle = cloneDeep(mapboxStyle);\n (copyStyle.layers || []).forEach(d => {\n // edit minzoom and maxzoom\n if (d.maxzoom) {\n d.maxzoom = Math.max(d.maxzoom + zoomOffset, 1);\n\n // The maximum zoom is 24\n // https://github.com/visgl/react-map-gl/blob/master/docs/api-reference/map.md#maxzoom-number-maxzoom\n if (d.maxzoom > 24) {\n d.maxzoom = 24;\n }\n }\n\n if (d.minzoom) {\n d.minzoom = Math.max(d.minzoom + zoomOffset, 1);\n }\n\n // edit text size\n if (labelLayerFilter(d)) {\n if (d.layout && d.layout['text-size'] && Array.isArray(d.layout['text-size'].stops)) {\n d.layout['text-size'].stops.forEach(stop => {\n // zoom\n stop[0] = Math.max(stop[0] + zoomOffset, 1);\n // size\n stop[1] *= scale;\n });\n }\n }\n });\n\n return copyStyle;\n }\n\n return mapboxStyle;\n}\n\n/**\n * When switch to a new style, try to keep current layer group visibility\n * by merging default and current\n * @param {Object} defaultLayerGroup\n * @param {Object} currentLayerGroup\n * @return {Object} mergedLayerGroups\n */\nexport function mergeLayerGroupVisibility(defaultLayerGroup, currentLayerGroup) {\n return Object.keys(defaultLayerGroup).reduce(\n (accu, key) => ({\n ...accu,\n ...(Object.prototype.hasOwnProperty.call(currentLayerGroup, key)\n ? {[key]: currentLayerGroup[key]}\n : {})\n }),\n defaultLayerGroup\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAGA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAK8B,SAAAG,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,aAAAhB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAE,MAAA,CAAAc,yBAAA,GAAAd,MAAA,CAAAe,gBAAA,CAAAlB,CAAA,EAAAG,MAAA,CAAAc,y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1DqF,GAAG,EAAGD,iBAAiB,CAACC,GAAG,CAAC,IAC9B,CAAC,CAAC;EAAA,CACN,EACFF,iBACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getBaseMapAttributions = getBaseMapAttributions;
|
|
8
|
+
exports.getBaseMapLibrary = void 0;
|
|
9
|
+
exports.isStyleUsingMapboxTiles = isStyleUsingMapboxTiles;
|
|
10
|
+
exports.isStyleUsingOpenStreetMapTiles = isStyleUsingOpenStreetMapTiles;
|
|
11
|
+
exports.mapHasOpenStreetMapAttribution = mapHasOpenStreetMapAttribution;
|
|
12
|
+
exports.transformRequest = void 0;
|
|
13
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
14
|
+
var _constants = require("@kepler.gl/constants");
|
|
15
|
+
// SPDX-License-Identifier: MIT
|
|
16
|
+
// Copyright contributors to the kepler.gl project
|
|
17
|
+
|
|
18
|
+
// import {isMapboxURL, transformMapboxUrl} from 'maplibregl-mapbox-request-transformer';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether a Map Style is using Mapbox Tiles
|
|
22
|
+
* @param {any} mapStyle the mapStyle to check
|
|
23
|
+
* @returns true if the style is using Mapbox tiles
|
|
24
|
+
*/
|
|
25
|
+
function isStyleUsingMapboxTiles(mapStyle) {
|
|
26
|
+
var _mapStyle$stylesheet;
|
|
27
|
+
var sources = ((_mapStyle$stylesheet = mapStyle.stylesheet) === null || _mapStyle$stylesheet === void 0 ? void 0 : _mapStyle$stylesheet.sources) || {};
|
|
28
|
+
return Object.keys(sources).some(function (sourceId) {
|
|
29
|
+
var _ref = sources[sourceId] || {},
|
|
30
|
+
url = _ref.url,
|
|
31
|
+
tiles = _ref.tiles;
|
|
32
|
+
if (url) {
|
|
33
|
+
return url.toLowerCase().startsWith('mapbox://');
|
|
34
|
+
}
|
|
35
|
+
if (tiles) {
|
|
36
|
+
return tiles.some(function (tileUrl) {
|
|
37
|
+
return tileUrl.toLowerCase().startsWith('mapbox://');
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function isStyleUsingOpenStreetMapTiles(mapStyle) {
|
|
44
|
+
var _mapStyle$stylesheet2;
|
|
45
|
+
var sources = (mapStyle === null || mapStyle === void 0 || (_mapStyle$stylesheet2 = mapStyle.stylesheet) === null || _mapStyle$stylesheet2 === void 0 ? void 0 : _mapStyle$stylesheet2.sources) || {};
|
|
46
|
+
return Object.keys(sources).some(function (sourceId) {
|
|
47
|
+
var _ref2 = sources[sourceId] || {},
|
|
48
|
+
attribution = _ref2.attribution;
|
|
49
|
+
if (typeof attribution === 'string') {
|
|
50
|
+
return attribution.includes('openstreetmap.org');
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Minimal structural contract for the MapLibre/Mapbox map instance used by the
|
|
58
|
+
* attribution helpers below. Only the members actually read are declared;
|
|
59
|
+
* everything is optional because these helpers may be called before the map is
|
|
60
|
+
* fully initialized (guarded by optional chaining + try/catch at runtime).
|
|
61
|
+
*
|
|
62
|
+
* `getSource` returns `any` on purpose: the concrete MapLibre/Mapbox source
|
|
63
|
+
* union (GeoJSONSource, VectorSource, …) is not structurally assignable to a
|
|
64
|
+
* `{attribution?}` shape, and we only ever read an optional `attribution`
|
|
65
|
+
* string off it. Declaring the two getters still catches passing a non-map.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Checks resolved map sources for OpenStreetMap attribution.
|
|
70
|
+
* CARTO basemaps don't have attribution in the raw style JSON;
|
|
71
|
+
* it only appears after MapLibre resolves the TileJSON.
|
|
72
|
+
* Uses map.getSource() to access the resolved source with TileJSON metadata.
|
|
73
|
+
*/
|
|
74
|
+
function mapHasOpenStreetMapAttribution(map) {
|
|
75
|
+
try {
|
|
76
|
+
var _map$getStyle;
|
|
77
|
+
var style = map === null || map === void 0 || (_map$getStyle = map.getStyle) === null || _map$getStyle === void 0 ? void 0 : _map$getStyle.call(map);
|
|
78
|
+
if (!(style !== null && style !== void 0 && style.sources)) return false;
|
|
79
|
+
return Object.keys(style.sources).some(function (sourceId) {
|
|
80
|
+
var _map$getSource;
|
|
81
|
+
var source = map === null || map === void 0 || (_map$getSource = map.getSource) === null || _map$getSource === void 0 ? void 0 : _map$getSource.call(map, sourceId);
|
|
82
|
+
var attribution = source === null || source === void 0 ? void 0 : source.attribution;
|
|
83
|
+
if (typeof attribution === 'string') {
|
|
84
|
+
return attribution.toLowerCase().includes('openstreetmap');
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
});
|
|
88
|
+
} catch (_unused) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Collects the attribution strings declared by the resolved map sources.
|
|
95
|
+
* Custom basemap styles (e.g. OpenFreeMap, OpenMapTiles) declare their own
|
|
96
|
+
* attribution in the source's TileJSON, which only becomes available after
|
|
97
|
+
* MapLibre resolves it. Unlike {@link mapHasOpenStreetMapAttribution}, this
|
|
98
|
+
* preserves the full attribution text instead of collapsing it to a boolean,
|
|
99
|
+
* so custom attributions are not lost.
|
|
100
|
+
* @param map the resolved MapLibre/Mapbox map instance
|
|
101
|
+
* @returns de-duplicated list of attribution HTML strings, order preserved
|
|
102
|
+
*/
|
|
103
|
+
function getBaseMapAttributions(map) {
|
|
104
|
+
try {
|
|
105
|
+
var _map$getStyle2;
|
|
106
|
+
var style = map === null || map === void 0 || (_map$getStyle2 = map.getStyle) === null || _map$getStyle2 === void 0 ? void 0 : _map$getStyle2.call(map);
|
|
107
|
+
if (!(style !== null && style !== void 0 && style.sources)) return [];
|
|
108
|
+
var seen = new Set();
|
|
109
|
+
Object.keys(style.sources).forEach(function (sourceId) {
|
|
110
|
+
var _map$getSource2;
|
|
111
|
+
var source = map === null || map === void 0 || (_map$getSource2 = map.getSource) === null || _map$getSource2 === void 0 ? void 0 : _map$getSource2.call(map, sourceId);
|
|
112
|
+
var attribution = source === null || source === void 0 ? void 0 : source.attribution;
|
|
113
|
+
if (typeof attribution === 'string') {
|
|
114
|
+
var trimmed = attribution.trim();
|
|
115
|
+
if (trimmed) {
|
|
116
|
+
seen.add(trimmed);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return (0, _toConsumableArray2["default"])(seen);
|
|
121
|
+
} catch (_unused2) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Transform mapbox protocol so can be used with maplibre
|
|
128
|
+
* @param mapboxKey mapbox api key
|
|
129
|
+
* @returns transformed url
|
|
130
|
+
*/
|
|
131
|
+
var transformRequest = exports.transformRequest = function transformRequest(_mapboxKey) {
|
|
132
|
+
return function (url, _resourceType) {
|
|
133
|
+
/*
|
|
134
|
+
if (isMapboxURL(url)) {
|
|
135
|
+
// ! TODO - use MapBox directly?
|
|
136
|
+
return transformMapboxUrl(url, resourceType, mapboxKey);
|
|
137
|
+
}
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
url: url
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
var getBaseMapLibrary = exports.getBaseMapLibrary = function getBaseMapLibrary(baseMapStyle) {
|
|
146
|
+
if (baseMapStyle) {
|
|
147
|
+
var _baseMapStyle$url, _baseMapStyle$url2, _baseMapStyle$style;
|
|
148
|
+
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')) {
|
|
149
|
+
return _constants.MAP_LIB_OPTIONS.MAPBOX;
|
|
150
|
+
}
|
|
151
|
+
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;
|
|
152
|
+
}
|
|
153
|
+
return _constants.MAP_LIB_OPTIONS.MAPLIBRE;
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=mapbox-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapbox-utils.js","names":["_constants","require","isStyleUsingMapboxTiles","mapStyle","_mapStyle$stylesheet","sources","stylesheet","Object","keys","some","sourceId","_ref","url","tiles","toLowerCase","startsWith","tileUrl","isStyleUsingOpenStreetMapTiles","_mapStyle$stylesheet2","_ref2","attribution","includes","mapHasOpenStreetMapAttribution","map","_map$getStyle","style","getStyle","call","_map$getSource","source","getSource","_unused","getBaseMapAttributions","_map$getStyle2","seen","Set","forEach","_map$getSource2","trimmed","trim","add","_toConsumableArray2","_unused2","transformRequest","exports","_mapboxKey","_resourceType","getBaseMapLibrary","baseMapStyle","_baseMapStyle$url","_baseMapStyle$url2","_baseMapStyle$style","MAP_LIB_OPTIONS","MAPBOX","MAPLIBRE"],"sources":["../../../src/map-style-utils/mapbox-utils.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright contributors to the kepler.gl project\n\n// import {isMapboxURL, transformMapboxUrl} from 'maplibregl-mapbox-request-transformer';\n\nimport {MAP_LIB_OPTIONS, BaseMapLibraryType} from '@kepler.gl/constants';\n\n/**\n * Determines whether a Map Style is using Mapbox Tiles\n * @param {any} mapStyle the mapStyle to check\n * @returns true if the style is using Mapbox tiles\n */\nexport function isStyleUsingMapboxTiles(mapStyle) {\n const sources = mapStyle.stylesheet?.sources || {};\n\n return Object.keys(sources).some(sourceId => {\n const {url, tiles} = sources[sourceId] || {};\n\n if (url) {\n return url.toLowerCase().startsWith('mapbox://');\n }\n\n if (tiles) {\n return tiles.some(tileUrl => tileUrl.toLowerCase().startsWith('mapbox://'));\n }\n\n return false;\n });\n}\n\nexport function isStyleUsingOpenStreetMapTiles(mapStyle: any) {\n const sources = mapStyle?.stylesheet?.sources || {};\n return Object.keys(sources).some(sourceId => {\n const {attribution} = sources[sourceId] || {};\n if (typeof attribution === 'string') {\n return attribution.includes('openstreetmap.org');\n }\n return false;\n });\n}\n\n/**\n * Minimal structural contract for the MapLibre/Mapbox map instance used by the\n * attribution helpers below. Only the members actually read are declared;\n * everything is optional because these helpers may be called before the map is\n * fully initialized (guarded by optional chaining + try/catch at runtime).\n *\n * `getSource` returns `any` on purpose: the concrete MapLibre/Mapbox source\n * union (GeoJSONSource, VectorSource, …) is not structurally assignable to a\n * `{attribution?}` shape, and we only ever read an optional `attribution`\n * string off it. Declaring the two getters still catches passing a non-map.\n */\nexport interface AttributionMapLike {\n getStyle?: () => {sources?: Record<string, unknown>} | undefined | null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getSource?: (id: string) => any;\n}\n\n/**\n * Checks resolved map sources for OpenStreetMap attribution.\n * CARTO basemaps don't have attribution in the raw style JSON;\n * it only appears after MapLibre resolves the TileJSON.\n * Uses map.getSource() to access the resolved source with TileJSON metadata.\n */\nexport function mapHasOpenStreetMapAttribution(map?: AttributionMapLike | null): boolean {\n try {\n const style = map?.getStyle?.();\n if (!style?.sources) return false;\n return Object.keys(style.sources).some(sourceId => {\n const source = map?.getSource?.(sourceId);\n const attribution = source?.attribution;\n if (typeof attribution === 'string') {\n return attribution.toLowerCase().includes('openstreetmap');\n }\n return false;\n });\n } catch {\n return false;\n }\n}\n\n/**\n * Collects the attribution strings declared by the resolved map sources.\n * Custom basemap styles (e.g. OpenFreeMap, OpenMapTiles) declare their own\n * attribution in the source's TileJSON, which only becomes available after\n * MapLibre resolves it. Unlike {@link mapHasOpenStreetMapAttribution}, this\n * preserves the full attribution text instead of collapsing it to a boolean,\n * so custom attributions are not lost.\n * @param map the resolved MapLibre/Mapbox map instance\n * @returns de-duplicated list of attribution HTML strings, order preserved\n */\nexport function getBaseMapAttributions(map?: AttributionMapLike | null): string[] {\n try {\n const style = map?.getStyle?.();\n if (!style?.sources) return [];\n const seen = new Set<string>();\n Object.keys(style.sources).forEach(sourceId => {\n const source = map?.getSource?.(sourceId);\n const attribution = source?.attribution;\n if (typeof attribution === 'string') {\n const trimmed = attribution.trim();\n if (trimmed) {\n seen.add(trimmed);\n }\n }\n });\n return [...seen];\n } catch {\n return [];\n }\n}\n\n/**\n * Transform mapbox protocol so can be used with maplibre\n * @param mapboxKey mapbox api key\n * @returns transformed url\n */\nexport const transformRequest = (\n _mapboxKey: string\n): ((url: string, resourceType: string) => {url: string}) => {\n return (url: string, _resourceType: string) => {\n /*\n if (isMapboxURL(url)) {\n // ! TODO - use MapBox directly?\n return transformMapboxUrl(url, resourceType, mapboxKey);\n }\n */\n\n return {url};\n };\n};\n\ntype StyleWithSources = {\n sources?: Record<string, any>;\n};\n\nexport const getBaseMapLibrary = (baseMapStyle?: {\n url?: string | null;\n style?: any;\n}): BaseMapLibraryType => {\n if (baseMapStyle) {\n if (baseMapStyle.url?.startsWith('mapbox://') || baseMapStyle.url?.includes('mapbox.com')) {\n return MAP_LIB_OPTIONS.MAPBOX;\n }\n\n if ((baseMapStyle.style as StyleWithSources)?.sources?.['mapbox'])\n return MAP_LIB_OPTIONS.MAPBOX;\n }\n\n return MAP_LIB_OPTIONS.MAPLIBRE;\n};\n"],"mappings":";;;;;;;;;;;;;AAKA,IAAAA,UAAA,GAAAC,OAAA;AALA;AACA;;AAEA;;AAIA;AACA;AACA;AACA;AACA;AACO,SAASC,uBAAuBA,CAACC,QAAQ,EAAE;EA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,EAAAC,kBAAA,EAAAC,mBAAA;IAChB,IAAI,CAAAF,iBAAA,GAAAD,YAAY,CAACpC,GAAG,cAAAqC,iBAAA,eAAhBA,iBAAA,CAAkBlC,UAAU,CAAC,WAAW,CAAC,KAAAmC,kBAAA,GAAIF,YAAY,CAACpC,GAAG,cAAAsC,kBAAA,eAAhBA,kBAAA,CAAkB7B,QAAQ,CAAC,YAAY,CAAC,EAAE;MACzF,OAAO+B,0BAAe,CAACC,MAAM;IAC/B;IAEA,KAAAF,mBAAA,GAAKH,YAAY,CAACvB,KAAK,cAAA0B,mBAAA,gBAAAA,mBAAA,GAAnBA,mBAAA,CAA0C9C,OAAO,cAAA8C,mBAAA,eAAjDA,mBAAA,CAAoD,QAAQ,CAAC,EAC/D,OAAOC,0BAAe,CAACC,MAAM;EACjC;EAEA,OAAOD,0BAAe,CAACE,QAAQ;AACjC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.validateViewPort = exports.onViewPortChange = exports.getViewportFromMapState = exports.getMapLayersFromSplitMaps = void 0;
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _webMercator = require("@math.gl/web-mercator");
|
|
11
|
+
var _core = require("@deck.gl/core");
|
|
12
|
+
var _constants = require("@kepler.gl/constants");
|
|
13
|
+
var _dataUtils = require("./data-utils");
|
|
14
|
+
var _excluded = ["width", "height"];
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // SPDX-License-Identifier: MIT
|
|
17
|
+
// Copyright contributors to the kepler.gl project
|
|
18
|
+
// @ts-ignore GlobeViewport is an experimental, underscore-prefixed deck.gl export whose named type binding isn't reliably resolvable through the package barrel under this project's module resolution. Access it off the namespace with a loose type.
|
|
19
|
+
/**
|
|
20
|
+
* Validates a ViewPort object.
|
|
21
|
+
* It retains all properties of the original ViewPort object,
|
|
22
|
+
* but ensures that the latitude is within the defined bounds.
|
|
23
|
+
* @param viewport - The ViewPort object to validate.
|
|
24
|
+
* @returns A new ViewPort object with validated latitude.
|
|
25
|
+
*/
|
|
26
|
+
var validateViewPort = exports.validateViewPort = function validateViewPort(viewport) {
|
|
27
|
+
return _objectSpread(_objectSpread(_objectSpread({}, viewport), viewport.latitude ? {
|
|
28
|
+
latitude: (0, _dataUtils.validateLatitude)(viewport.latitude)
|
|
29
|
+
} : {}), viewport.longitude ? {
|
|
30
|
+
longitude: (0, _dataUtils.validateLongitude)(viewport.longitude)
|
|
31
|
+
} : {});
|
|
32
|
+
};
|
|
33
|
+
var onViewPortChange = exports.onViewPortChange = function onViewPortChange(viewState, onUpdateMap, onViewStateChange) {
|
|
34
|
+
var primary = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
35
|
+
var mapIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
36
|
+
var _viewState$width = viewState.width,
|
|
37
|
+
width = _viewState$width === void 0 ? 0 : _viewState$width,
|
|
38
|
+
_viewState$height = viewState.height,
|
|
39
|
+
height = _viewState$height === void 0 ? 0 : _viewState$height,
|
|
40
|
+
restViewState = (0, _objectWithoutProperties2["default"])(viewState, _excluded);
|
|
41
|
+
// react-map-gl sends 0,0 dimensions during initialization
|
|
42
|
+
// after we have received proper dimensions from observeDimensions
|
|
43
|
+
var next = _objectSpread(_objectSpread({}, width > 0 && height > 0 ? viewState : restViewState), {}, {
|
|
44
|
+
// enabling transition in two maps may lead to endless update loops
|
|
45
|
+
transitionDuration: primary ? _constants.TRANSITION_DURATION : 0
|
|
46
|
+
});
|
|
47
|
+
if (onViewStateChange && typeof onViewStateChange === 'function') {
|
|
48
|
+
onViewStateChange(next);
|
|
49
|
+
}
|
|
50
|
+
onUpdateMap(next, mapIndex);
|
|
51
|
+
};
|
|
52
|
+
var getMapLayersFromSplitMaps = exports.getMapLayersFromSplitMaps = function getMapLayersFromSplitMaps(splitMaps, mapIndex) {
|
|
53
|
+
var _splitMaps;
|
|
54
|
+
return (_splitMaps = splitMaps[mapIndex || 0]) === null || _splitMaps === void 0 ? void 0 : _splitMaps.layers;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Generates a viewport from a map state.
|
|
59
|
+
* @param mapState
|
|
60
|
+
* @returns A viewport.
|
|
61
|
+
*/
|
|
62
|
+
var getViewportFromMapState = exports.getViewportFromMapState = function getViewportFromMapState(mapState) {
|
|
63
|
+
var viewPort;
|
|
64
|
+
try {
|
|
65
|
+
var _mapState$globe;
|
|
66
|
+
if ((_mapState$globe = mapState.globe) !== null && _mapState$globe !== void 0 && _mapState$globe.enabled) {
|
|
67
|
+
viewPort = new _core._GlobeViewport(mapState);
|
|
68
|
+
} else {
|
|
69
|
+
viewPort = new _webMercator.WebMercatorViewport(mapState);
|
|
70
|
+
}
|
|
71
|
+
} catch (_unused) {
|
|
72
|
+
viewPort = new _webMercator.WebMercatorViewport(validateViewPort(mapState));
|
|
73
|
+
}
|
|
74
|
+
return viewPort;
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=map-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-utils.js","names":["_webMercator","require","_core","_constants","_dataUtils","_excluded","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","validateViewPort","exports","viewport","latitude","validateLatitude","longitude","validateLongitude","onViewPortChange","viewState","onUpdateMap","onViewStateChange","primary","undefined","mapIndex","_viewState$width","width","_viewState$height","height","restViewState","_objectWithoutProperties2","next","transitionDuration","TRANSITION_DURATION","getMapLayersFromSplitMaps","splitMaps","_splitMaps","layers","getViewportFromMapState","mapState","viewPort","_mapState$globe","globe","enabled","GlobeViewport","WebMercatorViewport","_unused"],"sources":["../../src/map-utils.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright contributors to the kepler.gl project\n\nimport {WebMercatorViewport} from '@math.gl/web-mercator';\n// @ts-ignore GlobeViewport is an experimental, underscore-prefixed deck.gl export whose named type binding isn't reliably resolvable through the package barrel under this project's module resolution. Access it off the namespace with a loose type.\nimport {_GlobeViewport as GlobeViewport} from '@deck.gl/core';\n\nimport {TRANSITION_DURATION} from '@kepler.gl/constants';\nimport {SplitMapLayers, SplitMap, Viewport, MapState} from '@kepler.gl/types';\n\nimport {validateLatitude, validateLongitude} from './data-utils';\n\n/**\n * Validates a ViewPort object.\n * It retains all properties of the original ViewPort object,\n * but ensures that the latitude is within the defined bounds.\n * @param viewport - The ViewPort object to validate.\n * @returns A new ViewPort object with validated latitude.\n */\nexport const validateViewPort = <T extends Pick<Viewport, 'latitude' | 'longitude'>>(\n viewport: T\n): T => {\n return {\n ...viewport,\n // make sure to process latitude to avoid 90, -90 values\n // Uncaught Error: Pixel project matrix not invertible\n ...(viewport.latitude ? {latitude: validateLatitude(viewport.latitude)} : {}),\n ...(viewport.longitude ? {longitude: validateLongitude(viewport.longitude)} : {})\n };\n};\n\nexport const onViewPortChange = (\n viewState: Viewport,\n onUpdateMap: (next: any, mapIndex: number) => any,\n onViewStateChange?: (next: any) => void | null,\n primary = false,\n mapIndex = 0\n): void => {\n const {width = 0, height = 0, ...restViewState} = viewState;\n // react-map-gl sends 0,0 dimensions during initialization\n // after we have received proper dimensions from observeDimensions\n const next = {\n ...(width > 0 && height > 0 ? viewState : restViewState),\n // enabling transition in two maps may lead to endless update loops\n transitionDuration: primary ? TRANSITION_DURATION : 0\n };\n if (onViewStateChange && typeof onViewStateChange === 'function') {\n onViewStateChange(next);\n }\n\n onUpdateMap(next, mapIndex);\n};\n\nexport const getMapLayersFromSplitMaps = (\n splitMaps: SplitMap[],\n mapIndex?: number\n): SplitMapLayers | undefined | null => {\n return splitMaps[mapIndex || 0]?.layers;\n};\n\n/**\n * Generates a viewport from a map state.\n * @param mapState\n * @returns A viewport.\n */\nexport const getViewportFromMapState = (mapState: MapState): Viewport => {\n let viewPort;\n try {\n if (mapState.globe?.enabled) {\n viewPort = new GlobeViewport(mapState);\n } else {\n viewPort = new WebMercatorViewport(mapState);\n }\n } catch {\n viewPort = new WebMercatorViewport(validateViewPort(mapState));\n }\n\n return viewPort;\n};\n"],"mappings":";;;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAGA,IAAAG,UAAA,GAAAH,OAAA;AAAiE,IAAAI,SAAA;AAAA,SAAAC,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CA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,GAAG,SAA1BA,uBAAuBA,CAAIC,QAAkB,EAAe;EACvE,IAAIC,QAAQ;EACZ,IAAI;IAAA,IAAAC,eAAA;IACF,KAAAA,eAAA,GAAIF,QAAQ,CAACG,KAAK,cAAAD,eAAA,eAAdA,eAAA,CAAgBE,OAAO,EAAE;MAC3BH,QAAQ,GAAG,IAAII,oBAAa,CAACL,QAAQ,CAAC;IACxC,CAAC,MAAM;MACLC,QAAQ,GAAG,IAAIK,gCAAmB,CAACN,QAAQ,CAAC;IAC9C;EACF,CAAC,CAAC,OAAAO,OAAA,EAAM;IACNN,QAAQ,GAAG,IAAIK,gCAAmB,CAAClC,gBAAgB,CAAC4B,QAAQ,CAAC,CAAC;EAChE;EAEA,OAAOC,QAAQ;AACjB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateToken = void 0;
|
|
7
|
+
// SPDX-License-Identifier: MIT
|
|
8
|
+
// Copyright contributors to the kepler.gl project
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This method validates mapbox token.
|
|
12
|
+
* This token provides a simple synchronous validation
|
|
13
|
+
* @param {string} token the Mapbox token to validate
|
|
14
|
+
* @return {boolean} true if token is valid, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
var validateToken = exports.validateToken = function validateToken(token) {
|
|
17
|
+
return (token || '') !== '';
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=mapbox-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapbox-utils.js","names":["validateToken","exports","token"],"sources":["../../src/mapbox-utils.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright contributors to the kepler.gl project\n\n/**\n * This method validates mapbox token.\n * This token provides a simple synchronous validation\n * @param {string} token the Mapbox token to validate\n * @return {boolean} true if token is valid, false otherwise\n */\nexport const validateToken = (token: string): boolean => (token || '') !== '';\n"],"mappings":";;;;;;AAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,SAAhBA,aAAaA,CAAIE,KAAa;EAAA,OAAc,CAACA,KAAK,IAAI,EAAE,MAAM,EAAE;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createNotification = createNotification;
|
|
8
|
+
exports.successNotification = exports.exportImageError = exports.errorNotification = void 0;
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
var _commonUtils = require("@kepler.gl/common-utils");
|
|
12
|
+
var _constants = require("@kepler.gl/constants");
|
|
13
|
+
var _excluded = ["message", "type", "topic", "id", "count"]; // SPDX-License-Identifier: MIT
|
|
14
|
+
// Copyright contributors to the kepler.gl project
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
/**
|
|
18
|
+
* Creates a notification
|
|
19
|
+
*/
|
|
20
|
+
function createNotification(_ref) {
|
|
21
|
+
var _ref$message = _ref.message,
|
|
22
|
+
message = _ref$message === void 0 ? _constants.DEFAULT_NOTIFICATION_MESSAGE : _ref$message,
|
|
23
|
+
_ref$type = _ref.type,
|
|
24
|
+
type = _ref$type === void 0 ? _constants.DEFAULT_NOTIFICATION_TYPES.info : _ref$type,
|
|
25
|
+
_ref$topic = _ref.topic,
|
|
26
|
+
topic = _ref$topic === void 0 ? _constants.DEFAULT_NOTIFICATION_TOPICS.global : _ref$topic,
|
|
27
|
+
_ref$id = _ref.id,
|
|
28
|
+
id = _ref$id === void 0 ? (0, _commonUtils.generateHashId)(_constants.DEFAULT_UUID_COUNT) : _ref$id,
|
|
29
|
+
_ref$count = _ref.count,
|
|
30
|
+
count = _ref$count === void 0 ? 1 : _ref$count,
|
|
31
|
+
options = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
32
|
+
return _objectSpread(_objectSpread({}, options), {}, {
|
|
33
|
+
id: id,
|
|
34
|
+
message: message,
|
|
35
|
+
type: type,
|
|
36
|
+
topic: topic,
|
|
37
|
+
count: count > 99 ? 99 : count // no more than 2 digits
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates an error notification
|
|
43
|
+
* @param options
|
|
44
|
+
* @returns {{topic, id, message, type: (null|number)}}
|
|
45
|
+
*/
|
|
46
|
+
var errorNotification = exports.errorNotification = function errorNotification(options) {
|
|
47
|
+
return _objectSpread(_objectSpread({}, createNotification(options)), {}, {
|
|
48
|
+
type: _constants.DEFAULT_NOTIFICATION_TYPES.error
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates a success notification
|
|
54
|
+
* @param options
|
|
55
|
+
* @returns {{topic, id, message, type: null}}
|
|
56
|
+
*/
|
|
57
|
+
var successNotification = exports.successNotification = function successNotification(options) {
|
|
58
|
+
return _objectSpread(_objectSpread({}, createNotification(options)), {}, {
|
|
59
|
+
type: _constants.DEFAULT_NOTIFICATION_TYPES.success
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
var exportImageError = exports.exportImageError = function exportImageError(options) {
|
|
63
|
+
return errorNotification(_objectSpread(_objectSpread({}, options), {}, {
|
|
64
|
+
id: 'EXPORT_IMAGE_ERROR_ID',
|
|
65
|
+
topic: _constants.DEFAULT_NOTIFICATION_TOPICS.global,
|
|
66
|
+
message: "Failed to export image, please take a screenshot of the javascript console, report the with [this link](".concat(_constants.BUG_REPORT_LINK, ") ")
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=notifications-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications-utils.js","names":["_commonUtils","require","_constants","_excluded","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","createNotification","_ref","_ref$message","message","DEFAULT_NOTIFICATION_MESSAGE","_ref$type","type","DEFAULT_NOTIFICATION_TYPES","info","_ref$topic","topic","DEFAULT_NOTIFICATION_TOPICS","global","_ref$id","id","generateHashId","DEFAULT_UUID_COUNT","_ref$count","count","options","_objectWithoutProperties2","errorNotification","exports","error","successNotification","success","exportImageError","concat","BUG_REPORT_LINK"],"sources":["../../src/notifications-utils.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright contributors to the kepler.gl project\n\nimport {generateHashId} from '@kepler.gl/common-utils';\n\nimport {\n DEFAULT_NOTIFICATION_MESSAGE,\n DEFAULT_NOTIFICATION_TOPICS,\n DEFAULT_NOTIFICATION_TYPES,\n DEFAULT_UUID_COUNT,\n BUG_REPORT_LINK\n} from '@kepler.gl/constants';\n\nexport type Notification = Record<string, any> & {\n id: string;\n message: string;\n type: 'info' | 'error' | 'warning' | 'success';\n topic: 'global' | 'file';\n count: number;\n};\n\n/**\n * Creates a notification\n */\nexport function createNotification({\n message = DEFAULT_NOTIFICATION_MESSAGE,\n type = DEFAULT_NOTIFICATION_TYPES.info,\n topic = DEFAULT_NOTIFICATION_TOPICS.global,\n id = generateHashId(DEFAULT_UUID_COUNT),\n count = 1,\n ...options\n}: Partial<Notification>): Notification {\n return {\n ...options,\n id,\n message,\n type,\n topic,\n count: count > 99 ? 99 : count // no more than 2 digits\n };\n}\n\n/**\n * Creates an error notification\n * @param options\n * @returns {{topic, id, message, type: (null|number)}}\n */\nexport const errorNotification = options => ({\n ...createNotification(options),\n type: DEFAULT_NOTIFICATION_TYPES.error\n});\n\n/**\n * Creates a success notification\n * @param options\n * @returns {{topic, id, message, type: null}}\n */\nexport const successNotification = options => ({\n ...createNotification(options),\n type: DEFAULT_NOTIFICATION_TYPES.success\n});\n\nexport const exportImageError = options =>\n errorNotification({\n ...options,\n id: 'EXPORT_IMAGE_ERROR_ID',\n topic: DEFAULT_NOTIFICATION_TOPICS.global,\n message: `Failed to export image, please take a screenshot of the javascript console, report the with [this link](${BUG_REPORT_LINK}) `\n });\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAM8B,IAAAE,SAAA,gDAX9B;AACA;AAAA,SAAAC,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KA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