@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.
- package/dist/cjs/column-edit-reconcile.js +100 -0
- package/dist/cjs/column-edit-reconcile.js.map +1 -0
- package/dist/cjs/combined-updaters.js +676 -0
- package/dist/cjs/combined-updaters.js.map +1 -0
- package/dist/cjs/composer-helpers.js +101 -0
- package/dist/cjs/composer-helpers.js.map +1 -0
- package/dist/cjs/composers.js +21 -0
- package/dist/cjs/composers.js.map +1 -0
- package/dist/cjs/core.js +105 -0
- package/dist/cjs/core.js.map +1 -0
- package/dist/cjs/data-utils.js +53 -0
- package/dist/cjs/data-utils.js.map +1 -0
- package/dist/cjs/dataset-ops-updaters.js +375 -0
- package/dist/cjs/dataset-ops-updaters.js.map +1 -0
- package/dist/cjs/export-utils.js +163 -0
- package/dist/cjs/export-utils.js.map +1 -0
- package/dist/cjs/index.js +348 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interaction-utils.js +275 -0
- package/dist/cjs/interaction-utils.js.map +1 -0
- package/dist/cjs/layer-utils.js +797 -0
- package/dist/cjs/layer-utils.js.map +1 -0
- package/dist/cjs/map-state-updaters.js +709 -0
- package/dist/cjs/map-state-updaters.js.map +1 -0
- package/dist/cjs/map-state.js +35 -0
- package/dist/cjs/map-state.js.map +1 -0
- package/dist/cjs/map-style-updaters.js +659 -0
- package/dist/cjs/map-style-updaters.js.map +1 -0
- package/dist/cjs/map-style.js +33 -0
- package/dist/cjs/map-style.js.map +1 -0
- package/dist/cjs/merger-handler.js +105 -0
- package/dist/cjs/merger-handler.js.map +1 -0
- package/dist/cjs/middleware.js +25 -0
- package/dist/cjs/middleware.js.map +1 -0
- package/dist/cjs/provider-state-updaters.js +464 -0
- package/dist/cjs/provider-state-updaters.js.map +1 -0
- package/dist/cjs/provider-state.js +34 -0
- package/dist/cjs/provider-state.js.map +1 -0
- package/dist/cjs/root.js +207 -0
- package/dist/cjs/root.js.map +1 -0
- package/dist/cjs/ui-state-updaters.js +1096 -0
- package/dist/cjs/ui-state-updaters.js.map +1 -0
- package/dist/cjs/ui-state.js +36 -0
- package/dist/cjs/ui-state.js.map +1 -0
- package/dist/cjs/vis-state-merger.js +1439 -0
- package/dist/cjs/vis-state-merger.js.map +1 -0
- package/dist/cjs/vis-state-selectors.js +50 -0
- package/dist/cjs/vis-state-selectors.js.map +1 -0
- package/dist/cjs/vis-state-updaters.js +6749 -0
- package/dist/cjs/vis-state-updaters.js.map +1 -0
- package/dist/cjs/vis-state.js +35 -0
- package/dist/cjs/vis-state.js.map +1 -0
- package/dist/column-edit-reconcile.d.ts +4 -0
- package/dist/combined-updaters.d.ts +61 -15
- package/dist/composers.d.ts +17 -2
- package/dist/dataset-ops-updaters.d.ts +21 -0
- package/dist/esm/column-edit-reconcile.js +95 -0
- package/dist/esm/column-edit-reconcile.js.map +1 -0
- package/dist/esm/combined-updaters.js +669 -0
- package/dist/esm/combined-updaters.js.map +1 -0
- package/dist/esm/composer-helpers.js +85 -0
- package/dist/esm/composer-helpers.js.map +1 -0
- package/dist/esm/composers.js +15 -0
- package/dist/esm/composers.js.map +1 -0
- package/dist/esm/core.js +101 -0
- package/dist/esm/core.js.map +1 -0
- package/dist/esm/data-utils.js +47 -0
- package/dist/esm/data-utils.js.map +1 -0
- package/dist/esm/dataset-ops-updaters.js +357 -0
- package/dist/esm/dataset-ops-updaters.js.map +1 -0
- package/dist/esm/export-utils.js +158 -0
- package/dist/esm/export-utils.js.map +1 -0
- package/dist/esm/index.js +62 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interaction-utils.js +262 -0
- package/dist/esm/interaction-utils.js.map +1 -0
- package/dist/esm/layer-utils.js +762 -0
- package/dist/esm/layer-utils.js.map +1 -0
- package/dist/esm/map-state-updaters.js +701 -0
- package/dist/esm/map-state-updaters.js.map +1 -0
- package/dist/esm/map-state.js +29 -0
- package/dist/esm/map-state.js.map +1 -0
- package/dist/esm/map-style-updaters.js +652 -0
- package/dist/esm/map-style-updaters.js.map +1 -0
- package/dist/esm/map-style.js +27 -0
- package/dist/esm/map-style.js.map +1 -0
- package/dist/esm/merger-handler.js +96 -0
- package/dist/esm/merger-handler.js.map +1 -0
- package/dist/esm/middleware.js +17 -0
- package/dist/esm/middleware.js.map +1 -0
- package/dist/esm/provider-state-updaters.js +458 -0
- package/dist/esm/provider-state-updaters.js.map +1 -0
- package/dist/esm/provider-state.js +28 -0
- package/dist/esm/provider-state.js.map +1 -0
- package/dist/esm/root.js +201 -0
- package/dist/esm/root.js.map +1 -0
- package/dist/esm/ui-state-updaters.js +1091 -0
- package/dist/esm/ui-state-updaters.js.map +1 -0
- package/dist/esm/ui-state.js +30 -0
- package/dist/esm/ui-state.js.map +1 -0
- package/dist/esm/vis-state-merger.js +1403 -0
- package/dist/esm/vis-state-merger.js.map +1 -0
- package/dist/esm/vis-state-selectors.js +44 -0
- package/dist/esm/vis-state-selectors.js.map +1 -0
- package/dist/esm/vis-state-updaters.js +6586 -0
- package/dist/esm/vis-state-updaters.js.map +1 -0
- package/dist/esm/vis-state.js +29 -0
- package/dist/esm/vis-state.js.map +1 -0
- package/dist/export-utils.d.ts +2 -2
- package/dist/interaction-utils.d.ts +26 -3
- package/dist/layer-utils.d.ts +18 -0
- package/dist/map-state-updaters.d.ts +13 -0
- package/dist/map-style-updaters.d.ts +1 -3
- package/dist/middleware.d.ts +2 -2
- package/dist/root.d.ts +1 -1
- package/dist/ui-state-updaters.d.ts +62 -2
- package/dist/vis-state-merger.d.ts +23 -5
- package/dist/vis-state-selectors.d.ts +53 -6
- package/dist/vis-state-updaters.d.ts +196 -15
- package/dist/vis-state.d.ts +56 -0
- package/package.json +37 -32
- package/dist/combined-updaters.js +0 -412
- package/dist/composer-helpers.js +0 -101
- package/dist/composers.js +0 -23
- package/dist/core.js +0 -105
- package/dist/data-utils.js +0 -53
- package/dist/export-utils.js +0 -91
- package/dist/index.js +0 -349
- package/dist/interaction-utils.js +0 -105
- package/dist/layer-utils.js +0 -633
- package/dist/map-state-updaters.js +0 -516
- package/dist/map-state.js +0 -35
- package/dist/map-style-updaters.js +0 -661
- package/dist/map-style.js +0 -34
- package/dist/merger-handler.js +0 -105
- package/dist/middleware.js +0 -27
- package/dist/provider-state-updaters.js +0 -466
- package/dist/provider-state.js +0 -35
- package/dist/root.js +0 -207
- package/dist/ui-state-updaters.js +0 -890
- package/dist/ui-state.js +0 -37
- package/dist/vis-state-merger.js +0 -1193
- package/dist/vis-state-selectors.js +0 -30
- package/dist/vis-state-updaters.js +0 -4115
- package/dist/vis-state.js +0 -36
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
// SPDX-License-Identifier: MIT
|
|
6
|
+
// Copyright contributors to the kepler.gl project
|
|
7
|
+
|
|
8
|
+
import geoViewport from '@mapbox/geo-viewport';
|
|
9
|
+
import { booleanWithin } from '@turf/boolean-within';
|
|
10
|
+
import { bboxPolygon } from '@turf/bbox-polygon';
|
|
11
|
+
import { fitBounds } from '@math.gl/web-mercator';
|
|
12
|
+
import deepmerge from 'deepmerge';
|
|
13
|
+
import pick from 'es-toolkit/compat/pick';
|
|
14
|
+
import { getCenterAndZoomFromBounds, validateBounds, MAPBOX_TILE_SIZE, validateViewPort } from '@kepler.gl/utils';
|
|
15
|
+
import { MapSplitMode, MapViewMode, DEFAULT_GLOBE_CONFIG, GLOBE_MIN_ZOOM, GLOBE_MAX_ZOOM, GLOBE_MAX_LATITUDE } from '@kepler.gl/constants';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Updaters for `mapState` reducer. Can be used in your root reducer to directly modify kepler.gl's state.
|
|
19
|
+
* Read more about [Using updaters](../advanced-usage/using-updaters.md)
|
|
20
|
+
* @public
|
|
21
|
+
* @example
|
|
22
|
+
*
|
|
23
|
+
* import keplerGlReducer, {mapStateUpdaters} from '@kepler.gl/reducers';
|
|
24
|
+
* // Root Reducer
|
|
25
|
+
* const reducers = combineReducers({
|
|
26
|
+
* keplerGl: keplerGlReducer,
|
|
27
|
+
* app: appReducer
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const composedReducer = (state, action) => {
|
|
31
|
+
* switch (action.type) {
|
|
32
|
+
* // click button to close side panel
|
|
33
|
+
* case 'CLICK_BUTTON':
|
|
34
|
+
* return {
|
|
35
|
+
* ...state,
|
|
36
|
+
* keplerGl: {
|
|
37
|
+
* ...state.keplerGl,
|
|
38
|
+
* foo: {
|
|
39
|
+
* ...state.keplerGl.foo,
|
|
40
|
+
* mapState: mapStateUpdaters.fitBoundsUpdater(
|
|
41
|
+
* mapState, {payload: [127.34, 31.09, 127.56, 31.59]]}
|
|
42
|
+
* )
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* };
|
|
46
|
+
* }
|
|
47
|
+
* return reducers(state, action);
|
|
48
|
+
* };
|
|
49
|
+
*
|
|
50
|
+
* export default composedReducer;
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
var mapStateUpdaters = null;
|
|
56
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
57
|
+
/**
|
|
58
|
+
* Default initial `mapState`
|
|
59
|
+
* @memberof mapStateUpdaters
|
|
60
|
+
* @constant
|
|
61
|
+
* @property pitch Default: `0`
|
|
62
|
+
* @property bearing Default: `0`
|
|
63
|
+
* @property latitude Default: `37.75043`
|
|
64
|
+
* @property longitude Default: `-122.34679`
|
|
65
|
+
* @property zoom Default: `9`
|
|
66
|
+
* @property dragRotate Default: `false`
|
|
67
|
+
* @property width Default: `800`
|
|
68
|
+
* @property height Default: `800`
|
|
69
|
+
* @property minZoom: `undefined`,
|
|
70
|
+
* @property maxZoom: `undefined`,
|
|
71
|
+
* @property maxPitch: `undefined` (defaults to application config value, deck.gl default is 60)
|
|
72
|
+
* @property maxBounds: `undefined`,
|
|
73
|
+
* @property isSplit: `false`,
|
|
74
|
+
* @property isViewportSynced: `true`,
|
|
75
|
+
* @property isZoomLocked: `false`,
|
|
76
|
+
* @property splitMapViewports: `[]`
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export var INITIAL_MAP_STATE = {
|
|
80
|
+
pitch: 0,
|
|
81
|
+
bearing: 0,
|
|
82
|
+
latitude: 37.75043,
|
|
83
|
+
longitude: -122.34679,
|
|
84
|
+
zoom: 9,
|
|
85
|
+
dragRotate: false,
|
|
86
|
+
width: 800,
|
|
87
|
+
height: 800,
|
|
88
|
+
minZoom: undefined,
|
|
89
|
+
maxZoom: undefined,
|
|
90
|
+
maxPitch: undefined,
|
|
91
|
+
maxBounds: undefined,
|
|
92
|
+
isSplit: false,
|
|
93
|
+
isViewportSynced: true,
|
|
94
|
+
isZoomLocked: false,
|
|
95
|
+
splitMapViewports: [],
|
|
96
|
+
mapViewMode: MapViewMode.MODE_2D,
|
|
97
|
+
globe: {
|
|
98
|
+
enabled: false,
|
|
99
|
+
config: DEFAULT_GLOBE_CONFIG
|
|
100
|
+
},
|
|
101
|
+
mapSplitMode: MapSplitMode.SINGLE_MAP,
|
|
102
|
+
swipeComparePercentage: 50
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/* Updaters */
|
|
106
|
+
/**
|
|
107
|
+
* Update map viewport
|
|
108
|
+
* @memberof mapStateUpdaters
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export var updateMapUpdater = function updateMapUpdater(state, action) {
|
|
112
|
+
var _action$payload = action.payload,
|
|
113
|
+
inputViewport = _action$payload.viewport,
|
|
114
|
+
_action$payload$mapIn = _action$payload.mapIndex,
|
|
115
|
+
mapIndex = _action$payload$mapIn === void 0 ? 0 : _action$payload$mapIn;
|
|
116
|
+
var viewport = validateViewPort(inputViewport);
|
|
117
|
+
if (state.isViewportSynced) {
|
|
118
|
+
var _state$globe;
|
|
119
|
+
// The `updateViewport` function is typed as (Viewport, Viewport) -> Viewport but here the
|
|
120
|
+
// expected typing is (MapState, Viewport) -> MapState.
|
|
121
|
+
// this could be a potential bug as we treat Viewport and MapState as equal seemingly
|
|
122
|
+
// @ts-expect-error Type 'Viewport' is missing the following properties from type 'MapState': isSplit, isViewportSynced, isZoomLocked, splitMapViewports
|
|
123
|
+
return updateViewport(state, viewport, Boolean((_state$globe = state.globe) === null || _state$globe === void 0 ? void 0 : _state$globe.enabled));
|
|
124
|
+
}
|
|
125
|
+
var otherViewportMapIndex = -1;
|
|
126
|
+
var splitMapViewports = state.splitMapViewports.map(function (currentViewport, i) {
|
|
127
|
+
if (i === mapIndex) {
|
|
128
|
+
var _state$globe2;
|
|
129
|
+
// update the matching viewport with the newViewport info in the action payload
|
|
130
|
+
// Split viewports contain camera fields only; projection belongs to the root state.
|
|
131
|
+
return updateViewport(currentViewport, viewport, Boolean((_state$globe2 = state.globe) === null || _state$globe2 === void 0 ? void 0 : _state$globe2.enabled));
|
|
132
|
+
}
|
|
133
|
+
otherViewportMapIndex = i;
|
|
134
|
+
// make no changes to the other viewport (yet)
|
|
135
|
+
return currentViewport;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// make conditional updates to the other viewport not matching this payload's `mapIndex`
|
|
139
|
+
if (Number.isFinite(otherViewportMapIndex) && otherViewportMapIndex > -1) {
|
|
140
|
+
// width and height are a special case and are always updated
|
|
141
|
+
splitMapViewports[otherViewportMapIndex] = _objectSpread(_objectSpread({}, splitMapViewports[otherViewportMapIndex]), {}, {
|
|
142
|
+
width: splitMapViewports[mapIndex].width,
|
|
143
|
+
height: splitMapViewports[mapIndex].height
|
|
144
|
+
});
|
|
145
|
+
if (state.isZoomLocked) {
|
|
146
|
+
// update the other viewport with the new zoom from the split viewport that was updated with this payload's `mapIndex`
|
|
147
|
+
splitMapViewports[otherViewportMapIndex] = _objectSpread(_objectSpread({}, splitMapViewports[otherViewportMapIndex]), {}, {
|
|
148
|
+
zoom: splitMapViewports[mapIndex].zoom
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return _objectSpread(_objectSpread(_objectSpread({}, state), splitMapViewports[mapIndex]), {}, {
|
|
153
|
+
// update the mapState with the new array of split viewports
|
|
154
|
+
splitMapViewports: splitMapViewports
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Apply a partial map state from the viewport JSON editor.
|
|
160
|
+
* Preserves current width/height so saved JSON cannot resize the map container,
|
|
161
|
+
* including nested split-map viewports. When viewports are unsynced, camera
|
|
162
|
+
* fields are applied to the opened map pane (`mapIndex`), matching `updateMap`.
|
|
163
|
+
* @memberof mapStateUpdaters
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
var APPLY_MAP_STATE_VIEWPORT_KEYS = ['latitude', 'longitude', 'zoom', 'pitch', 'bearing', 'dragRotate', 'minZoom', 'maxZoom', 'maxPitch'];
|
|
167
|
+
export var applyMapStateUpdater = function applyMapStateUpdater(state, action) {
|
|
168
|
+
var _action$meta$mapIndex, _action$meta;
|
|
169
|
+
var next = action.payload || {};
|
|
170
|
+
var mapIndex = (_action$meta$mapIndex = (_action$meta = action.meta) === null || _action$meta === void 0 ? void 0 : _action$meta.mapIndex) !== null && _action$meta$mapIndex !== void 0 ? _action$meta$mapIndex : 0;
|
|
171
|
+
var width = state.width,
|
|
172
|
+
height = state.height;
|
|
173
|
+
var nextConfig = _objectSpread({}, next);
|
|
174
|
+
delete nextConfig.width;
|
|
175
|
+
delete nextConfig.height;
|
|
176
|
+
if (Array.isArray(next.splitMapViewports)) {
|
|
177
|
+
nextConfig.splitMapViewports = next.splitMapViewports.map(function (viewport, i) {
|
|
178
|
+
var _state$splitMapViewpo, _state$splitMapViewpo2, _state$splitMapViewpo3, _state$splitMapViewpo4;
|
|
179
|
+
return _objectSpread(_objectSpread({}, viewport), {}, {
|
|
180
|
+
width: (_state$splitMapViewpo = (_state$splitMapViewpo2 = state.splitMapViewports[i]) === null || _state$splitMapViewpo2 === void 0 ? void 0 : _state$splitMapViewpo2.width) !== null && _state$splitMapViewpo !== void 0 ? _state$splitMapViewpo : width,
|
|
181
|
+
height: (_state$splitMapViewpo3 = (_state$splitMapViewpo4 = state.splitMapViewports[i]) === null || _state$splitMapViewpo4 === void 0 ? void 0 : _state$splitMapViewpo4.height) !== null && _state$splitMapViewpo3 !== void 0 ? _state$splitMapViewpo3 : height
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
var mergedState = deepmerge(state, nextConfig, {
|
|
186
|
+
arrayMerge: function arrayMerge(_destinationArray, sourceArray) {
|
|
187
|
+
return sourceArray;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
var applied = validateViewPort(_objectSpread(_objectSpread({}, mergedState), {}, {
|
|
191
|
+
width: width,
|
|
192
|
+
height: height
|
|
193
|
+
}));
|
|
194
|
+
if (!state.isViewportSynced && state.splitMapViewports.length) {
|
|
195
|
+
var viewport = pick(next, APPLY_MAP_STATE_VIEWPORT_KEYS);
|
|
196
|
+
if (Object.keys(viewport).length) {
|
|
197
|
+
return updateMapUpdater(applied, {
|
|
198
|
+
payload: {
|
|
199
|
+
viewport: viewport,
|
|
200
|
+
mapIndex: mapIndex
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return applied;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Fit map viewport to bounds
|
|
210
|
+
* @memberof mapStateUpdaters
|
|
211
|
+
* @public
|
|
212
|
+
*/
|
|
213
|
+
export var fitBoundsUpdater = function fitBoundsUpdater(state, action) {
|
|
214
|
+
var _action$meta2, _state$globe3;
|
|
215
|
+
var centerAndZoom = getCenterAndZoomFromBounds(action.payload, {
|
|
216
|
+
width: state.width,
|
|
217
|
+
height: state.height,
|
|
218
|
+
padding: (_action$meta2 = action.meta) === null || _action$meta2 === void 0 ? void 0 : _action$meta2.padding
|
|
219
|
+
});
|
|
220
|
+
if (!centerAndZoom) {
|
|
221
|
+
// bounds is invalid
|
|
222
|
+
return state;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// In globe mode, clamp zoom to globe's allowed range
|
|
226
|
+
var isGlobeMode = Boolean((_state$globe3 = state.globe) === null || _state$globe3 === void 0 ? void 0 : _state$globe3.enabled);
|
|
227
|
+
var zoom = Number.isFinite(centerAndZoom.zoom) ? isGlobeMode ? Math.min(Math.max(centerAndZoom.zoom, GLOBE_MIN_ZOOM), GLOBE_MAX_ZOOM) : centerAndZoom.zoom : undefined;
|
|
228
|
+
var newState = _objectSpread(_objectSpread({}, state), {}, {
|
|
229
|
+
latitude: centerAndZoom.center[1],
|
|
230
|
+
longitude: centerAndZoom.center[0]
|
|
231
|
+
}, zoom !== undefined ? {
|
|
232
|
+
zoom: zoom
|
|
233
|
+
} : {});
|
|
234
|
+
|
|
235
|
+
// if fitting to bounds while split and unsynced
|
|
236
|
+
// copy the new latitude, longitude, and zoom values to each split viewport
|
|
237
|
+
if (newState.splitMapViewports.length) {
|
|
238
|
+
newState.splitMapViewports = newState.splitMapViewports.map(function (currentViewport) {
|
|
239
|
+
return _objectSpread(_objectSpread({}, currentViewport), {}, {
|
|
240
|
+
latitude: newState.latitude,
|
|
241
|
+
longitude: newState.longitude,
|
|
242
|
+
zoom: newState.zoom
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return newState;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Toggle between 3d and 2d map.
|
|
251
|
+
* @memberof mapStateUpdaters
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
export var togglePerspectiveUpdater = function togglePerspectiveUpdater(state) {
|
|
255
|
+
var _state$globe4;
|
|
256
|
+
// Only drop min/maxZoom when we're actually leaving globe mode, where those
|
|
257
|
+
// bounds are set to globe-only values. If globe was never enabled these are
|
|
258
|
+
// the app's own custom bounds and must be preserved.
|
|
259
|
+
var wasGlobeEnabled = Boolean((_state$globe4 = state.globe) === null || _state$globe4 === void 0 ? void 0 : _state$globe4.enabled);
|
|
260
|
+
var newState = _objectSpread(_objectSpread(_objectSpread({}, state), {
|
|
261
|
+
pitch: state.dragRotate ? 0 : 50,
|
|
262
|
+
bearing: state.dragRotate ? 0 : 24
|
|
263
|
+
}), {}, {
|
|
264
|
+
dragRotate: !state.dragRotate,
|
|
265
|
+
mapViewMode: state.dragRotate ? MapViewMode.MODE_2D : MapViewMode.MODE_3D,
|
|
266
|
+
globe: _objectSpread(_objectSpread({}, state.globe), {}, {
|
|
267
|
+
enabled: false
|
|
268
|
+
})
|
|
269
|
+
}, wasGlobeEnabled ? {
|
|
270
|
+
minZoom: undefined,
|
|
271
|
+
maxZoom: undefined
|
|
272
|
+
} : {});
|
|
273
|
+
|
|
274
|
+
// if toggling 3d and 2d while split and unsynced
|
|
275
|
+
// copy the new pitch, bearing, and dragRotate values to each split viewport
|
|
276
|
+
if (newState.splitMapViewports.length) {
|
|
277
|
+
newState.splitMapViewports = newState.splitMapViewports.map(function (currentViewport) {
|
|
278
|
+
return _objectSpread(_objectSpread({}, currentViewport), {}, {
|
|
279
|
+
pitch: newState.pitch,
|
|
280
|
+
bearing: newState.bearing,
|
|
281
|
+
dragRotate: newState.dragRotate
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
return newState;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Set map view mode (2D, 3D, Globe)
|
|
290
|
+
* @memberof mapStateUpdaters
|
|
291
|
+
* @public
|
|
292
|
+
*/
|
|
293
|
+
export var setMapViewModeUpdater = function setMapViewModeUpdater(state, action) {
|
|
294
|
+
var _state$globe5;
|
|
295
|
+
var mapViewMode = action.payload.mapViewMode;
|
|
296
|
+
var nextState;
|
|
297
|
+
|
|
298
|
+
// Only clear min/maxZoom when leaving globe mode (where they hold globe-only
|
|
299
|
+
// bounds). Otherwise preserve the app's custom bounds.
|
|
300
|
+
var wasGlobeEnabled = Boolean((_state$globe5 = state.globe) === null || _state$globe5 === void 0 ? void 0 : _state$globe5.enabled);
|
|
301
|
+
switch (mapViewMode) {
|
|
302
|
+
case MapViewMode.MODE_2D:
|
|
303
|
+
nextState = _objectSpread(_objectSpread(_objectSpread({}, state), {}, {
|
|
304
|
+
globe: _objectSpread(_objectSpread({}, state.globe), {}, {
|
|
305
|
+
enabled: false
|
|
306
|
+
}),
|
|
307
|
+
pitch: 0,
|
|
308
|
+
bearing: 0,
|
|
309
|
+
dragRotate: false
|
|
310
|
+
}, wasGlobeEnabled ? {
|
|
311
|
+
minZoom: undefined,
|
|
312
|
+
maxZoom: undefined
|
|
313
|
+
} : {}), {}, {
|
|
314
|
+
mapViewMode: mapViewMode
|
|
315
|
+
});
|
|
316
|
+
break;
|
|
317
|
+
case MapViewMode.MODE_3D:
|
|
318
|
+
nextState = _objectSpread(_objectSpread(_objectSpread({}, state), {}, {
|
|
319
|
+
globe: _objectSpread(_objectSpread({}, state.globe), {}, {
|
|
320
|
+
enabled: false
|
|
321
|
+
}),
|
|
322
|
+
pitch: 50,
|
|
323
|
+
bearing: 24,
|
|
324
|
+
dragRotate: true
|
|
325
|
+
}, wasGlobeEnabled ? {
|
|
326
|
+
minZoom: undefined,
|
|
327
|
+
maxZoom: undefined
|
|
328
|
+
} : {}), {}, {
|
|
329
|
+
mapViewMode: mapViewMode
|
|
330
|
+
});
|
|
331
|
+
break;
|
|
332
|
+
case MapViewMode.MODE_GLOBE:
|
|
333
|
+
nextState = _objectSpread(_objectSpread({}, state), {}, {
|
|
334
|
+
globe: _objectSpread(_objectSpread({}, state.globe), {}, {
|
|
335
|
+
enabled: true
|
|
336
|
+
}),
|
|
337
|
+
dragRotate: true,
|
|
338
|
+
pitch: 0,
|
|
339
|
+
bearing: 0,
|
|
340
|
+
// Allow zooming out further than the default so the whole globe can be
|
|
341
|
+
// pulled back on screen. Cap the max zoom so the basemap tiles stay
|
|
342
|
+
// coherent (they break down at high globe zoom in deck.gl 9.x).
|
|
343
|
+
minZoom: GLOBE_MIN_ZOOM,
|
|
344
|
+
maxZoom: GLOBE_MAX_ZOOM,
|
|
345
|
+
zoom: Math.min(Math.max(state.zoom, GLOBE_MIN_ZOOM), GLOBE_MAX_ZOOM),
|
|
346
|
+
mapViewMode: mapViewMode
|
|
347
|
+
});
|
|
348
|
+
break;
|
|
349
|
+
default:
|
|
350
|
+
return state;
|
|
351
|
+
}
|
|
352
|
+
if (nextState.splitMapViewports.length) {
|
|
353
|
+
nextState.splitMapViewports = nextState.splitMapViewports.map(function (currentViewport) {
|
|
354
|
+
return _objectSpread(_objectSpread({}, currentViewport), {}, {
|
|
355
|
+
pitch: nextState.pitch,
|
|
356
|
+
bearing: nextState.bearing,
|
|
357
|
+
dragRotate: nextState.dragRotate
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
return nextState;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Update globe config
|
|
366
|
+
* @memberof mapStateUpdaters
|
|
367
|
+
* @public
|
|
368
|
+
*/
|
|
369
|
+
export var globeConfigChangeUpdater = function globeConfigChangeUpdater(state, action) {
|
|
370
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
371
|
+
globe: _objectSpread(_objectSpread({}, state.globe), {}, {
|
|
372
|
+
config: _objectSpread(_objectSpread({}, state.globe.config), action.payload)
|
|
373
|
+
})
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* reset mapState to initial State
|
|
379
|
+
* @memberof mapStateUpdaters
|
|
380
|
+
* @public
|
|
381
|
+
*/
|
|
382
|
+
export var resetMapConfigUpdater = function resetMapConfigUpdater(state) {
|
|
383
|
+
return _objectSpread(_objectSpread(_objectSpread({}, INITIAL_MAP_STATE), state.initialState), {}, {
|
|
384
|
+
initialState: state.initialState
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// consider case where you have a split map and user wants to reset
|
|
389
|
+
/**
|
|
390
|
+
* Update `mapState` to propagate a new config
|
|
391
|
+
* @memberof mapStateUpdaters
|
|
392
|
+
* @public
|
|
393
|
+
*/
|
|
394
|
+
export var receiveMapConfigUpdater = function receiveMapConfigUpdater(state, _ref) {
|
|
395
|
+
var _ref$payload = _ref.payload,
|
|
396
|
+
_ref$payload$config = _ref$payload.config,
|
|
397
|
+
config = _ref$payload$config === void 0 ? {} : _ref$payload$config,
|
|
398
|
+
_ref$payload$options = _ref$payload.options,
|
|
399
|
+
options = _ref$payload$options === void 0 ? {} : _ref$payload$options,
|
|
400
|
+
_ref$payload$bounds = _ref$payload.bounds,
|
|
401
|
+
bounds = _ref$payload$bounds === void 0 ? null : _ref$payload$bounds;
|
|
402
|
+
/**
|
|
403
|
+
* @type {Partial<MapState>}
|
|
404
|
+
*/
|
|
405
|
+
var mapState = (config || {}).mapState || {};
|
|
406
|
+
// merged received mapState with previous state
|
|
407
|
+
// state also may include properties that are new to an existing, saved project's mapState
|
|
408
|
+
|
|
409
|
+
var mergedState = deepmerge(state, mapState, {
|
|
410
|
+
// note: deepmerge by default will merge arrays by concatenating them
|
|
411
|
+
// but we need to overwrite destination arrays with source arrays, if present
|
|
412
|
+
// https://github.com/TehShrike/deepmerge#arraymerge-example-overwrite-target-array
|
|
413
|
+
arrayMerge: function arrayMerge(_destinationArray, sourceArray) {
|
|
414
|
+
return sourceArray;
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// if center map
|
|
419
|
+
// center map will override mapState config
|
|
420
|
+
if (options.centerMap && bounds) {
|
|
421
|
+
mergedState = fitBoundsUpdater(mergedState, {
|
|
422
|
+
payload: bounds,
|
|
423
|
+
meta: {
|
|
424
|
+
padding: options.padding
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// make sure we validate map state before we merge
|
|
430
|
+
mergedState = validateViewPort(mergedState);
|
|
431
|
+
return _objectSpread(_objectSpread({}, mergedState), getMapDimForSplitMap(mergedState.isSplit, state));
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Toggle between one or split maps
|
|
436
|
+
* @memberof mapStateUpdaters
|
|
437
|
+
* @public
|
|
438
|
+
*/
|
|
439
|
+
export var toggleSplitMapUpdater = function toggleSplitMapUpdater(state) {
|
|
440
|
+
return _objectSpread(_objectSpread(_objectSpread({}, state), getMapDimForSplitMap(!state.isSplit, state)), {}, {
|
|
441
|
+
isSplit: !state.isSplit,
|
|
442
|
+
mapSplitMode: !state.isSplit ? MapSplitMode.DUAL_MAP : MapSplitMode.SINGLE_MAP
|
|
443
|
+
}, !state.isSplit === false ? {
|
|
444
|
+
// if toggling to no longer split (single mode) then reset a few properties
|
|
445
|
+
isViewportSynced: true,
|
|
446
|
+
isZoomLocked: false,
|
|
447
|
+
splitMapViewports: []
|
|
448
|
+
} : {});
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Set the map split mode (single, dual, or swipe)
|
|
453
|
+
* @memberof mapStateUpdaters
|
|
454
|
+
* @public
|
|
455
|
+
*/
|
|
456
|
+
export var setMapSplitModeUpdater = function setMapSplitModeUpdater(state, action) {
|
|
457
|
+
var mapSplitMode = action.payload.mapSplitMode;
|
|
458
|
+
var prevMode = state.mapSplitMode;
|
|
459
|
+
if (mapSplitMode === prevMode) {
|
|
460
|
+
return state;
|
|
461
|
+
}
|
|
462
|
+
switch (mapSplitMode) {
|
|
463
|
+
case MapSplitMode.SINGLE_MAP:
|
|
464
|
+
return _objectSpread(_objectSpread(_objectSpread({}, state), {}, {
|
|
465
|
+
mapSplitMode: mapSplitMode,
|
|
466
|
+
isSplit: false
|
|
467
|
+
}, prevMode === MapSplitMode.DUAL_MAP && {
|
|
468
|
+
width: state.width * 2
|
|
469
|
+
}), {}, {
|
|
470
|
+
isViewportSynced: true,
|
|
471
|
+
isZoomLocked: false,
|
|
472
|
+
splitMapViewports: []
|
|
473
|
+
});
|
|
474
|
+
case MapSplitMode.DUAL_MAP:
|
|
475
|
+
return _objectSpread(_objectSpread(_objectSpread({}, state), {}, {
|
|
476
|
+
mapSplitMode: mapSplitMode,
|
|
477
|
+
isSplit: true
|
|
478
|
+
}, prevMode === MapSplitMode.SINGLE_MAP && {
|
|
479
|
+
width: state.width / 2
|
|
480
|
+
}), prevMode === MapSplitMode.SWIPE_COMPARE && {
|
|
481
|
+
width: state.width / 2
|
|
482
|
+
});
|
|
483
|
+
case MapSplitMode.SWIPE_COMPARE:
|
|
484
|
+
return _objectSpread(_objectSpread(_objectSpread({}, state), {}, {
|
|
485
|
+
mapSplitMode: mapSplitMode,
|
|
486
|
+
isSplit: true
|
|
487
|
+
}, prevMode === MapSplitMode.DUAL_MAP && {
|
|
488
|
+
width: state.width * 2
|
|
489
|
+
}), {}, {
|
|
490
|
+
isViewportSynced: true,
|
|
491
|
+
isZoomLocked: false,
|
|
492
|
+
splitMapViewports: []
|
|
493
|
+
});
|
|
494
|
+
default:
|
|
495
|
+
return state;
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Set the swipe compare percentage
|
|
501
|
+
* @memberof mapStateUpdaters
|
|
502
|
+
* @public
|
|
503
|
+
*/
|
|
504
|
+
export var setSwipeComparePercentageUpdater = function setSwipeComparePercentageUpdater(state, action) {
|
|
505
|
+
var percentage = action.payload.percentage;
|
|
506
|
+
var clamped = Math.min(100, Math.max(0, percentage));
|
|
507
|
+
if (clamped === state.swipeComparePercentage) {
|
|
508
|
+
return state;
|
|
509
|
+
}
|
|
510
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
511
|
+
swipeComparePercentage: clamped
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Toggle between locked and unlocked split viewports
|
|
517
|
+
* @memberof mapStateUpdaters
|
|
518
|
+
* @public
|
|
519
|
+
*/
|
|
520
|
+
export var toggleSplitMapViewportUpdater = function toggleSplitMapViewportUpdater(state, action) {
|
|
521
|
+
// Swipe mode always uses synced viewports
|
|
522
|
+
if (state.mapSplitMode === MapSplitMode.SWIPE_COMPARE) {
|
|
523
|
+
return state;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// new map state immediately gets the new, optional payload values for isViewportSynced and/or isZoomLocked
|
|
527
|
+
var newMapState = _objectSpread(_objectSpread({}, state), action.payload || {});
|
|
528
|
+
if (newMapState.isViewportSynced) {
|
|
529
|
+
// switching from unsynced to synced viewports
|
|
530
|
+
newMapState.splitMapViewports = [];
|
|
531
|
+
} else {
|
|
532
|
+
// switching from synced to unsynced viewports
|
|
533
|
+
// or already in unsynced mode and toggling locked zoom
|
|
534
|
+
|
|
535
|
+
if (state.isZoomLocked && !newMapState.isZoomLocked) {
|
|
536
|
+
// switching off locked zoom while unsynced
|
|
537
|
+
// don't copy the mapStates to left and right viewports because there will be zoom "jumping"
|
|
538
|
+
return newMapState;
|
|
539
|
+
}
|
|
540
|
+
if (!state.isZoomLocked && newMapState.isZoomLocked) {
|
|
541
|
+
// switching on locked zoom while unsynced
|
|
542
|
+
// only copy zoom viewport property from the most recently interacted-with viewport to the other
|
|
543
|
+
// TODO: do we want to check for a match a different way, such as a combo of `latitude` and `longitude`?
|
|
544
|
+
var lastUpdatedViewportIndex = newMapState.splitMapViewports.findIndex(function (v) {
|
|
545
|
+
return newMapState.zoom === v.zoom;
|
|
546
|
+
});
|
|
547
|
+
var splitMapViewports = newMapState.splitMapViewports.map(function (currentViewport, i) {
|
|
548
|
+
if (i === lastUpdatedViewportIndex) {
|
|
549
|
+
// no zoom to modify here
|
|
550
|
+
return currentViewport;
|
|
551
|
+
}
|
|
552
|
+
// the other viewport gets the most recently interacted-with viewport's zoom
|
|
553
|
+
// WHY? the viewport the user was last interacting with will set zoom across the board for smooth UX
|
|
554
|
+
return _objectSpread(_objectSpread({}, currentViewport), {}, {
|
|
555
|
+
zoom: newMapState.splitMapViewports[lastUpdatedViewportIndex].zoom
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
newMapState.splitMapViewports = splitMapViewports;
|
|
559
|
+
return newMapState;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// if current viewport is synced, and we are unsyncing it
|
|
563
|
+
// or already in unsynced mode and NOT toggling locked zoom
|
|
564
|
+
// make a fresh copy of the current viewport object, assign it to splitMapViewports[]
|
|
565
|
+
// pickViewportPropsFromMapState is called twice to avoid memory allocation conflicts
|
|
566
|
+
var leftViewport = pickViewportPropsFromMapState(newMapState);
|
|
567
|
+
var rightViewport = pickViewportPropsFromMapState(newMapState);
|
|
568
|
+
newMapState.splitMapViewports = [leftViewport, rightViewport];
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// return new state
|
|
572
|
+
return newMapState;
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
// Helpers
|
|
576
|
+
export function getMapDimForSplitMap(isSplit, state) {
|
|
577
|
+
// cases:
|
|
578
|
+
// 1. state split: true - isSplit: true
|
|
579
|
+
// do nothing
|
|
580
|
+
// 2. state split: false - isSplit: false
|
|
581
|
+
// do nothing
|
|
582
|
+
if (state.isSplit === isSplit) {
|
|
583
|
+
return {};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// In swipe mode, both maps use full width (overlapping with clip)
|
|
587
|
+
if (state.mapSplitMode === MapSplitMode.SWIPE_COMPARE) {
|
|
588
|
+
return {};
|
|
589
|
+
}
|
|
590
|
+
var width = state.isSplit && !isSplit ?
|
|
591
|
+
// 3. state split: true - isSplit: false
|
|
592
|
+
// double width
|
|
593
|
+
state.width * 2 :
|
|
594
|
+
// 4. state split: false - isSplit: true
|
|
595
|
+
// split width
|
|
596
|
+
state.width / 2;
|
|
597
|
+
return {
|
|
598
|
+
width: width
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
function updateViewportBasedOnBounds(state, newMapState) {
|
|
602
|
+
// Get the new viewport bounds
|
|
603
|
+
var viewportBounds = geoViewport.bounds([newMapState.longitude, newMapState.latitude], newMapState.zoom, [newMapState.width, newMapState.height], MAPBOX_TILE_SIZE);
|
|
604
|
+
// Generate turf Polygon from bounds for comparison
|
|
605
|
+
var viewportBoundsPolygon = bboxPolygon(viewportBounds);
|
|
606
|
+
// @ts-ignore
|
|
607
|
+
var newStateMaxBounds = newMapState.maxBounds;
|
|
608
|
+
// @ts-ignore
|
|
609
|
+
var maxBoundsPolygon = bboxPolygon(newStateMaxBounds);
|
|
610
|
+
|
|
611
|
+
// If maxBounds has changed reset the viewport to snap to bounds
|
|
612
|
+
var hasMaxBoundsChanged = !state.maxBounds || !state.maxBounds.every(function (val, idx) {
|
|
613
|
+
return val === newStateMaxBounds[idx];
|
|
614
|
+
});
|
|
615
|
+
if (hasMaxBoundsChanged) {
|
|
616
|
+
// Check if the newMapState viewport is within maxBounds
|
|
617
|
+
if (!booleanWithin(viewportBoundsPolygon, maxBoundsPolygon)) {
|
|
618
|
+
var _fitBounds = fitBounds({
|
|
619
|
+
width: newMapState.width,
|
|
620
|
+
height: newMapState.height,
|
|
621
|
+
bounds: [[newStateMaxBounds[0], newStateMaxBounds[1]], [newStateMaxBounds[2], newStateMaxBounds[3]]]
|
|
622
|
+
}),
|
|
623
|
+
latitude = _fitBounds.latitude,
|
|
624
|
+
longitude = _fitBounds.longitude,
|
|
625
|
+
zoom = _fitBounds.zoom;
|
|
626
|
+
newMapState = _objectSpread(_objectSpread({}, newMapState), {}, {
|
|
627
|
+
latitude: latitude,
|
|
628
|
+
longitude: longitude
|
|
629
|
+
}, Number.isFinite(zoom) ? {
|
|
630
|
+
zoom: zoom
|
|
631
|
+
} : {});
|
|
632
|
+
}
|
|
633
|
+
return newMapState;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Check if the newMapState viewport is within maxBounds
|
|
637
|
+
if (!booleanWithin(viewportBoundsPolygon, maxBoundsPolygon)) {
|
|
638
|
+
newMapState = _objectSpread(_objectSpread({}, newMapState), {}, {
|
|
639
|
+
longitude: state.longitude,
|
|
640
|
+
latitude: state.latitude,
|
|
641
|
+
zoom: state.zoom
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
return newMapState;
|
|
645
|
+
}
|
|
646
|
+
export function pickViewportPropsFromMapState(state) {
|
|
647
|
+
return pick(state, ['width', 'height', 'zoom', 'pitch', 'bearing', 'latitude', 'longitude', 'dragRotate', 'minZoom', 'maxZoom', 'maxPitch', 'maxBounds']);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/** Select items from object whose value is not undefined */
|
|
651
|
+
var definedProps = function definedProps(obj) {
|
|
652
|
+
return Object.entries(obj).reduce(function (accu, _ref2) {
|
|
653
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
654
|
+
k = _ref3[0],
|
|
655
|
+
v = _ref3[1];
|
|
656
|
+
return _objectSpread(_objectSpread({}, accu), v !== undefined ? _defineProperty({}, k, v) : {});
|
|
657
|
+
}, {});
|
|
658
|
+
};
|
|
659
|
+
function updateViewport(originalViewport, viewportUpdates, isGlobe) {
|
|
660
|
+
var newViewport = _objectSpread(_objectSpread({}, originalViewport), definedProps(viewportUpdates) || {});
|
|
661
|
+
|
|
662
|
+
// deck.gl's globe controller applies a latitude-dependent adjustment to the
|
|
663
|
+
// zoom range (see KeplerGlobeView._constrainZoom). If we clamp the propagated
|
|
664
|
+
// zoom here against the raw minZoom/maxZoom (without that adjustment), Redux
|
|
665
|
+
// ends up disagreeing with the controller: the controller lets the user pull
|
|
666
|
+
// the globe further out, but this clamp snaps zoom back to `minZoom` when the
|
|
667
|
+
// interaction's inertia transition ends. Apply the same adjustment in globe
|
|
668
|
+
// mode so Redux stays consistent with the controller and there's no snap-back.
|
|
669
|
+
if (isGlobe) {
|
|
670
|
+
var _newViewport$latitude;
|
|
671
|
+
// Keep the camera target within a latitude band around the equator so the
|
|
672
|
+
// stored viewport can't be centered on the poles (matches the globe
|
|
673
|
+
// controller's applyConstraints so geocoder/programmatic updates agree).
|
|
674
|
+
if (typeof newViewport.latitude === 'number') {
|
|
675
|
+
newViewport.latitude = Math.min(GLOBE_MAX_LATITUDE, Math.max(-GLOBE_MAX_LATITUDE, newViewport.latitude));
|
|
676
|
+
}
|
|
677
|
+
var zoomAdjustment = Math.log2(Math.cos(((_newViewport$latitude = newViewport.latitude) !== null && _newViewport$latitude !== void 0 ? _newViewport$latitude : 0) * Math.PI / 180));
|
|
678
|
+
if (typeof newViewport.minZoom === 'number' && typeof newViewport.zoom === 'number' && newViewport.zoom < newViewport.minZoom + zoomAdjustment) {
|
|
679
|
+
newViewport.zoom = newViewport.minZoom + zoomAdjustment;
|
|
680
|
+
}
|
|
681
|
+
if (typeof newViewport.maxZoom === 'number' && typeof newViewport.zoom === 'number' && newViewport.zoom > newViewport.maxZoom + zoomAdjustment) {
|
|
682
|
+
newViewport.zoom = newViewport.maxZoom + zoomAdjustment;
|
|
683
|
+
}
|
|
684
|
+
} else {
|
|
685
|
+
// Make sure zoom level doesn't go bellow minZoom if defined
|
|
686
|
+
if (newViewport.minZoom && newViewport.zoom && newViewport.zoom < newViewport.minZoom) {
|
|
687
|
+
newViewport.zoom = newViewport.minZoom;
|
|
688
|
+
}
|
|
689
|
+
// Make sure zoom level doesn't go above maxZoom if defined
|
|
690
|
+
if (newViewport.maxZoom && newViewport.zoom && newViewport.zoom > newViewport.maxZoom) {
|
|
691
|
+
newViewport.zoom = newViewport.maxZoom;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
// Limit viewport update based on maxBounds
|
|
695
|
+
if (newViewport.maxBounds && validateBounds(newViewport.maxBounds)) {
|
|
696
|
+
// @ts-expect-error Type 'Viewport' is missing the following properties from type 'MapState': isSplit, isViewportSynced, isZoomLocked, splitMapViewports
|
|
697
|
+
newViewport = updateViewportBasedOnBounds(originalViewport, newViewport);
|
|
698
|
+
}
|
|
699
|
+
return newViewport;
|
|
700
|
+
}
|
|
701
|
+
//# sourceMappingURL=map-state-updaters.js.map
|