@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.
Files changed (264) hide show
  1. package/dist/application-config.d.ts +180 -1
  2. package/dist/arrow-data-container.d.ts +55 -2
  3. package/dist/camera-tour.d.ts +11 -0
  4. package/dist/camera-utils.d.ts +7 -0
  5. package/dist/cjs/aggregation.js +84 -0
  6. package/dist/cjs/aggregation.js.map +1 -0
  7. package/dist/cjs/application-config-types.js +6 -0
  8. package/dist/cjs/application-config-types.js.map +1 -0
  9. package/dist/cjs/application-config.js +178 -0
  10. package/dist/cjs/application-config.js.map +1 -0
  11. package/dist/cjs/arrow-data-container.js +1152 -0
  12. package/dist/cjs/arrow-data-container.js.map +1 -0
  13. package/dist/cjs/browser-utils.js +17 -0
  14. package/dist/cjs/browser-utils.js.map +1 -0
  15. package/dist/cjs/camera-tour.js +99 -0
  16. package/dist/cjs/camera-tour.js.map +1 -0
  17. package/dist/cjs/camera-utils.js +81 -0
  18. package/dist/cjs/camera-utils.js.map +1 -0
  19. package/dist/cjs/color-utils.js +462 -0
  20. package/dist/cjs/color-utils.js.map +1 -0
  21. package/dist/cjs/column-statistics.js +115 -0
  22. package/dist/cjs/column-statistics.js.map +1 -0
  23. package/dist/cjs/data-container-interface.js +6 -0
  24. package/dist/cjs/data-container-interface.js.map +1 -0
  25. package/dist/cjs/data-container-utils.js +76 -0
  26. package/dist/cjs/data-container-utils.js.map +1 -0
  27. package/dist/cjs/data-row.js +110 -0
  28. package/dist/cjs/data-row.js.map +1 -0
  29. package/dist/cjs/data-scale-utils.js +634 -0
  30. package/dist/cjs/data-scale-utils.js.map +1 -0
  31. package/dist/cjs/data-utils.js +538 -0
  32. package/dist/cjs/data-utils.js.map +1 -0
  33. package/dist/cjs/dataset-utils.js +361 -0
  34. package/dist/cjs/dataset-utils.js.map +1 -0
  35. package/dist/cjs/dom-to-image.js +433 -0
  36. package/dist/cjs/dom-to-image.js.map +1 -0
  37. package/dist/cjs/dom-utils.js +349 -0
  38. package/dist/cjs/dom-utils.js.map +1 -0
  39. package/dist/cjs/editor-feature-utils.js +177 -0
  40. package/dist/cjs/editor-feature-utils.js.map +1 -0
  41. package/dist/cjs/effect-utils.js +340 -0
  42. package/dist/cjs/effect-utils.js.map +1 -0
  43. package/dist/cjs/export-map-html.js +112 -0
  44. package/dist/cjs/export-map-html.js.map +1 -0
  45. package/dist/cjs/export-utils.js +318 -0
  46. package/dist/cjs/export-utils.js.map +1 -0
  47. package/dist/cjs/extract-dataset-utils.js +218 -0
  48. package/dist/cjs/extract-dataset-utils.js.map +1 -0
  49. package/dist/cjs/filter-utils.js +1762 -0
  50. package/dist/cjs/filter-utils.js.map +1 -0
  51. package/dist/cjs/format.js +38 -0
  52. package/dist/cjs/format.js.map +1 -0
  53. package/dist/cjs/gl-utils.js +118 -0
  54. package/dist/cjs/gl-utils.js.map +1 -0
  55. package/dist/{index.js → cjs/index.js} +391 -10
  56. package/dist/cjs/index.js.map +1 -0
  57. package/dist/cjs/indexed-data-container.js +214 -0
  58. package/dist/cjs/indexed-data-container.js.map +1 -0
  59. package/dist/cjs/jenks.js +156 -0
  60. package/dist/cjs/jenks.js.map +1 -0
  61. package/dist/cjs/locale-utils.js +39 -0
  62. package/dist/cjs/locale-utils.js.map +1 -0
  63. package/dist/cjs/map-info-utils.js +41 -0
  64. package/dist/cjs/map-info-utils.js.map +1 -0
  65. package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js +198 -0
  66. package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
  67. package/dist/cjs/map-style-utils/mapbox-utils.js +155 -0
  68. package/dist/cjs/map-style-utils/mapbox-utils.js.map +1 -0
  69. package/dist/cjs/map-utils.js +76 -0
  70. package/dist/cjs/map-utils.js.map +1 -0
  71. package/dist/cjs/mapbox-utils.js +19 -0
  72. package/dist/cjs/mapbox-utils.js.map +1 -0
  73. package/dist/cjs/notifications-utils.js +69 -0
  74. package/dist/cjs/notifications-utils.js.map +1 -0
  75. package/dist/cjs/observe-dimensions.js +136 -0
  76. package/dist/cjs/observe-dimensions.js.map +1 -0
  77. package/dist/cjs/plot.js +1502 -0
  78. package/dist/cjs/plot.js.map +1 -0
  79. package/dist/cjs/position-utils.js +29 -0
  80. package/dist/cjs/position-utils.js.map +1 -0
  81. package/dist/cjs/projection-utils.js +141 -0
  82. package/dist/cjs/projection-utils.js.map +1 -0
  83. package/dist/cjs/quick-insertion-sort.js +132 -0
  84. package/dist/cjs/quick-insertion-sort.js.map +1 -0
  85. package/dist/cjs/row-data-container.js +291 -0
  86. package/dist/cjs/row-data-container.js.map +1 -0
  87. package/dist/cjs/slider-scale-utils.js +138 -0
  88. package/dist/cjs/slider-scale-utils.js.map +1 -0
  89. package/dist/cjs/split-map-utils.js +117 -0
  90. package/dist/cjs/split-map-utils.js.map +1 -0
  91. package/dist/cjs/strings.js +16 -0
  92. package/dist/cjs/strings.js.map +1 -0
  93. package/dist/cjs/theme-utils.js +46 -0
  94. package/dist/cjs/theme-utils.js.map +1 -0
  95. package/dist/cjs/time.js +321 -0
  96. package/dist/cjs/time.js.map +1 -0
  97. package/dist/cjs/types.js +6 -0
  98. package/dist/cjs/types.js.map +1 -0
  99. package/dist/cjs/utils.js +224 -0
  100. package/dist/cjs/utils.js.map +1 -0
  101. package/dist/column-statistics.d.ts +54 -0
  102. package/dist/data-container-interface.d.ts +16 -1
  103. package/dist/data-container-utils.d.ts +2 -1
  104. package/dist/data-scale-utils.d.ts +5 -0
  105. package/dist/data-utils.d.ts +3 -3
  106. package/dist/dataset-utils.d.ts +11 -28
  107. package/dist/editor-feature-utils.d.ts +30 -0
  108. package/dist/esm/aggregation.js +75 -0
  109. package/dist/esm/aggregation.js.map +1 -0
  110. package/dist/esm/application-config-types.js +3 -0
  111. package/dist/esm/application-config-types.js.map +1 -0
  112. package/dist/esm/application-config.js +167 -0
  113. package/dist/esm/application-config.js.map +1 -0
  114. package/dist/esm/arrow-data-container.js +1136 -0
  115. package/dist/esm/arrow-data-container.js.map +1 -0
  116. package/dist/esm/browser-utils.js +11 -0
  117. package/dist/esm/browser-utils.js.map +1 -0
  118. package/dist/esm/camera-tour.js +92 -0
  119. package/dist/esm/camera-tour.js.map +1 -0
  120. package/dist/esm/camera-utils.js +74 -0
  121. package/dist/esm/camera-utils.js.map +1 -0
  122. package/dist/esm/color-utils.js +435 -0
  123. package/dist/esm/color-utils.js.map +1 -0
  124. package/dist/esm/column-statistics.js +105 -0
  125. package/dist/esm/column-statistics.js.map +1 -0
  126. package/dist/esm/data-container-interface.js +3 -0
  127. package/dist/esm/data-container-interface.js.map +1 -0
  128. package/dist/esm/data-container-utils.js +68 -0
  129. package/dist/esm/data-container-utils.js.map +1 -0
  130. package/dist/esm/data-row.js +106 -0
  131. package/dist/esm/data-row.js.map +1 -0
  132. package/dist/esm/data-scale-utils.js +602 -0
  133. package/dist/esm/data-scale-utils.js.map +1 -0
  134. package/dist/esm/data-utils.js +504 -0
  135. package/dist/esm/data-utils.js.map +1 -0
  136. package/dist/esm/dataset-utils.js +352 -0
  137. package/dist/esm/dataset-utils.js.map +1 -0
  138. package/dist/esm/dom-to-image.js +426 -0
  139. package/dist/esm/dom-to-image.js.map +1 -0
  140. package/dist/esm/dom-utils.js +323 -0
  141. package/dist/esm/dom-utils.js.map +1 -0
  142. package/dist/esm/editor-feature-utils.js +164 -0
  143. package/dist/esm/editor-feature-utils.js.map +1 -0
  144. package/dist/esm/effect-utils.js +333 -0
  145. package/dist/esm/effect-utils.js.map +1 -0
  146. package/dist/esm/export-map-html.js +107 -0
  147. package/dist/esm/export-map-html.js.map +1 -0
  148. package/dist/esm/export-utils.js +297 -0
  149. package/dist/esm/export-utils.js.map +1 -0
  150. package/dist/esm/extract-dataset-utils.js +206 -0
  151. package/dist/esm/extract-dataset-utils.js.map +1 -0
  152. package/dist/esm/filter-utils.js +1701 -0
  153. package/dist/esm/filter-utils.js.map +1 -0
  154. package/dist/esm/format.js +31 -0
  155. package/dist/esm/format.js.map +1 -0
  156. package/dist/esm/gl-utils.js +113 -0
  157. package/dist/esm/gl-utils.js.map +1 -0
  158. package/dist/esm/index.js +55 -0
  159. package/dist/esm/index.js.map +1 -0
  160. package/dist/esm/indexed-data-container.js +210 -0
  161. package/dist/esm/indexed-data-container.js.map +1 -0
  162. package/dist/esm/jenks.js +149 -0
  163. package/dist/esm/jenks.js.map +1 -0
  164. package/dist/esm/locale-utils.js +36 -0
  165. package/dist/esm/locale-utils.js.map +1 -0
  166. package/dist/esm/map-info-utils.js +35 -0
  167. package/dist/esm/map-info-utils.js.map +1 -0
  168. package/dist/esm/map-style-utils/mapbox-gl-style-editor.js +188 -0
  169. package/dist/esm/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
  170. package/dist/esm/map-style-utils/mapbox-utils.js +144 -0
  171. package/dist/esm/map-style-utils/mapbox-utils.js.map +1 -0
  172. package/dist/esm/map-utils.js +72 -0
  173. package/dist/esm/map-utils.js.map +1 -0
  174. package/dist/esm/mapbox-utils.js +13 -0
  175. package/dist/esm/mapbox-utils.js.map +1 -0
  176. package/dist/esm/notifications-utils.js +63 -0
  177. package/dist/esm/notifications-utils.js.map +1 -0
  178. package/dist/esm/observe-dimensions.js +128 -0
  179. package/dist/esm/observe-dimensions.js.map +1 -0
  180. package/dist/esm/plot.js +1460 -0
  181. package/dist/esm/plot.js.map +1 -0
  182. package/dist/esm/position-utils.js +22 -0
  183. package/dist/esm/position-utils.js.map +1 -0
  184. package/dist/esm/projection-utils.js +131 -0
  185. package/dist/esm/projection-utils.js.map +1 -0
  186. package/dist/esm/quick-insertion-sort.js +125 -0
  187. package/dist/esm/quick-insertion-sort.js.map +1 -0
  188. package/dist/esm/row-data-container.js +286 -0
  189. package/dist/esm/row-data-container.js.map +1 -0
  190. package/dist/esm/slider-scale-utils.js +129 -0
  191. package/dist/esm/slider-scale-utils.js.map +1 -0
  192. package/dist/esm/split-map-utils.js +109 -0
  193. package/dist/esm/split-map-utils.js.map +1 -0
  194. package/dist/esm/strings.js +10 -0
  195. package/dist/esm/strings.js.map +1 -0
  196. package/dist/esm/theme-utils.js +38 -0
  197. package/dist/esm/theme-utils.js.map +1 -0
  198. package/dist/esm/time.js +308 -0
  199. package/dist/esm/time.js.map +1 -0
  200. package/dist/esm/types.js +3 -0
  201. package/dist/esm/types.js.map +1 -0
  202. package/dist/esm/utils.js +203 -0
  203. package/dist/esm/utils.js.map +1 -0
  204. package/dist/export-map-html.d.ts +5 -0
  205. package/dist/export-utils.d.ts +31 -3
  206. package/dist/extract-dataset-utils.d.ts +79 -0
  207. package/dist/filter-utils.d.ts +56 -7
  208. package/dist/index.d.ts +20 -9
  209. package/dist/jenks.d.ts +5 -0
  210. package/dist/map-info-utils.d.ts +11 -1
  211. package/dist/map-style-utils/mapbox-gl-style-editor.d.ts +11 -10
  212. package/dist/map-style-utils/mapbox-utils.d.ts +29 -1
  213. package/dist/plot.d.ts +187 -21
  214. package/dist/projection-utils.d.ts +6 -4
  215. package/dist/row-data-container.d.ts +19 -0
  216. package/dist/split-map-utils.d.ts +7 -0
  217. package/dist/theme-utils.d.ts +8 -0
  218. package/dist/time.d.ts +3 -3
  219. package/dist/types.d.ts +2 -0
  220. package/package.json +33 -26
  221. package/dist/aggregation.js +0 -84
  222. package/dist/application-config-types.js +0 -6
  223. package/dist/application-config.js +0 -113
  224. package/dist/arrow-data-container.js +0 -398
  225. package/dist/browser-utils.js +0 -17
  226. package/dist/color-utils.js +0 -462
  227. package/dist/data-container-interface.js +0 -6
  228. package/dist/data-container-utils.js +0 -75
  229. package/dist/data-row.js +0 -110
  230. package/dist/data-scale-utils.js +0 -620
  231. package/dist/data-utils.js +0 -532
  232. package/dist/dataset-utils.js +0 -330
  233. package/dist/dom-to-image.js +0 -433
  234. package/dist/dom-utils.js +0 -349
  235. package/dist/effect-utils.js +0 -318
  236. package/dist/export-map-html.js +0 -38
  237. package/dist/export-utils.js +0 -203
  238. package/dist/filter-utils.js +0 -1274
  239. package/dist/format.js +0 -38
  240. package/dist/gl-utils.js +0 -118
  241. package/dist/indexed-data-container.js +0 -214
  242. package/dist/locale-utils.js +0 -39
  243. package/dist/map-info-utils.js +0 -14
  244. package/dist/map-style-utils/mapbox-gl-style-editor.js +0 -194
  245. package/dist/map-style-utils/mapbox-utils.js +0 -107
  246. package/dist/map-utils.js +0 -72
  247. package/dist/mapbox-utils.js +0 -19
  248. package/dist/noop.d.ts +0 -1
  249. package/dist/noop.js +0 -13
  250. package/dist/notifications-utils.js +0 -69
  251. package/dist/observe-dimensions.js +0 -136
  252. package/dist/plot.js +0 -637
  253. package/dist/position-utils.js +0 -26
  254. package/dist/projection-utils.js +0 -91
  255. package/dist/quick-insertion-sort.js +0 -132
  256. package/dist/row-data-container.js +0 -206
  257. package/dist/searcher-utils.d.ts +0 -1
  258. package/dist/searcher-utils.js +0 -25
  259. package/dist/slider-scale-utils.js +0 -138
  260. package/dist/split-map-utils.js +0 -99
  261. package/dist/strings.js +0 -16
  262. package/dist/time.js +0 -325
  263. package/dist/types.js +0 -6
  264. package/dist/utils.js +0 -224
@@ -0,0 +1,188 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ 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; }
3
+ 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) { _defineProperty(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; }
4
+ // SPDX-License-Identifier: MIT
5
+ // Copyright contributors to the kepler.gl project
6
+
7
+ import memoize from 'es-toolkit/compat/memoize';
8
+ import cloneDeep from 'es-toolkit/compat/cloneDeep';
9
+ import { DEFAULT_LAYER_GROUPS, DEFAULT_MAPBOX_API_URL, NO_MAP_ID, EMPTY_MAPBOX_STYLE } from '@kepler.gl/constants';
10
+ export function getDefaultLayerGroupVisibility(_ref) {
11
+ var _ref$layerGroups = _ref.layerGroups,
12
+ layerGroups = _ref$layerGroups === void 0 ? [] : _ref$layerGroups;
13
+ return layerGroups.reduce(function (accu, layer) {
14
+ return _objectSpread(_objectSpread({}, accu), {}, _defineProperty({}, layer.slug, layer.defaultVisibility));
15
+ }, {});
16
+ }
17
+
18
+ // Explicit function type so declaration emit does not need es-toolkit's unexported MemoizedFunction.
19
+
20
+ var resolver = function resolver(_ref2) {
21
+ var id = _ref2.id,
22
+ _ref2$visibleLayerGro = _ref2.visibleLayerGroups,
23
+ visibleLayerGroups = _ref2$visibleLayerGro === void 0 ? {} : _ref2$visibleLayerGro;
24
+ return "".concat(id, ":").concat(Object.keys(visibleLayerGroups).filter(function (d) {
25
+ return visibleLayerGroups[d];
26
+ }).sort().join('-'));
27
+ };
28
+
29
+ /**
30
+ * Edit preset map style to keep only visible layers
31
+ *
32
+ * @param mapStyle - preset map style
33
+ * @param visibleLayerGroups - visible layers of top map
34
+ * @returns top map style
35
+ */
36
+ export var editTopMapStyle = memoize(function (_ref3) {
37
+ var mapStyle = _ref3.mapStyle,
38
+ visibleLayerGroups = _ref3.visibleLayerGroups;
39
+ var visibleFilters = (mapStyle.layerGroups || []).filter(function (lg) {
40
+ return visibleLayerGroups[lg.slug];
41
+ }).map(function (lg) {
42
+ return lg.filter;
43
+ });
44
+
45
+ // if top map
46
+ // keep only visible layers
47
+ // @ts-expect-error
48
+ var filteredLayers = mapStyle.style.layers.filter(function (layer) {
49
+ return visibleFilters.some(function (match) {
50
+ return match(layer);
51
+ });
52
+ });
53
+ return _objectSpread(_objectSpread({}, mapStyle.style), {}, {
54
+ layers: filteredLayers
55
+ });
56
+ }, resolver);
57
+
58
+ /**
59
+ * Edit preset map style to filter out invisible layers
60
+ *
61
+ * @param {Object} mapStyle - preset map style
62
+ * @param {Object} visibleLayerGroups - visible layers of bottom map
63
+ * @returns {Object} bottom map style
64
+ */
65
+ export var editBottomMapStyle = memoize(function (_ref4) {
66
+ var id = _ref4.id,
67
+ mapStyle = _ref4.mapStyle,
68
+ visibleLayerGroups = _ref4.visibleLayerGroups;
69
+ if (id === NO_MAP_ID) {
70
+ return EMPTY_MAPBOX_STYLE;
71
+ }
72
+ var invisibleFilters = (mapStyle.layerGroups || []).filter(function (lg) {
73
+ return !visibleLayerGroups[lg.slug];
74
+ }).map(function (lg) {
75
+ return lg.filter;
76
+ });
77
+
78
+ // if bottom map
79
+ // filter out invisible layers
80
+ // @ts-expect-error
81
+ var filteredLayers = mapStyle.style.layers.filter(function (layer) {
82
+ return invisibleFilters.every(function (match) {
83
+ return !match(layer);
84
+ });
85
+ });
86
+ return _objectSpread(_objectSpread({}, mapStyle.style), {}, {
87
+ layers: filteredLayers
88
+ });
89
+ }, resolver);
90
+ export function getStyleDownloadUrl(styleUrl, accessToken, mapboxApiUrl) {
91
+ if (styleUrl.startsWith('http')) {
92
+ return styleUrl;
93
+ }
94
+
95
+ // mapbox://styles/jckr/cjhcl0lxv13di2rpfoytdbdyj
96
+ if (styleUrl.startsWith('mapbox://styles')) {
97
+ var styleId = styleUrl.replace('mapbox://styles/', '');
98
+
99
+ // https://api.mapbox.com/styles/v1/heshan0131/cjg1bfumo1cwm2rlrjxkinfgw?pluginName=Keplergl&access_token=<token>
100
+ return "".concat(mapboxApiUrl || DEFAULT_MAPBOX_API_URL, "/styles/v1/").concat(styleId, "?pluginName=Keplergl&access_token=").concat(accessToken);
101
+ }
102
+
103
+ // style url not recognized
104
+ return null;
105
+ }
106
+
107
+ /**
108
+ * Generate static map image from style Url to be used as icon
109
+ * @param param
110
+ * @param param.styleUrl
111
+ * @param param.mapboxApiAccessToken
112
+ * @param param.mapboxApiUrl
113
+ * @param param.mapState
114
+ * @param param.mapW
115
+ * @param param.mapH
116
+ */
117
+ export function getStyleImageIcon(_ref5) {
118
+ var styleUrl = _ref5.styleUrl,
119
+ mapboxApiAccessToken = _ref5.mapboxApiAccessToken,
120
+ _ref5$mapboxApiUrl = _ref5.mapboxApiUrl,
121
+ mapboxApiUrl = _ref5$mapboxApiUrl === void 0 ? DEFAULT_MAPBOX_API_URL : _ref5$mapboxApiUrl,
122
+ _ref5$mapState = _ref5.mapState,
123
+ mapState = _ref5$mapState === void 0 ? {
124
+ longitude: -122.3391,
125
+ latitude: 37.7922,
126
+ zoom: 9
127
+ } : _ref5$mapState,
128
+ _ref5$mapW = _ref5.mapW,
129
+ mapW = _ref5$mapW === void 0 ? 400 : _ref5$mapW,
130
+ _ref5$mapH = _ref5.mapH,
131
+ mapH = _ref5$mapH === void 0 ? 300 : _ref5$mapH;
132
+ var styleId = styleUrl.replace('mapbox://styles/', '');
133
+ 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");
134
+ }
135
+ export function scaleMapStyleByResolution(mapboxStyle, scale) {
136
+ if (scale !== 1 && mapboxStyle) {
137
+ var labelLayerGroup = DEFAULT_LAYER_GROUPS.find(function (lg) {
138
+ return lg.slug === 'label';
139
+ });
140
+ // @ts-ignore
141
+ var labelLayerFilter = labelLayerGroup.filter;
142
+ var zoomOffset = Math.log2(scale);
143
+ var copyStyle = cloneDeep(mapboxStyle);
144
+ (copyStyle.layers || []).forEach(function (d) {
145
+ // edit minzoom and maxzoom
146
+ if (d.maxzoom) {
147
+ d.maxzoom = Math.max(d.maxzoom + zoomOffset, 1);
148
+
149
+ // The maximum zoom is 24
150
+ // https://github.com/visgl/react-map-gl/blob/master/docs/api-reference/map.md#maxzoom-number-maxzoom
151
+ if (d.maxzoom > 24) {
152
+ d.maxzoom = 24;
153
+ }
154
+ }
155
+ if (d.minzoom) {
156
+ d.minzoom = Math.max(d.minzoom + zoomOffset, 1);
157
+ }
158
+
159
+ // edit text size
160
+ if (labelLayerFilter(d)) {
161
+ if (d.layout && d.layout['text-size'] && Array.isArray(d.layout['text-size'].stops)) {
162
+ d.layout['text-size'].stops.forEach(function (stop) {
163
+ // zoom
164
+ stop[0] = Math.max(stop[0] + zoomOffset, 1);
165
+ // size
166
+ stop[1] *= scale;
167
+ });
168
+ }
169
+ }
170
+ });
171
+ return copyStyle;
172
+ }
173
+ return mapboxStyle;
174
+ }
175
+
176
+ /**
177
+ * When switch to a new style, try to keep current layer group visibility
178
+ * by merging default and current
179
+ * @param {Object} defaultLayerGroup
180
+ * @param {Object} currentLayerGroup
181
+ * @return {Object} mergedLayerGroups
182
+ */
183
+ export function mergeLayerGroupVisibility(defaultLayerGroup, currentLayerGroup) {
184
+ return Object.keys(defaultLayerGroup).reduce(function (accu, key) {
185
+ return _objectSpread(_objectSpread({}, accu), Object.prototype.hasOwnProperty.call(currentLayerGroup, key) ? _defineProperty({}, key, currentLayerGroup[key]) : {});
186
+ }, defaultLayerGroup);
187
+ }
188
+ //# sourceMappingURL=mapbox-gl-style-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapbox-gl-style-editor.js","names":["memoize","cloneDeep","DEFAULT_LAYER_GROUPS","DEFAULT_MAPBOX_API_URL","NO_MAP_ID","EMPTY_MAPBOX_STYLE","getDefaultLayerGroupVisibility","_ref","_ref$layerGroups","layerGroups","reduce","accu","layer","_objectSpread","_defineProperty","slug","defaultVisibility","resolver","_ref2","id","_ref2$visibleLayerGro","visibleLayerGroups","concat","Object","keys","filter","d","sort","join","editTopMapStyle","_ref3","mapStyle","visibleFilters","lg","map","filteredLayers","style","layers","some","match","editBottomMapStyle","_ref4","invisibleFilters","every","getStyleDownloadUrl","styleUrl","accessToken","mapboxApiUrl","startsWith","styleId","replace","getStyleImageIcon","_ref5","mapboxApiAccessToken","_ref5$mapboxApiUrl","_ref5$mapState","mapState","longitude","latitude","zoom","_ref5$mapW","mapW","_ref5$mapH","mapH","scaleMapStyleByResolution","mapboxStyle","scale","labelLayerGroup","find","labelLayerFilter","zoomOffset","Math","log2","copyStyle","forEach","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":";;;AAAA;AACA;;AAEA,OAAOA,OAAO,MAAM,2BAA2B;AAC/C,OAAOC,SAAS,MAAM,6BAA6B;AACnD,SACEC,oBAAoB,EACpBC,sBAAsB,EACtBC,SAAS,EACTC,kBAAkB,QACb,sBAAsB;AAG7B,OAAO,SAASC,8BAA8BA,CAAAC,IAAA,EAAkD;EAAA,IAAAC,gBAAA,GAAAD,IAAA,CAAhDE,WAAW;IAAXA,WAAW,GAAAD,gBAAA,cAAG,EAAE,GAAAA,gBAAA;EAC9D,OAAOC,WAAW,CAACC,MAAM,CACvB,UAACC,IAAI,EAAEC,KAAK;IAAA,OAAAC,aAAA,CAAAA,aAAA,KACPF,IAAI,OAAAG,eAAA,KACNF,KAAK,CAACG,IAAI,EAAGH,KAAK,CAACI,iBAAiB;EAAA,CACrC,EACF,CAAC,CACH,CAAC;AACH;;AAQA;;AAGA,IAAMC,QAAQ,GAAG,SAAXA,QAAQA,CAAAC,KAAA;EAAA,IAAKC,EAAE,GAAAD,KAAA,CAAFC,EAAE;IAAAC,qBAAA,GAAAF,KAAA,CAAEG,kBAAkB;IAAlBA,kBAAkB,GAAAD,qBAAA,cAAG,CAAC,CAAC,GAAAA,qBAAA;EAAA,UAAAE,MAAA,CACzCH,EAAE,OAAAG,MAAA,CAAIC,MAAM,CAACC,IAAI,CAACH,kBAAkB,CAAC,CACrCI,MAAM,CAAC,UAAAC,CAAC;IAAA,OAAIL,kBAAkB,CAACK,CAAC,CAAC;EAAA,EAAC,CAClCC,IAAI,CAAC,CAAC,CACNC,IAAI,CAAC,GAAG,CAAC;AAAA,CAAE;;AAEhB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMC,eAA6B,GAAG7B,OAAO,C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,CAACC,IAAI,CAACJ,iBAAiB,EAAEC,GAAG,CAAC,GAAAxE,eAAA,KAC1DwE,GAAG,EAAGD,iBAAiB,CAACC,GAAG,CAAC,IAC9B,CAAC,CAAC;EAAA,CACN,EACFF,iBACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,144 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright contributors to the kepler.gl project
4
+
5
+ // import {isMapboxURL, transformMapboxUrl} from 'maplibregl-mapbox-request-transformer';
6
+
7
+ import { MAP_LIB_OPTIONS } from '@kepler.gl/constants';
8
+
9
+ /**
10
+ * Determines whether a Map Style is using Mapbox Tiles
11
+ * @param {any} mapStyle the mapStyle to check
12
+ * @returns true if the style is using Mapbox tiles
13
+ */
14
+ export function isStyleUsingMapboxTiles(mapStyle) {
15
+ var _mapStyle$stylesheet;
16
+ var sources = ((_mapStyle$stylesheet = mapStyle.stylesheet) === null || _mapStyle$stylesheet === void 0 ? void 0 : _mapStyle$stylesheet.sources) || {};
17
+ return Object.keys(sources).some(function (sourceId) {
18
+ var _ref = sources[sourceId] || {},
19
+ url = _ref.url,
20
+ tiles = _ref.tiles;
21
+ if (url) {
22
+ return url.toLowerCase().startsWith('mapbox://');
23
+ }
24
+ if (tiles) {
25
+ return tiles.some(function (tileUrl) {
26
+ return tileUrl.toLowerCase().startsWith('mapbox://');
27
+ });
28
+ }
29
+ return false;
30
+ });
31
+ }
32
+ export function isStyleUsingOpenStreetMapTiles(mapStyle) {
33
+ var _mapStyle$stylesheet2;
34
+ var sources = (mapStyle === null || mapStyle === void 0 || (_mapStyle$stylesheet2 = mapStyle.stylesheet) === null || _mapStyle$stylesheet2 === void 0 ? void 0 : _mapStyle$stylesheet2.sources) || {};
35
+ return Object.keys(sources).some(function (sourceId) {
36
+ var _ref2 = sources[sourceId] || {},
37
+ attribution = _ref2.attribution;
38
+ if (typeof attribution === 'string') {
39
+ return attribution.includes('openstreetmap.org');
40
+ }
41
+ return false;
42
+ });
43
+ }
44
+
45
+ /**
46
+ * Minimal structural contract for the MapLibre/Mapbox map instance used by the
47
+ * attribution helpers below. Only the members actually read are declared;
48
+ * everything is optional because these helpers may be called before the map is
49
+ * fully initialized (guarded by optional chaining + try/catch at runtime).
50
+ *
51
+ * `getSource` returns `any` on purpose: the concrete MapLibre/Mapbox source
52
+ * union (GeoJSONSource, VectorSource, …) is not structurally assignable to a
53
+ * `{attribution?}` shape, and we only ever read an optional `attribution`
54
+ * string off it. Declaring the two getters still catches passing a non-map.
55
+ */
56
+
57
+ /**
58
+ * Checks resolved map sources for OpenStreetMap attribution.
59
+ * CARTO basemaps don't have attribution in the raw style JSON;
60
+ * it only appears after MapLibre resolves the TileJSON.
61
+ * Uses map.getSource() to access the resolved source with TileJSON metadata.
62
+ */
63
+ export function mapHasOpenStreetMapAttribution(map) {
64
+ try {
65
+ var _map$getStyle;
66
+ var style = map === null || map === void 0 || (_map$getStyle = map.getStyle) === null || _map$getStyle === void 0 ? void 0 : _map$getStyle.call(map);
67
+ if (!(style !== null && style !== void 0 && style.sources)) return false;
68
+ return Object.keys(style.sources).some(function (sourceId) {
69
+ var _map$getSource;
70
+ var source = map === null || map === void 0 || (_map$getSource = map.getSource) === null || _map$getSource === void 0 ? void 0 : _map$getSource.call(map, sourceId);
71
+ var attribution = source === null || source === void 0 ? void 0 : source.attribution;
72
+ if (typeof attribution === 'string') {
73
+ return attribution.toLowerCase().includes('openstreetmap');
74
+ }
75
+ return false;
76
+ });
77
+ } catch (_unused) {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Collects the attribution strings declared by the resolved map sources.
84
+ * Custom basemap styles (e.g. OpenFreeMap, OpenMapTiles) declare their own
85
+ * attribution in the source's TileJSON, which only becomes available after
86
+ * MapLibre resolves it. Unlike {@link mapHasOpenStreetMapAttribution}, this
87
+ * preserves the full attribution text instead of collapsing it to a boolean,
88
+ * so custom attributions are not lost.
89
+ * @param map the resolved MapLibre/Mapbox map instance
90
+ * @returns de-duplicated list of attribution HTML strings, order preserved
91
+ */
92
+ export function getBaseMapAttributions(map) {
93
+ try {
94
+ var _map$getStyle2;
95
+ var style = map === null || map === void 0 || (_map$getStyle2 = map.getStyle) === null || _map$getStyle2 === void 0 ? void 0 : _map$getStyle2.call(map);
96
+ if (!(style !== null && style !== void 0 && style.sources)) return [];
97
+ var seen = new Set();
98
+ Object.keys(style.sources).forEach(function (sourceId) {
99
+ var _map$getSource2;
100
+ var source = map === null || map === void 0 || (_map$getSource2 = map.getSource) === null || _map$getSource2 === void 0 ? void 0 : _map$getSource2.call(map, sourceId);
101
+ var attribution = source === null || source === void 0 ? void 0 : source.attribution;
102
+ if (typeof attribution === 'string') {
103
+ var trimmed = attribution.trim();
104
+ if (trimmed) {
105
+ seen.add(trimmed);
106
+ }
107
+ }
108
+ });
109
+ return _toConsumableArray(seen);
110
+ } catch (_unused2) {
111
+ return [];
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Transform mapbox protocol so can be used with maplibre
117
+ * @param mapboxKey mapbox api key
118
+ * @returns transformed url
119
+ */
120
+ export var transformRequest = function transformRequest(_mapboxKey) {
121
+ return function (url, _resourceType) {
122
+ /*
123
+ if (isMapboxURL(url)) {
124
+ // ! TODO - use MapBox directly?
125
+ return transformMapboxUrl(url, resourceType, mapboxKey);
126
+ }
127
+ */
128
+
129
+ return {
130
+ url: url
131
+ };
132
+ };
133
+ };
134
+ export var getBaseMapLibrary = function getBaseMapLibrary(baseMapStyle) {
135
+ if (baseMapStyle) {
136
+ var _baseMapStyle$url, _baseMapStyle$url2, _baseMapStyle$style;
137
+ 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')) {
138
+ return MAP_LIB_OPTIONS.MAPBOX;
139
+ }
140
+ if ((_baseMapStyle$style = baseMapStyle.style) !== null && _baseMapStyle$style !== void 0 && (_baseMapStyle$style = _baseMapStyle$style.sources) !== null && _baseMapStyle$style !== void 0 && _baseMapStyle$style['mapbox']) return MAP_LIB_OPTIONS.MAPBOX;
141
+ }
142
+ return MAP_LIB_OPTIONS.MAPLIBRE;
143
+ };
144
+ //# sourceMappingURL=mapbox-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapbox-utils.js","names":["MAP_LIB_OPTIONS","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","_toConsumableArray","_unused2","transformRequest","_mapboxKey","_resourceType","getBaseMapLibrary","baseMapStyle","_baseMapStyle$url","_baseMapStyle$url2","_baseMapStyle$style","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":";AAAA;AACA;;AAEA;;AAEA,SAAQA,eAAe,QAA2B,sBAAsB;;AAExE;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAACC,QAAQ,EAAE;EAAA,IAAAC,oBAAA;EAChD,IAAMC,OAAO,GAAG,EAAAD,oBAAA,GAAAD,QAAQ,CAACG,UAAU,cAAAF,oBAAA,uBAAnBA,oBAAA,CAAqBC,OAAO,KAAI,CAAC,CAAC;EAElD,OAAOE,MAAM,CAACC,IAAI,CAACH,OAAO,CAAC,CAACI,IAAI,CAAC,UAAAC,QAAQ,EAAI;IAC3C,IAAAC,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,eAAe,CAACkD,MAAM;IAC/B;IAEA,KAAAD,mBAAA,GAAKH,YAAY,CAACtB,KAAK,cAAAyB,mBAAA,gBAAAA,mBAAA,GAAnBA,mBAAA,CAA0C7C,OAAO,cAAA6C,mBAAA,eAAjDA,mBAAA,CAAoD,QAAQ,CAAC,EAC/D,OAAOjD,eAAe,CAACkD,MAAM;EACjC;EAEA,OAAOlD,eAAe,CAACmD,QAAQ;AACjC,CAAC","ignoreList":[]}
@@ -0,0 +1,72 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ var _excluded = ["width", "height"];
4
+ 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; }
5
+ 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) { _defineProperty(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; }
6
+ // SPDX-License-Identifier: MIT
7
+ // Copyright contributors to the kepler.gl project
8
+
9
+ import { WebMercatorViewport } from '@math.gl/web-mercator';
10
+ // @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.
11
+ import { _GlobeViewport as GlobeViewport } from '@deck.gl/core';
12
+ import { TRANSITION_DURATION } from '@kepler.gl/constants';
13
+ import { validateLatitude, validateLongitude } from './data-utils';
14
+
15
+ /**
16
+ * Validates a ViewPort object.
17
+ * It retains all properties of the original ViewPort object,
18
+ * but ensures that the latitude is within the defined bounds.
19
+ * @param viewport - The ViewPort object to validate.
20
+ * @returns A new ViewPort object with validated latitude.
21
+ */
22
+ export var validateViewPort = function validateViewPort(viewport) {
23
+ return _objectSpread(_objectSpread(_objectSpread({}, viewport), viewport.latitude ? {
24
+ latitude: validateLatitude(viewport.latitude)
25
+ } : {}), viewport.longitude ? {
26
+ longitude: validateLongitude(viewport.longitude)
27
+ } : {});
28
+ };
29
+ export var onViewPortChange = function onViewPortChange(viewState, onUpdateMap, onViewStateChange) {
30
+ var primary = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
31
+ var mapIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
32
+ var _viewState$width = viewState.width,
33
+ width = _viewState$width === void 0 ? 0 : _viewState$width,
34
+ _viewState$height = viewState.height,
35
+ height = _viewState$height === void 0 ? 0 : _viewState$height,
36
+ restViewState = _objectWithoutProperties(viewState, _excluded);
37
+ // react-map-gl sends 0,0 dimensions during initialization
38
+ // after we have received proper dimensions from observeDimensions
39
+ var next = _objectSpread(_objectSpread({}, width > 0 && height > 0 ? viewState : restViewState), {}, {
40
+ // enabling transition in two maps may lead to endless update loops
41
+ transitionDuration: primary ? TRANSITION_DURATION : 0
42
+ });
43
+ if (onViewStateChange && typeof onViewStateChange === 'function') {
44
+ onViewStateChange(next);
45
+ }
46
+ onUpdateMap(next, mapIndex);
47
+ };
48
+ export var getMapLayersFromSplitMaps = function getMapLayersFromSplitMaps(splitMaps, mapIndex) {
49
+ var _splitMaps;
50
+ return (_splitMaps = splitMaps[mapIndex || 0]) === null || _splitMaps === void 0 ? void 0 : _splitMaps.layers;
51
+ };
52
+
53
+ /**
54
+ * Generates a viewport from a map state.
55
+ * @param mapState
56
+ * @returns A viewport.
57
+ */
58
+ export var getViewportFromMapState = function getViewportFromMapState(mapState) {
59
+ var viewPort;
60
+ try {
61
+ var _mapState$globe;
62
+ if ((_mapState$globe = mapState.globe) !== null && _mapState$globe !== void 0 && _mapState$globe.enabled) {
63
+ viewPort = new GlobeViewport(mapState);
64
+ } else {
65
+ viewPort = new WebMercatorViewport(mapState);
66
+ }
67
+ } catch (_unused) {
68
+ viewPort = new WebMercatorViewport(validateViewPort(mapState));
69
+ }
70
+ return viewPort;
71
+ };
72
+ //# sourceMappingURL=map-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-utils.js","names":["WebMercatorViewport","_GlobeViewport","GlobeViewport","TRANSITION_DURATION","validateLatitude","validateLongitude","validateViewPort","viewport","_objectSpread","latitude","longitude","onViewPortChange","viewState","onUpdateMap","onViewStateChange","primary","arguments","length","undefined","mapIndex","_viewState$width","width","_viewState$height","height","restViewState","_objectWithoutProperties","_excluded","next","transitionDuration","getMapLayersFromSplitMaps","splitMaps","_splitMaps","layers","getViewportFromMapState","mapState","viewPort","_mapState$globe","globe","enabled","_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":";;;;;AAAA;AACA;;AAEA,SAAQA,mBAAmB,QAAO,uBAAuB;AACzD;AACA,SAAQC,cAAc,IAAIC,aAAa,QAAO,eAAe;AAE7D,SAAQC,mBAAmB,QAAO,sBAAsB;AAGxD,SAAQC,gBAAgB,EAAEC,iBAAiB,QAAO,cAAc;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAC3BC,QAAW,EACL;EACN,OAAAC,aAAA,CAAAA,aAAA,CAAAA,aAAA,KACKD,QAAQ,GAGPA,QAAQ,CAACE,QAAQ,GAAG;IAACA,QAAQ,EAAEL,gBAAgB,CAACG,QAAQ,CAACE,QAAQ;EAAC,CAAC,GAA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AA,uBAAxBA,UAAA,CAA0BC,MAAM;AACzC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMC,uBAAuB,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,IAAIjC,aAAa,CAACgC,QAAQ,CAAC;IACxC,CAAC,MAAM;MACLC,QAAQ,GAAG,IAAInC,mBAAmB,CAACkC,QAAQ,CAAC;IAC9C;EACF,CAAC,CAAC,OAAAK,OAAA,EAAM;IACNJ,QAAQ,GAAG,IAAInC,mBAAmB,CAACM,gBAAgB,CAAC4B,QAAQ,CAAC,CAAC;EAChE;EAEA,OAAOC,QAAQ;AACjB,CAAC","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright contributors to the kepler.gl project
3
+
4
+ /**
5
+ * This method validates mapbox token.
6
+ * This token provides a simple synchronous validation
7
+ * @param {string} token the Mapbox token to validate
8
+ * @return {boolean} true if token is valid, false otherwise
9
+ */
10
+ export var validateToken = function validateToken(token) {
11
+ return (token || '') !== '';
12
+ };
13
+ //# sourceMappingURL=mapbox-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapbox-utils.js","names":["validateToken","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;AACA,OAAO,IAAMA,aAAa,GAAG,SAAhBA,aAAaA,CAAIC,KAAa;EAAA,OAAc,CAACA,KAAK,IAAI,EAAE,MAAM,EAAE;AAAA","ignoreList":[]}
@@ -0,0 +1,63 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["message", "type", "topic", "id", "count"];
4
+ 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; }
5
+ 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) { _defineProperty(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; }
6
+ // SPDX-License-Identifier: MIT
7
+ // Copyright contributors to the kepler.gl project
8
+
9
+ import { generateHashId } from '@kepler.gl/common-utils';
10
+ import { DEFAULT_NOTIFICATION_MESSAGE, DEFAULT_NOTIFICATION_TOPICS, DEFAULT_NOTIFICATION_TYPES, DEFAULT_UUID_COUNT, BUG_REPORT_LINK } from '@kepler.gl/constants';
11
+ /**
12
+ * Creates a notification
13
+ */
14
+ export function createNotification(_ref) {
15
+ var _ref$message = _ref.message,
16
+ message = _ref$message === void 0 ? DEFAULT_NOTIFICATION_MESSAGE : _ref$message,
17
+ _ref$type = _ref.type,
18
+ type = _ref$type === void 0 ? DEFAULT_NOTIFICATION_TYPES.info : _ref$type,
19
+ _ref$topic = _ref.topic,
20
+ topic = _ref$topic === void 0 ? DEFAULT_NOTIFICATION_TOPICS.global : _ref$topic,
21
+ _ref$id = _ref.id,
22
+ id = _ref$id === void 0 ? generateHashId(DEFAULT_UUID_COUNT) : _ref$id,
23
+ _ref$count = _ref.count,
24
+ count = _ref$count === void 0 ? 1 : _ref$count,
25
+ options = _objectWithoutProperties(_ref, _excluded);
26
+ return _objectSpread(_objectSpread({}, options), {}, {
27
+ id: id,
28
+ message: message,
29
+ type: type,
30
+ topic: topic,
31
+ count: count > 99 ? 99 : count // no more than 2 digits
32
+ });
33
+ }
34
+
35
+ /**
36
+ * Creates an error notification
37
+ * @param options
38
+ * @returns {{topic, id, message, type: (null|number)}}
39
+ */
40
+ export var errorNotification = function errorNotification(options) {
41
+ return _objectSpread(_objectSpread({}, createNotification(options)), {}, {
42
+ type: DEFAULT_NOTIFICATION_TYPES.error
43
+ });
44
+ };
45
+
46
+ /**
47
+ * Creates a success notification
48
+ * @param options
49
+ * @returns {{topic, id, message, type: null}}
50
+ */
51
+ export var successNotification = function successNotification(options) {
52
+ return _objectSpread(_objectSpread({}, createNotification(options)), {}, {
53
+ type: DEFAULT_NOTIFICATION_TYPES.success
54
+ });
55
+ };
56
+ export var exportImageError = function exportImageError(options) {
57
+ return errorNotification(_objectSpread(_objectSpread({}, options), {}, {
58
+ id: 'EXPORT_IMAGE_ERROR_ID',
59
+ topic: DEFAULT_NOTIFICATION_TOPICS.global,
60
+ message: "Failed to export image, please take a screenshot of the javascript console, report the with [this link](".concat(BUG_REPORT_LINK, ") ")
61
+ }));
62
+ };
63
+ //# sourceMappingURL=notifications-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notifications-utils.js","names":["generateHashId","DEFAULT_NOTIFICATION_MESSAGE","DEFAULT_NOTIFICATION_TOPICS","DEFAULT_NOTIFICATION_TYPES","DEFAULT_UUID_COUNT","BUG_REPORT_LINK","createNotification","_ref","_ref$message","message","_ref$type","type","info","_ref$topic","topic","global","_ref$id","id","_ref$count","count","options","_objectWithoutProperties","_excluded","_objectSpread","errorNotification","error","successNotification","success","exportImageError","concat"],"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":";;;;;AAAA;AACA;;AAEA,SAAQA,cAAc,QAAO,yBAAyB;AAEtD,SACEC,4BAA4B,EAC5BC,2BAA2B,EAC3BC,0BAA0B,EAC1BC,kBAAkB,EAClBC,eAAe,QACV,sBAAsB;AAU7B;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAAC,IAAA,EAOM;EAAA,IAAAC,YAAA,GAAAD,IAAA,CANtCE,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