@kepler.gl/reducers 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 (145) hide show
  1. package/dist/cjs/column-edit-reconcile.js +100 -0
  2. package/dist/cjs/column-edit-reconcile.js.map +1 -0
  3. package/dist/cjs/combined-updaters.js +676 -0
  4. package/dist/cjs/combined-updaters.js.map +1 -0
  5. package/dist/cjs/composer-helpers.js +101 -0
  6. package/dist/cjs/composer-helpers.js.map +1 -0
  7. package/dist/cjs/composers.js +21 -0
  8. package/dist/cjs/composers.js.map +1 -0
  9. package/dist/cjs/core.js +105 -0
  10. package/dist/cjs/core.js.map +1 -0
  11. package/dist/cjs/data-utils.js +53 -0
  12. package/dist/cjs/data-utils.js.map +1 -0
  13. package/dist/cjs/dataset-ops-updaters.js +375 -0
  14. package/dist/cjs/dataset-ops-updaters.js.map +1 -0
  15. package/dist/cjs/export-utils.js +163 -0
  16. package/dist/cjs/export-utils.js.map +1 -0
  17. package/dist/cjs/index.js +348 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/interaction-utils.js +275 -0
  20. package/dist/cjs/interaction-utils.js.map +1 -0
  21. package/dist/cjs/layer-utils.js +797 -0
  22. package/dist/cjs/layer-utils.js.map +1 -0
  23. package/dist/cjs/map-state-updaters.js +709 -0
  24. package/dist/cjs/map-state-updaters.js.map +1 -0
  25. package/dist/cjs/map-state.js +35 -0
  26. package/dist/cjs/map-state.js.map +1 -0
  27. package/dist/cjs/map-style-updaters.js +659 -0
  28. package/dist/cjs/map-style-updaters.js.map +1 -0
  29. package/dist/cjs/map-style.js +33 -0
  30. package/dist/cjs/map-style.js.map +1 -0
  31. package/dist/cjs/merger-handler.js +105 -0
  32. package/dist/cjs/merger-handler.js.map +1 -0
  33. package/dist/cjs/middleware.js +25 -0
  34. package/dist/cjs/middleware.js.map +1 -0
  35. package/dist/cjs/provider-state-updaters.js +464 -0
  36. package/dist/cjs/provider-state-updaters.js.map +1 -0
  37. package/dist/cjs/provider-state.js +34 -0
  38. package/dist/cjs/provider-state.js.map +1 -0
  39. package/dist/cjs/root.js +207 -0
  40. package/dist/cjs/root.js.map +1 -0
  41. package/dist/cjs/ui-state-updaters.js +1096 -0
  42. package/dist/cjs/ui-state-updaters.js.map +1 -0
  43. package/dist/cjs/ui-state.js +36 -0
  44. package/dist/cjs/ui-state.js.map +1 -0
  45. package/dist/cjs/vis-state-merger.js +1439 -0
  46. package/dist/cjs/vis-state-merger.js.map +1 -0
  47. package/dist/cjs/vis-state-selectors.js +50 -0
  48. package/dist/cjs/vis-state-selectors.js.map +1 -0
  49. package/dist/cjs/vis-state-updaters.js +6749 -0
  50. package/dist/cjs/vis-state-updaters.js.map +1 -0
  51. package/dist/cjs/vis-state.js +35 -0
  52. package/dist/cjs/vis-state.js.map +1 -0
  53. package/dist/column-edit-reconcile.d.ts +4 -0
  54. package/dist/combined-updaters.d.ts +61 -15
  55. package/dist/composers.d.ts +17 -2
  56. package/dist/dataset-ops-updaters.d.ts +21 -0
  57. package/dist/esm/column-edit-reconcile.js +95 -0
  58. package/dist/esm/column-edit-reconcile.js.map +1 -0
  59. package/dist/esm/combined-updaters.js +669 -0
  60. package/dist/esm/combined-updaters.js.map +1 -0
  61. package/dist/esm/composer-helpers.js +85 -0
  62. package/dist/esm/composer-helpers.js.map +1 -0
  63. package/dist/esm/composers.js +15 -0
  64. package/dist/esm/composers.js.map +1 -0
  65. package/dist/esm/core.js +101 -0
  66. package/dist/esm/core.js.map +1 -0
  67. package/dist/esm/data-utils.js +47 -0
  68. package/dist/esm/data-utils.js.map +1 -0
  69. package/dist/esm/dataset-ops-updaters.js +357 -0
  70. package/dist/esm/dataset-ops-updaters.js.map +1 -0
  71. package/dist/esm/export-utils.js +158 -0
  72. package/dist/esm/export-utils.js.map +1 -0
  73. package/dist/esm/index.js +62 -0
  74. package/dist/esm/index.js.map +1 -0
  75. package/dist/esm/interaction-utils.js +262 -0
  76. package/dist/esm/interaction-utils.js.map +1 -0
  77. package/dist/esm/layer-utils.js +762 -0
  78. package/dist/esm/layer-utils.js.map +1 -0
  79. package/dist/esm/map-state-updaters.js +701 -0
  80. package/dist/esm/map-state-updaters.js.map +1 -0
  81. package/dist/esm/map-state.js +29 -0
  82. package/dist/esm/map-state.js.map +1 -0
  83. package/dist/esm/map-style-updaters.js +652 -0
  84. package/dist/esm/map-style-updaters.js.map +1 -0
  85. package/dist/esm/map-style.js +27 -0
  86. package/dist/esm/map-style.js.map +1 -0
  87. package/dist/esm/merger-handler.js +96 -0
  88. package/dist/esm/merger-handler.js.map +1 -0
  89. package/dist/esm/middleware.js +17 -0
  90. package/dist/esm/middleware.js.map +1 -0
  91. package/dist/esm/provider-state-updaters.js +458 -0
  92. package/dist/esm/provider-state-updaters.js.map +1 -0
  93. package/dist/esm/provider-state.js +28 -0
  94. package/dist/esm/provider-state.js.map +1 -0
  95. package/dist/esm/root.js +201 -0
  96. package/dist/esm/root.js.map +1 -0
  97. package/dist/esm/ui-state-updaters.js +1091 -0
  98. package/dist/esm/ui-state-updaters.js.map +1 -0
  99. package/dist/esm/ui-state.js +30 -0
  100. package/dist/esm/ui-state.js.map +1 -0
  101. package/dist/esm/vis-state-merger.js +1403 -0
  102. package/dist/esm/vis-state-merger.js.map +1 -0
  103. package/dist/esm/vis-state-selectors.js +44 -0
  104. package/dist/esm/vis-state-selectors.js.map +1 -0
  105. package/dist/esm/vis-state-updaters.js +6586 -0
  106. package/dist/esm/vis-state-updaters.js.map +1 -0
  107. package/dist/esm/vis-state.js +29 -0
  108. package/dist/esm/vis-state.js.map +1 -0
  109. package/dist/export-utils.d.ts +2 -2
  110. package/dist/interaction-utils.d.ts +26 -3
  111. package/dist/layer-utils.d.ts +18 -0
  112. package/dist/map-state-updaters.d.ts +13 -0
  113. package/dist/map-style-updaters.d.ts +1 -3
  114. package/dist/middleware.d.ts +2 -2
  115. package/dist/root.d.ts +1 -1
  116. package/dist/ui-state-updaters.d.ts +62 -2
  117. package/dist/vis-state-merger.d.ts +23 -5
  118. package/dist/vis-state-selectors.d.ts +53 -6
  119. package/dist/vis-state-updaters.d.ts +196 -15
  120. package/dist/vis-state.d.ts +56 -0
  121. package/package.json +37 -32
  122. package/dist/combined-updaters.js +0 -412
  123. package/dist/composer-helpers.js +0 -101
  124. package/dist/composers.js +0 -23
  125. package/dist/core.js +0 -105
  126. package/dist/data-utils.js +0 -53
  127. package/dist/export-utils.js +0 -91
  128. package/dist/index.js +0 -349
  129. package/dist/interaction-utils.js +0 -105
  130. package/dist/layer-utils.js +0 -633
  131. package/dist/map-state-updaters.js +0 -516
  132. package/dist/map-state.js +0 -35
  133. package/dist/map-style-updaters.js +0 -661
  134. package/dist/map-style.js +0 -34
  135. package/dist/merger-handler.js +0 -105
  136. package/dist/middleware.js +0 -27
  137. package/dist/provider-state-updaters.js +0 -466
  138. package/dist/provider-state.js +0 -35
  139. package/dist/root.js +0 -207
  140. package/dist/ui-state-updaters.js +0 -890
  141. package/dist/ui-state.js +0 -37
  142. package/dist/vis-state-merger.js +0 -1193
  143. package/dist/vis-state-selectors.js +0 -30
  144. package/dist/vis-state-updaters.js +0 -4115
  145. package/dist/vis-state.js +0 -36
@@ -0,0 +1,659 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.getDefaultMapStyles = exports.editCustomMapStyleUpdater = exports.addCustomMapStyleUpdater = exports.INITIAL_MAP_STYLE = void 0;
9
+ exports.getInitialInputStyle = getInitialInputStyle;
10
+ exports.getMapStyles = getMapStyles;
11
+ exports.setBackgroundColorUpdater = exports.set3dBuildingColorUpdater = exports.resetMapConfigMapStyleUpdater = exports.requestMapStylesUpdater = exports.removeCustomMapStyleUpdater = exports.receiveMapConfigUpdater = exports.mapStyleChangeUpdater = exports.mapConfigChangeUpdater = exports.loadMapStylesUpdater = exports.loadMapStyleErrUpdater = exports.loadCustomMapStyleUpdater = exports.inputMapStyleUpdater = exports.initMapStyleUpdater = void 0;
12
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _tasks = _interopRequireWildcard(require("@kepler.gl/tasks"));
15
+ var _cloneDeep = _interopRequireDefault(require("es-toolkit/compat/cloneDeep"));
16
+ var _console = _interopRequireDefault(require("global/console"));
17
+ var _utils = require("@kepler.gl/utils");
18
+ var _commonUtils = require("@kepler.gl/common-utils");
19
+ var _constants = require("@kepler.gl/constants");
20
+ var _d3Color = require("d3-color");
21
+ var _actions = require("@kepler.gl/actions");
22
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
23
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
24
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
25
+ 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; }
26
+ 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
27
+ // Copyright contributors to the kepler.gl project
28
+ // Utils
29
+ var getDefaultMapStyles = exports.getDefaultMapStyles = function getDefaultMapStyles(cdnUrl) {
30
+ return _constants.DEFAULT_MAP_STYLES.reduce(function (accu, curr) {
31
+ return _objectSpread(_objectSpread({}, accu), {}, (0, _defineProperty2["default"])({}, curr.id, _objectSpread(_objectSpread({}, curr), {}, {
32
+ icon: "".concat(cdnUrl, "/").concat(curr.icon)
33
+ })));
34
+ }, {});
35
+ };
36
+ var getDefaultState = function getDefaultState() {
37
+ var visibleLayerGroups = {};
38
+ var topLayerGroups = {};
39
+ return {
40
+ styleType: _constants.DEFAULT_BASE_MAP_STYLE,
41
+ visibleLayerGroups: visibleLayerGroups,
42
+ topLayerGroups: topLayerGroups,
43
+ mapStyles: getDefaultMapStyles((0, _utils.getApplicationConfig)().cdnUrl),
44
+ // save mapbox access token
45
+ mapboxApiAccessToken: null,
46
+ mapboxApiUrl: _constants.DEFAULT_MAPBOX_API_URL,
47
+ mapStylesReplaceDefault: false,
48
+ inputStyle: getInitialInputStyle(),
49
+ threeDBuildingColor: (0, _utils.hexToRgb)(_constants.DEFAULT_BLDG_COLOR),
50
+ custom3DBuildingColor: false,
51
+ backgroundColor: (0, _utils.hexToRgb)(_constants.DEFAULT_BACKGROUND_COLOR),
52
+ isLoading: {},
53
+ bottomMapStyle: undefined,
54
+ topMapStyle: undefined
55
+ };
56
+ };
57
+
58
+ /**
59
+ * Updaters for `mapStyle`. Can be used in your root reducer to directly modify kepler.gl's state.
60
+ * Read more about [Using updaters](../advanced-usage/using-updaters.md)
61
+ * @public
62
+ * @example
63
+ *
64
+ * import keplerGlReducer, {mapStyleUpdaters} from '@kepler.gl/reducers';
65
+ * // Root Reducer
66
+ * const reducers = combineReducers({
67
+ * keplerGl: keplerGlReducer,
68
+ * app: appReducer
69
+ * });
70
+ *
71
+ * const composedReducer = (state, action) => {
72
+ * switch (action.type) {
73
+ * // click button to hide label from background map
74
+ * case 'CLICK_BUTTON':
75
+ * return {
76
+ * ...state,
77
+ * keplerGl: {
78
+ * ...state.keplerGl,
79
+ * foo: {
80
+ * ...state.keplerGl.foo,
81
+ * mapStyle: mapStyleUpdaters.mapConfigChangeUpdater(
82
+ * mapStyle,
83
+ * {payload: {visibleLayerGroups: {label: false, road: true, background: true}}}
84
+ * )
85
+ * }
86
+ * }
87
+ * };
88
+ * }
89
+ * return reducers(state, action);
90
+ * };
91
+ *
92
+ * export default composedReducer;
93
+ */
94
+
95
+ /* eslint-disable @typescript-eslint/no-unused-vars */
96
+ // @ts-ignore
97
+ var mapStyleUpdaters = null;
98
+ /* eslint-enable @typescript-eslint/no-unused-vars */
99
+ /**
100
+ * Default initial `mapStyle`
101
+ * @memberof mapStyleUpdaters
102
+ * @constant
103
+ * @property styleType - Default: `'dark'`
104
+ * @property visibleLayerGroups - Default: `{}`
105
+ * @property topLayerGroups - Default: `{}`
106
+ * @property mapStyles - mapping from style key to style object
107
+ * @property mapboxApiAccessToken - Default: `null`
108
+ * @Property mapboxApiUrl - Default null
109
+ * @Property mapStylesReplaceDefault - Default: `false`
110
+ * @property inputStyle - Default: `{}`
111
+ * @property threeDBuildingColor - Default: `[r, g, b]`
112
+ * @property backgroundColor - Default: `[r, g, b]`
113
+ * @public
114
+ */
115
+ var INITIAL_MAP_STYLE = exports.INITIAL_MAP_STYLE = getDefaultState();
116
+ /**
117
+ * Create two map styles from preset map style, one for top map one for bottom
118
+ *
119
+ * @param {string} styleType - current map style
120
+ * @param {Object} visibleLayerGroups - visible layers of bottom map
121
+ * @param {Object} topLayerGroups - visible layers of top map
122
+ * @param {Object} mapStyles - a dictionary of all map styles
123
+ * @returns {Object} bottomMapStyle | topMapStyle | isRaster
124
+ */
125
+ function getMapStyles(_ref) {
126
+ var styleType = _ref.styleType,
127
+ visibleLayerGroups = _ref.visibleLayerGroups,
128
+ topLayerGroups = _ref.topLayerGroups,
129
+ mapStyles = _ref.mapStyles;
130
+ var mapStyle = mapStyles[styleType];
131
+
132
+ // style might not be loaded yet
133
+ if (!mapStyle || !mapStyle.style) {
134
+ return {};
135
+ }
136
+ var editable = Object.keys(visibleLayerGroups).length;
137
+ var bottomMapStyle = !editable ? mapStyle.style : (0, _utils.editBottomMapStyle)({
138
+ id: styleType,
139
+ mapStyle: mapStyle,
140
+ visibleLayerGroups: visibleLayerGroups
141
+ });
142
+ var hasTopLayer = editable > 0 && Object.values(topLayerGroups).some(function (v) {
143
+ return v;
144
+ });
145
+
146
+ // mute top layer if not visible in bottom layer
147
+ var topLayers = hasTopLayer && Object.keys(topLayerGroups).reduce(function (accu, key) {
148
+ return _objectSpread(_objectSpread({}, accu), {}, (0, _defineProperty2["default"])({}, key, topLayerGroups[key] && visibleLayerGroups[key]));
149
+ }, {});
150
+ var topMapStyle = hasTopLayer ? (0, _utils.editTopMapStyle)({
151
+ id: styleType,
152
+ mapStyle: mapStyle,
153
+ visibleLayerGroups: topLayers
154
+ }) : null;
155
+ return {
156
+ bottomMapStyle: bottomMapStyle,
157
+ topMapStyle: topMapStyle,
158
+ editable: editable
159
+ };
160
+ }
161
+ function findLayerFillColor(layer) {
162
+ return layer && layer.paint && layer.paint['background-color'];
163
+ }
164
+
165
+ // need to be careful because some basemap layer.paint['background-color'] values may be an interpolate array expression instead of a color string
166
+ // https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#paint-background-background-color
167
+ // https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#interpolate
168
+ function getPaintColor(color) {
169
+ if (Array.isArray(color) && color[0] === 'interpolate') {
170
+ // get color of first zoom break
171
+ // ["interpolate", ["linear"], ["zoom"], 11, "hsl(35, 32%, 91%)", 13, "hsl(35, 12%, 89%)"]
172
+ return color[4];
173
+ }
174
+ return color;
175
+ }
176
+ function get3DBuildingColor(style) {
177
+ // set building color to be the same as the background color.
178
+ if (!style.style) {
179
+ return (0, _utils.hexToRgb)(_constants.DEFAULT_BLDG_COLOR);
180
+ }
181
+ var backgroundLayer = (style.style.layers || []).find(function (_ref2) {
182
+ var id = _ref2.id;
183
+ return id === 'background';
184
+ });
185
+ var buildingLayer = (style.style.layers || []).find(function (_ref3) {
186
+ var id = _ref3.id;
187
+ return id.match(/building/);
188
+ });
189
+ var buildingColor = findLayerFillColor(buildingLayer) || findLayerFillColor(backgroundLayer) || _constants.DEFAULT_BLDG_COLOR;
190
+
191
+ // brighten or darken building based on style
192
+ var operation = style.id.match(/(?=(dark|night))/) ? 'brighter' : 'darker';
193
+ var alpha = 0.2;
194
+ var rgbObj = (0, _d3Color.rgb)(buildingColor)[operation]([alpha]);
195
+ return [rgbObj.r, rgbObj.g, rgbObj.b];
196
+ }
197
+ function getBackgroundColorFromStyleBaseLayer(style, backupBackgroundColor) {
198
+ var _colorMaybeToRGB;
199
+ if (!style.style) {
200
+ return (0, _utils.colorMaybeToRGB)(backupBackgroundColor) || backupBackgroundColor;
201
+ }
202
+
203
+ // @ts-expect-error style.style not typed
204
+ var baseLayer = (style.style.layers || []).find(function (_ref4) {
205
+ var id = _ref4.id;
206
+ return _constants.BASE_MAP_BACKGROUND_LAYER_IDS.includes(id);
207
+ });
208
+ var backgroundColorOfBaseLayer = getPaintColor(findLayerFillColor(baseLayer));
209
+ var newBackgroundColor = typeof backgroundColorOfBaseLayer === 'string' ? backgroundColorOfBaseLayer : backupBackgroundColor;
210
+ var newBackgroundColorAsRGBArray = (_colorMaybeToRGB = (0, _utils.colorMaybeToRGB)(newBackgroundColor)
211
+ // if newBackgroundColor was in string HSL format it can introduce RGB numbers with decimals,
212
+ // which may render the background-color CSS of the <StyledMap> container incorrectly when using our own color utils `rgbToHex()`
213
+ // so we attempt to round to nearest integer here
214
+ ) === null || _colorMaybeToRGB === void 0 ? void 0 : _colorMaybeToRGB.map(function (channelNumber) {
215
+ return Math.round(channelNumber);
216
+ });
217
+ return newBackgroundColorAsRGBArray || backupBackgroundColor;
218
+ }
219
+
220
+ // determine new backgroundColor from either previous state basemap style, previous state backgroundColor, or the DEFAULT_BACKGROUND_COLOR
221
+ function getBackgroundColor(previousState, styleType) {
222
+ var previousStateMapStyle = previousState.mapStyles[previousState.styleType];
223
+ var backupBackgroundColor = previousState.backgroundColor || _constants.DEFAULT_BACKGROUND_COLOR;
224
+ var backgroundColor = styleType === _constants.NO_MAP_ID ?
225
+ // if the style has switched to the "no basemap" style,
226
+ // attempt to detect backgroundColor of the previous basemap if it was a mapbox basemap
227
+ // and set it as the "no basemap" backgroundColor
228
+ getBackgroundColorFromStyleBaseLayer(previousStateMapStyle, backupBackgroundColor) :
229
+ // otherwise leave it alone and rely on the previous state's preexisting backgroundColor
230
+ // or DEFAULT_BACKGROUND_COLOR as a last resort
231
+ backupBackgroundColor;
232
+ return backgroundColor;
233
+ }
234
+ function getLayerGroupsFromStyle(style) {
235
+ return Array.isArray(style === null || style === void 0 ? void 0 : style.layers) ? _constants.DEFAULT_LAYER_GROUPS.filter(function (lg) {
236
+ return style.layers.filter(lg.filter).length;
237
+ }) : [];
238
+ }
239
+
240
+ // Updaters
241
+
242
+ /**
243
+ * @memberof mapStyleUpdaters
244
+ * @public
245
+ */
246
+ var requestMapStylesUpdater = exports.requestMapStylesUpdater = function requestMapStylesUpdater(state, _ref5) {
247
+ var _ref5$payload = _ref5.payload,
248
+ mapStyles = _ref5$payload.mapStyles,
249
+ onSuccess = _ref5$payload.onSuccess;
250
+ var toLoad = Object.keys(mapStyles).reduce(function (accu, id) {
251
+ return _objectSpread(_objectSpread({}, accu), !state.isLoading[id] ? (0, _defineProperty2["default"])({}, id, mapStyles[id]) : {});
252
+ }, {});
253
+ var loadMapStyleTasks = getLoadMapStyleTasks(toLoad, state.mapboxApiAccessToken, state.mapboxApiUrl, onSuccess);
254
+ var isLoading = Object.keys(toLoad).reduce(function (accu, key) {
255
+ return _objectSpread(_objectSpread({}, accu), {}, (0, _defineProperty2["default"])({}, key, true));
256
+ }, {});
257
+ var nextState = _objectSpread(_objectSpread({}, state), {}, {
258
+ isLoading: isLoading
259
+ });
260
+ return (0, _tasks.withTask)(nextState, loadMapStyleTasks);
261
+ };
262
+
263
+ /**
264
+ * Propagate `mapStyle` reducer with `mapboxApiAccessToken` and `mapStylesReplaceDefault`.
265
+ * if mapStylesReplaceDefault is true mapStyles is emptied; loadMapStylesUpdater() will
266
+ * populate mapStyles.
267
+ *
268
+ * @memberof mapStyleUpdaters
269
+ * @public
270
+ */
271
+ var initMapStyleUpdater = exports.initMapStyleUpdater = function initMapStyleUpdater(state, _ref7) {
272
+ var _ref7$payload = _ref7.payload,
273
+ payload = _ref7$payload === void 0 ? {} : _ref7$payload;
274
+ return _objectSpread(_objectSpread({}, state), {}, {
275
+ // save mapbox access token to map style state
276
+ mapboxApiAccessToken: payload.mapboxApiAccessToken || state.mapboxApiAccessToken,
277
+ mapboxApiUrl: payload.mapboxApiUrl || state.mapboxApiUrl,
278
+ mapStyles: !payload.mapStylesReplaceDefault ? state.mapStyles : {},
279
+ mapStylesReplaceDefault: payload.mapStylesReplaceDefault || false
280
+ });
281
+ };
282
+ // });
283
+
284
+ /**
285
+ * Update `visibleLayerGroups`to change layer group visibility
286
+ * @memberof mapStyleUpdaters
287
+ * @public
288
+ */
289
+ var mapConfigChangeUpdater = exports.mapConfigChangeUpdater = function mapConfigChangeUpdater(state, action) {
290
+ return _objectSpread(_objectSpread(_objectSpread({}, state), action.payload), getMapStyles(_objectSpread(_objectSpread({}, state), action.payload)));
291
+ };
292
+ var hasStyleObject = function hasStyleObject(style) {
293
+ return (0, _utils.isPlainObject)(style === null || style === void 0 ? void 0 : style.style);
294
+ };
295
+
296
+ /**
297
+ * Change to another map style. The selected style should already been loaded into `mapStyle.mapStyles`
298
+ * @memberof mapStyleUpdaters
299
+ * @public
300
+ */
301
+ var mapStyleChangeUpdater = exports.mapStyleChangeUpdater = function mapStyleChangeUpdater(state, _ref8) {
302
+ var _state$mapStyles$styl, _state$mapStyles$styl2;
303
+ var _ref8$payload = _ref8.payload,
304
+ styleType = _ref8$payload.styleType,
305
+ onSuccess = _ref8$payload.onSuccess;
306
+ if (
307
+ // we might not have received the style yet
308
+ !state.mapStyles[styleType] ||
309
+ // or if it is a managed custom style asset
310
+ // and if it has not been hydrated with URL info yet (during app first initialization)
311
+ // and it does not have a style object (during adding a custom style)
312
+ ((_state$mapStyles$styl = state.mapStyles[styleType]) === null || _state$mapStyles$styl === void 0 ? void 0 : _state$mapStyles$styl.custom) === 'MANAGED' && !((_state$mapStyles$styl2 = state.mapStyles[styleType]) !== null && _state$mapStyles$styl2 !== void 0 && _state$mapStyles$styl2.url) && !hasStyleObject(state.mapStyles[styleType])) {
313
+ return state;
314
+ }
315
+ if (!hasStyleObject(state.mapStyles[styleType])) {
316
+ // style hasn't loaded yet
317
+ return requestMapStylesUpdater(_objectSpread(_objectSpread({}, state), {}, {
318
+ styleType: styleType
319
+ }), {
320
+ payload: {
321
+ mapStyles: (0, _defineProperty2["default"])({}, styleType, state.mapStyles[styleType]),
322
+ onSuccess: onSuccess
323
+ }
324
+ });
325
+ }
326
+ var defaultLGVisibility = (0, _utils.getDefaultLayerGroupVisibility)(state.mapStyles[styleType]);
327
+ var visibleLayerGroups = (0, _utils.mergeLayerGroupVisibility)(defaultLGVisibility, state.visibleLayerGroups);
328
+ var threeDBuildingColor = state.custom3DBuildingColor ? state.threeDBuildingColor : get3DBuildingColor(state.mapStyles[styleType]);
329
+
330
+ // determine new backgroundColor from either previous state basemap style, previous state backgroundColor, or the DEFAULT_BACKGROUND_COLOR
331
+ var backgroundColor = getBackgroundColor(state, styleType);
332
+ return _objectSpread(_objectSpread({}, state), {}, {
333
+ styleType: styleType,
334
+ visibleLayerGroups: visibleLayerGroups,
335
+ threeDBuildingColor: threeDBuildingColor,
336
+ backgroundColor: backgroundColor
337
+ }, getMapStyles(_objectSpread(_objectSpread({}, state), {}, {
338
+ visibleLayerGroups: visibleLayerGroups,
339
+ styleType: styleType
340
+ })));
341
+ };
342
+
343
+ /**
344
+ * Callback when load map style success
345
+ * @memberof mapStyleUpdaters
346
+ * @public
347
+ */
348
+ var loadMapStylesUpdater = exports.loadMapStylesUpdater = function loadMapStylesUpdater(state, action) {
349
+ var _ref9 = action.payload || {},
350
+ newStyles = _ref9.newStyles,
351
+ onSuccess = _ref9.onSuccess;
352
+ var addLayerGroups = Object.keys(newStyles).reduce(function (accu, id) {
353
+ return _objectSpread(_objectSpread({}, accu), {}, (0, _defineProperty2["default"])({}, id, _objectSpread(_objectSpread({}, newStyles[id]), {}, {
354
+ layerGroups: newStyles[id].layerGroups || getLayerGroupsFromStyle(newStyles[id].style)
355
+ })));
356
+ }, {});
357
+ // reset isLoading
358
+ var isLoading = Object.keys(state.isLoading).reduce(function (accu, key) {
359
+ return _objectSpread(_objectSpread({}, accu), state.isLoading[key] && hasStyleObject(newStyles[key]) ? (0, _defineProperty2["default"])({}, key, false) : (0, _defineProperty2["default"])({}, key, state.isLoading[key]));
360
+ }, {});
361
+ // add new styles to state
362
+ var newState = _objectSpread(_objectSpread({}, state), {}, {
363
+ isLoading: isLoading,
364
+ mapStyles: _objectSpread(_objectSpread({}, state.mapStyles), addLayerGroups)
365
+ });
366
+ var tasks = createActionTask(onSuccess, {
367
+ styleType: state.styleType
368
+ });
369
+ var nextState = newStyles[state.styleType] ? mapStyleChangeUpdater(newState, {
370
+ payload: {
371
+ styleType: state.styleType
372
+ }
373
+ }) : newState;
374
+ return tasks ? (0, _tasks.withTask)(nextState, tasks) : nextState;
375
+ };
376
+ function createActionTask(action, payload) {
377
+ if (typeof action === 'function') {
378
+ return (0, _tasks.ACTION_TASK)().map(function () {
379
+ return action(payload);
380
+ });
381
+ }
382
+ return null;
383
+ }
384
+
385
+ /**
386
+ * Callback when load map style error
387
+ * @memberof mapStyleUpdaters
388
+ * @public
389
+ */
390
+ // do nothing for now, if didn't load, skip it
391
+ var loadMapStyleErrUpdater = exports.loadMapStyleErrUpdater = function loadMapStyleErrUpdater(state, _ref10) {
392
+ var _ref10$payload = _ref10.payload,
393
+ ids = _ref10$payload.ids,
394
+ error = _ref10$payload.error;
395
+ _console["default"].error(error);
396
+ // reset isLoading
397
+ var isLoading = Object.keys(state.isLoading).reduce(function (accu, key) {
398
+ return _objectSpread(_objectSpread({}, accu), state.isLoading[key] && (ids || []).includes(key) ? (0, _defineProperty2["default"])({}, key, false) : (0, _defineProperty2["default"])({}, key, state.isLoading[key]));
399
+ }, {});
400
+ return _objectSpread(_objectSpread({}, state), {}, {
401
+ isLoading: isLoading
402
+ });
403
+ };
404
+
405
+ /**
406
+ * Load map style object when pass in saved map config
407
+ * @memberof mapStyleUpdaters
408
+ * @param state `mapStyle`
409
+ * @param action
410
+ * @param action.payload saved map config `{mapStyle, visState, mapState}`
411
+ * @returns nextState or `react-pam` tasks to load map style object
412
+ */
413
+ var receiveMapConfigUpdater = exports.receiveMapConfigUpdater = function receiveMapConfigUpdater(state, _ref13) {
414
+ var config = _ref13.payload.config;
415
+ var _ref14 = config || {},
416
+ mapStyle = _ref14.mapStyle;
417
+ if (!mapStyle) {
418
+ return state;
419
+ }
420
+
421
+ // merge default mapStyles
422
+ var merged = mapStyle.mapStyles ? _objectSpread(_objectSpread({}, mapStyle), {}, {
423
+ mapStyles: _objectSpread(_objectSpread({}, mapStyle.mapStyles), state.mapStyles)
424
+ }) : mapStyle;
425
+
426
+ // set custom3DBuildingColor: true if mapStyle contains threeDBuildingColor
427
+ // @ts-expect-error
428
+ merged.custom3DBuildingColor =
429
+ // @ts-expect-error
430
+ Boolean(mapStyle.threeDBuildingColor) || merged.custom3DBuildingColor;
431
+ var newState = mapConfigChangeUpdater(state, {
432
+ payload: merged
433
+ });
434
+ return mapStyleChangeUpdater(newState, {
435
+ payload: {
436
+ styleType: newState.styleType
437
+ }
438
+ });
439
+ };
440
+ function getLoadMapStyleTasks(mapStyles, mapboxApiAccessToken, mapboxApiUrl, onSuccess) {
441
+ return [_tasks["default"].all(Object.values(mapStyles)
442
+ // @ts-expect-error
443
+ .map(function (_ref15) {
444
+ var id = _ref15.id,
445
+ url = _ref15.url,
446
+ accessToken = _ref15.accessToken;
447
+ return {
448
+ id: id,
449
+ url: (0, _utils.getStyleDownloadUrl)(url, accessToken || mapboxApiAccessToken, mapboxApiUrl)
450
+ };
451
+ }).map(_tasks.LOAD_MAP_STYLE_TASK)).bimap(
452
+ // success
453
+ function (results) {
454
+ return (0, _actions.loadMapStyles)(results.reduce(function (accu, _ref16) {
455
+ var id = _ref16.id,
456
+ style = _ref16.style;
457
+ return _objectSpread(_objectSpread({}, accu), {}, (0, _defineProperty2["default"])({}, id, _objectSpread(_objectSpread({}, mapStyles[id]), {}, {
458
+ style: style
459
+ })));
460
+ }, {}), onSuccess);
461
+ },
462
+ // error
463
+ function (err) {
464
+ return (0, _actions.loadMapStyleErr)(Object.keys(mapStyles), err);
465
+ })];
466
+ }
467
+ /**
468
+ * Reset map style config to initial state
469
+ * @memberof mapStyleUpdaters
470
+ * @param state `mapStyle`
471
+ * @returns nextState
472
+ * @public
473
+ */
474
+ var resetMapConfigMapStyleUpdater = exports.resetMapConfigMapStyleUpdater = function resetMapConfigMapStyleUpdater(state) {
475
+ var emptyConfig = _objectSpread(_objectSpread(_objectSpread({}, INITIAL_MAP_STYLE), {}, {
476
+ mapboxApiAccessToken: state.mapboxApiAccessToken,
477
+ mapboxApiUrl: state.mapboxApiUrl,
478
+ mapStylesReplaceDefault: state.mapStylesReplaceDefault
479
+ }, state.initialState), {}, {
480
+ mapStyles: state.mapStyles,
481
+ initialState: state.initialState
482
+ });
483
+ return mapStyleChangeUpdater(emptyConfig, {
484
+ payload: {
485
+ styleType: emptyConfig.styleType
486
+ }
487
+ });
488
+ };
489
+
490
+ /**
491
+ * Callback when a custom map style object is received
492
+ * @memberof mapStyleUpdaters
493
+ * @public
494
+ */
495
+ var loadCustomMapStyleUpdater = exports.loadCustomMapStyleUpdater = function loadCustomMapStyleUpdater(state, _ref17) {
496
+ var _ref17$payload = _ref17.payload,
497
+ icon = _ref17$payload.icon,
498
+ style = _ref17$payload.style,
499
+ error = _ref17$payload.error;
500
+ return _objectSpread(_objectSpread({}, state), {}, {
501
+ // @ts-expect-error
502
+ inputStyle: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, state.inputStyle), style ? {
503
+ id: state.inputStyle.custom === 'MANAGED' ? state.inputStyle.id // custom MANAGED type
504
+ :
505
+ // @ts-expect-error
506
+ style.id || (0, _commonUtils.generateHashId)(),
507
+ // custom LOCAL type
508
+ // make a copy of the style object
509
+ style: (0, _cloneDeep["default"])(style),
510
+ // @ts-expect-error
511
+ label: state.inputStyle.label || style.name,
512
+ // gathering layer group info from style json
513
+ layerGroups: getLayerGroupsFromStyle(style)
514
+ } : {}), icon ? {
515
+ icon: icon
516
+ } : {}), error !== undefined ? {
517
+ error: error
518
+ } : {})
519
+ });
520
+ };
521
+
522
+ /**
523
+ * Input a custom map style object
524
+ * @memberof mapStyleUpdaters
525
+ * @public
526
+ */
527
+ var inputMapStyleUpdater = exports.inputMapStyleUpdater = function inputMapStyleUpdater(state, _ref18) {
528
+ var _updated$icon, _updated$url, _updated$url2;
529
+ var _ref18$payload = _ref18.payload,
530
+ inputStyle = _ref18$payload.inputStyle,
531
+ mapState = _ref18$payload.mapState;
532
+ var updated = _objectSpread(_objectSpread({}, state.inputStyle), inputStyle);
533
+
534
+ // differentiate between either a url to hosted style json that needs an icon url,
535
+ // or an icon already available client-side as a data uri
536
+ var isUpdatedIconDataUri = (_updated$icon = updated.icon) === null || _updated$icon === void 0 ? void 0 : _updated$icon.startsWith('data:image');
537
+ var isMapboxStyleUrl = ((_updated$url = updated.url) === null || _updated$url === void 0 ? void 0 : _updated$url.startsWith('mapbox://')) || ((_updated$url2 = updated.url) === null || _updated$url2 === void 0 ? void 0 : _updated$url2.includes('mapbox.com'));
538
+ var icon = !isUpdatedIconDataUri && isMapboxStyleUrl ?
539
+ // Get image icon urls only for mapbox map lib.
540
+ (0, _utils.getStyleImageIcon)({
541
+ mapState: mapState,
542
+ styleUrl: updated.url || '',
543
+ mapboxApiAccessToken: updated.accessToken || state.mapboxApiAccessToken || '',
544
+ mapboxApiUrl: state.mapboxApiUrl || _constants.DEFAULT_MAPBOX_API_URL
545
+ }) : updated.icon;
546
+ return _objectSpread(_objectSpread({}, state), {}, {
547
+ inputStyle: _objectSpread(_objectSpread({}, updated), {}, {
548
+ isValid: true,
549
+ icon: icon
550
+ })
551
+ });
552
+ };
553
+
554
+ /**
555
+ * Add map style from user input to reducer and set it to current style
556
+ * This action is called when user click confirm after putting in a valid style url in the custom map style dialog.
557
+ * It should not be called from outside kepler.gl without a valid `inputStyle` in the `mapStyle` reducer.
558
+ * @memberof mapStyleUpdaters
559
+ */
560
+ var addCustomMapStyleUpdater = exports.addCustomMapStyleUpdater = function addCustomMapStyleUpdater(state) {
561
+ var styleId = state.inputStyle.id;
562
+ if (!styleId) return state;
563
+ var newState = getNewStateWithCustomMapStyle(state);
564
+ // set new style
565
+ return mapStyleChangeUpdater(newState, {
566
+ payload: {
567
+ styleType: styleId
568
+ }
569
+ });
570
+ };
571
+
572
+ /**
573
+ * Edit map style from user input to reducer.
574
+ * This action is called when user clicks confirm after editing an existing custom style in the custom map style dialog.
575
+ * It should not be called from outside kepler.gl without a valid `inputStyle` in the `mapStyle` reducer.
576
+ * @memberof mapStyleUpdaters
577
+ */
578
+ var editCustomMapStyleUpdater = exports.editCustomMapStyleUpdater = function editCustomMapStyleUpdater(state) {
579
+ return getNewStateWithCustomMapStyle(state);
580
+ };
581
+ function getNewStateWithCustomMapStyle(state) {
582
+ var styleId = state.inputStyle.id;
583
+ if (!styleId) return state;
584
+ return _objectSpread(_objectSpread({}, state), {}, {
585
+ // @ts-expect-error Property 'layerGroups' is missing in type 'InputStyle' but required in type 'BaseMapStyle'. Legacy case?
586
+ mapStyles: _objectSpread(_objectSpread({}, state.mapStyles), {}, (0, _defineProperty2["default"])({}, styleId, _objectSpread(_objectSpread({}, state.mapStyles[styleId]), state.inputStyle))),
587
+ // set to default
588
+ inputStyle: getInitialInputStyle()
589
+ });
590
+ }
591
+
592
+ /**
593
+ * Remove a custom map style from `state.mapStyle.mapStyles`.
594
+ * @memberof mapStyleUpdaters
595
+ */
596
+ var removeCustomMapStyleUpdater = exports.removeCustomMapStyleUpdater = function removeCustomMapStyleUpdater(state, action) {
597
+ var id = action.payload.id;
598
+
599
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
600
+ var _state$mapStyles = state.mapStyles,
601
+ _ = _state$mapStyles[id],
602
+ restOfMapStyles = (0, _objectWithoutProperties2["default"])(_state$mapStyles, [id].map(_toPropertyKey));
603
+ var newState = _objectSpread(_objectSpread({}, state), {}, {
604
+ mapStyles: restOfMapStyles
605
+ });
606
+ if (state.styleType === id) {
607
+ // if removing a custom style that is also the current active base map,
608
+ // then reset to the default active base map (`mapStyle.styleType`)
609
+ return mapStyleChangeUpdater(newState, {
610
+ payload: {
611
+ styleType: getDefaultState().styleType
612
+ }
613
+ });
614
+ }
615
+ return newState;
616
+ };
617
+
618
+ /**
619
+ * Updates 3d building color
620
+ * @memberof mapStyleUpdaters
621
+ */
622
+ var set3dBuildingColorUpdater = exports.set3dBuildingColorUpdater = function set3dBuildingColorUpdater(state, _ref19) {
623
+ var color = _ref19.payload;
624
+ return _objectSpread(_objectSpread({}, state), {}, {
625
+ threeDBuildingColor: color,
626
+ custom3DBuildingColor: true
627
+ });
628
+ };
629
+
630
+ /**
631
+ * Updates background color
632
+ * @memberof mapStyleUpdaters
633
+ */
634
+ var setBackgroundColorUpdater = exports.setBackgroundColorUpdater = function setBackgroundColorUpdater(state, _ref20) {
635
+ var color = _ref20.payload;
636
+ return _objectSpread(_objectSpread({}, state), {}, {
637
+ backgroundColor: color
638
+ });
639
+ };
640
+
641
+ /**
642
+ * Return the initial input style
643
+ * @return Object
644
+ */
645
+ function getInitialInputStyle() {
646
+ return {
647
+ id: null,
648
+ accessToken: null,
649
+ error: false,
650
+ isValid: false,
651
+ label: null,
652
+ style: null,
653
+ url: null,
654
+ icon: null,
655
+ custom: 'LOCAL',
656
+ uploadedFile: null
657
+ };
658
+ }
659
+ //# sourceMappingURL=map-style-updaters.js.map