-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmaplayout.js
29 lines (27 loc) · 1.23 KB
/
maplayout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {mapLayoutSelector} from "@mapstore/selectors/maplayout";
import {memoize} from "lodash";
export const boundingSidebarRectSelector = (state) => state.maplayout && state.maplayout.boundingSidebarRect || {};
/**
* Retrieve only specific attribute from map layout
* @function
* @memberof selectors.mapLayout
* @param {object} state the state
* @param {object} attributes attributes to retrieve, bool {left: true}
* @param {boolean} isDock flag to use dock paddings instead of toolbar paddings
* @return {object} selected attributes of layout of the map
*/
export const mapLayoutValuesSelector = memoize((state, attributes = {}, isDock = false) => {
const layout = mapLayoutSelector(state);
const boundingSidebarRect = boundingSidebarRectSelector(state);
return layout && Object.keys(layout).filter(key =>
attributes[key]).reduce((a, key) => {
if (isDock) {
return ({...a, [key]: (boundingSidebarRect[key] ?? layout[key])});
}
return ({...a, [key]: layout[key]});
},
{}) || {};
}, (state, attributes, isDock) =>
JSON.stringify(mapLayoutSelector(state)) +
JSON.stringify(boundingSidebarRectSelector(state)) +
JSON.stringify(attributes) + (isDock ? '_isDock' : ''));