Skip to content

Commit 3ee0683

Browse files
authored
[Maps] Feature/hide view/layer control in embeddable (#53469)
* Added options to hide layer/view controls * remove event attachments
1 parent e03b15e commit 3ee0683

File tree

9 files changed

+74
-17
lines changed

9 files changed

+74
-17
lines changed

x-pack/legacy/plugins/maps/public/actions/map_actions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export const SET_MAP_INIT_ERROR = 'SET_MAP_INIT_ERROR';
7070
export const SET_INTERACTIVE = 'SET_INTERACTIVE';
7171
export const DISABLE_TOOLTIP_CONTROL = 'DISABLE_TOOLTIP_CONTROL';
7272
export const HIDE_TOOLBAR_OVERLAY = 'HIDE_TOOLBAR_OVERLAY';
73+
export const HIDE_LAYER_CONTROL = 'HIDE_LAYER_CONTROL';
74+
export const HIDE_VIEW_CONTROL = 'HIDE_VIEW_CONTROL';
7375

7476
function getLayerLoadingCallbacks(dispatch, layerId) {
7577
return {
@@ -831,3 +833,10 @@ export function disableTooltipControl() {
831833
export function hideToolbarOverlay() {
832834
return { type: HIDE_TOOLBAR_OVERLAY, hideToolbarOverlay: true };
833835
}
836+
837+
export function hideLayerControl() {
838+
return { type: HIDE_LAYER_CONTROL, hideLayerControl: true };
839+
}
840+
export function hideViewControl() {
841+
return { type: HIDE_VIEW_CONTROL, hideViewControl: true };
842+
}

x-pack/legacy/plugins/maps/public/connected_components/map/mb/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
getScrollZoom,
2424
isInteractiveDisabled,
2525
isTooltipControlDisabled,
26+
isViewControlHidden,
2627
} from '../../../selectors/map_selectors';
2728
import { getInspectorAdapters } from '../../../reducers/non_serializable_instances';
2829

@@ -36,6 +37,8 @@ function mapStateToProps(state = {}) {
3637
scrollZoom: getScrollZoom(state),
3738
disableInteractive: isInteractiveDisabled(state),
3839
disableTooltipControl: isTooltipControlDisabled(state),
40+
disableTooltipControl: isTooltipControlDisabled(state),
41+
hideViewControl: isViewControlHidden(state),
3942
};
4043
}
4144

x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,20 @@ export class MBMapContainer extends React.Component {
188188
this.props.extentChanged(this._getMapState());
189189
}, 100)
190190
);
191-
192-
const throttledSetMouseCoordinates = _.throttle(e => {
193-
this.props.setMouseCoordinates({
194-
lat: e.lngLat.lat,
195-
lon: e.lngLat.lng,
191+
// Attach event only if view control is visible, which shows lat/lon
192+
if (!this.props.hideViewControl) {
193+
const throttledSetMouseCoordinates = _.throttle(e => {
194+
this.props.setMouseCoordinates({
195+
lat: e.lngLat.lat,
196+
lon: e.lngLat.lng,
197+
});
198+
}, 100);
199+
this.state.mbMap.on('mousemove', throttledSetMouseCoordinates);
200+
this.state.mbMap.on('mouseout', () => {
201+
throttledSetMouseCoordinates.cancel(); // cancel any delayed setMouseCoordinates invocations
202+
this.props.clearMouseCoordinates();
196203
});
197-
}, 100);
198-
this.state.mbMap.on('mousemove', throttledSetMouseCoordinates);
199-
this.state.mbMap.on('mouseout', () => {
200-
throttledSetMouseCoordinates.cancel(); // cancel any delayed setMouseCoordinates invocations
201-
this.props.clearMouseCoordinates();
202-
});
204+
}
203205
}
204206

205207
_initResizerChecker() {

x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,14 @@
77
import { connect } from 'react-redux';
88
import { WidgetOverlay } from './widget_overlay';
99

10-
const connectedWidgetOverlay = connect(null, null)(WidgetOverlay);
10+
import { isLayerControlHidden, isViewControlHidden } from '../../selectors/map_selectors';
11+
12+
function mapStateToProps(state = {}) {
13+
return {
14+
hideLayerControl: isLayerControlHidden(state),
15+
hideViewControl: isViewControlHidden(state),
16+
};
17+
}
18+
19+
const connectedWidgetOverlay = connect(mapStateToProps, null)(WidgetOverlay);
1120
export { connectedWidgetOverlay as WidgetOverlay };

x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/widget_overlay.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { LayerControl } from './layer_control';
1010
import { ViewControl } from './view_control';
1111
import { AttributionControl } from './attribution_control';
1212

13-
export function WidgetOverlay() {
13+
export function WidgetOverlay({ hideLayerControl, hideViewControl }) {
1414
return (
1515
<EuiFlexGroup
1616
className="mapWidgetOverlay"
@@ -20,11 +20,9 @@ export function WidgetOverlay() {
2020
gutterSize="s"
2121
>
2222
<EuiFlexItem className="mapWidgetOverlay__layerWrapper">
23-
<LayerControl />
24-
</EuiFlexItem>
25-
<EuiFlexItem grow={false}>
26-
<ViewControl />
23+
{!hideLayerControl && <LayerControl />}
2724
</EuiFlexItem>
25+
<EuiFlexItem grow={false}>{!hideViewControl && <ViewControl />}</EuiFlexItem>
2826
<EuiFlexItem grow={false}>
2927
<AttributionControl />
3028
</EuiFlexItem>

x-pack/legacy/plugins/maps/public/embeddable/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- **disableInteractive:** (Boolean) Will disable map interactions, panning, zooming in the map.
88
- **disableTooltipControl:** (Boolean) Will disable tooltip which shows relevant information on hover, like Continent name etc
99
- **hideToolbarOverlay:** (Boolean) Will disable toolbar, which can be used to navigate to coordinate by entering lat/long and zoom values.
10+
- **hideLayerControl:** (Boolean) Will hide useful layer control, which can be used to hide/show a layer to get a refined view of the map.
11+
- **hideViewControl:** (Boolean) Will hide view control at bottom right of the map, which shows lat/lon values based on mouse hover in the map, this is useful to get coordinate value from a particular point in map.
1012

1113
### Creating a Map embeddable from saved object
1214
```

x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {
3030
disableInteractive,
3131
disableTooltipControl,
3232
hideToolbarOverlay,
33+
hideLayerControl,
34+
hideViewControl,
3335
} from '../actions/map_actions';
3436
import { setReadOnly, setIsLayerTOCOpen, setOpenTOCDetails } from '../actions/ui_actions';
3537
import { getIsLayerTOCOpen, getOpenTOCDetails } from '../selectors/ui_selectors';
@@ -132,6 +134,14 @@ export class MapEmbeddable extends Embeddable {
132134
this._store.dispatch(hideToolbarOverlay(this.input.hideToolbarOverlay));
133135
}
134136

137+
if (_.has(this.input, 'hideLayerControl') && this.input.hideLayerControl) {
138+
this._store.dispatch(hideLayerControl(this.input.hideLayerControl));
139+
}
140+
141+
if (_.has(this.input, 'hideViewControl') && this.input.hideViewControl) {
142+
this._store.dispatch(hideViewControl(this.input.hideViewControl));
143+
}
144+
135145
if (this.input.mapCenter) {
136146
this._store.dispatch(
137147
setGotoWithCenter({

x-pack/legacy/plugins/maps/public/reducers/map.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import {
4444
SET_INTERACTIVE,
4545
DISABLE_TOOLTIP_CONTROL,
4646
HIDE_TOOLBAR_OVERLAY,
47+
HIDE_LAYER_CONTROL,
48+
HIDE_VIEW_CONTROL,
4749
} from '../actions/map_actions';
4850

4951
import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from './util';
@@ -113,6 +115,8 @@ const INITIAL_STATE = {
113115
disableInteractive: false,
114116
disableTooltipControl: false,
115117
hideToolbarOverlay: false,
118+
hideLayerControl: false,
119+
hideViewControl: false,
116120
},
117121
selectedLayerId: null,
118122
__transientLayerId: null,
@@ -356,6 +360,22 @@ export function map(state = INITIAL_STATE, action) {
356360
hideToolbarOverlay: action.hideToolbarOverlay,
357361
},
358362
};
363+
case HIDE_LAYER_CONTROL:
364+
return {
365+
...state,
366+
mapState: {
367+
...state.mapState,
368+
hideLayerControl: action.hideLayerControl,
369+
},
370+
};
371+
case HIDE_VIEW_CONTROL:
372+
return {
373+
...state,
374+
mapState: {
375+
...state.mapState,
376+
hideViewControl: action.hideViewControl,
377+
},
378+
};
359379
default:
360380
return state;
361381
}

x-pack/legacy/plugins/maps/public/selectors/map_selectors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export const isTooltipControlDisabled = ({ map }) => map.mapState.disableTooltip
7171

7272
export const isToolbarOverlayHidden = ({ map }) => map.mapState.hideToolbarOverlay;
7373

74+
export const isLayerControlHidden = ({ map }) => map.mapState.hideLayerControl;
75+
76+
export const isViewControlHidden = ({ map }) => map.mapState.hideViewControl;
77+
7478
export const getMapExtent = ({ map }) => (map.mapState.extent ? map.mapState.extent : {});
7579

7680
export const getMapBuffer = ({ map }) => (map.mapState.buffer ? map.mapState.buffer : {});

0 commit comments

Comments
 (0)