Skip to content

Commit 1ef6373

Browse files
authored
[Maps] use EuiPopover instead of mapbox tooltip (#45938)
* [Maps] use EuiPopover instead of mapbox tooltip * update draw tooltip to use EuiPopover, remove mapbox popup css hacks * use anchor size of 26px to fix positioning calculations * close tooltip when position is no longer visible * remove reevaluateTooltipPosition, its no longer needed * fix problem with map move and hover tooltip location not also moving
1 parent 921e356 commit 1ef6373

File tree

7 files changed

+131
-136
lines changed

7 files changed

+131
-136
lines changed

x-pack/legacy/plugins/maps/public/_mapbox_hacks.scss

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,6 @@
33
.mapContainer {
44
flex-grow: 1;
55

6-
.mapboxgl-popup {
7-
z-index: $euiZLevel2;
8-
border-color: $euiColorEmptyShade;
9-
}
10-
11-
.mapboxgl-popup-content {
12-
@include euiBottomShadow($color: #000);
13-
background-color: $euiColorEmptyShade;
14-
padding: $euiSizeS;
15-
overflow: hidden;
16-
}
17-
18-
.mapboxgl-popup-tip {
19-
border-top-color: $euiColorEmptyShade !important;
20-
}
21-
226
.mapboxgl-ctrl-top-left .mapboxgl-ctrl {
237
margin-left: $euiSizeM;
248
margin-top: $euiSizeM;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ import { GeometryFilterForm } from '../../components/geometry_filter_form';
1616

1717
export class FeatureGeometryFilterForm extends Component {
1818

19-
componentDidMount() {
20-
this.props.reevaluateTooltipPosition();
21-
}
22-
23-
componentDidUpdate() {
24-
this.props.reevaluateTooltipPosition();
25-
}
26-
2719
_createFilter = ({ geometryLabel, indexPatternId, geoFieldName, geoFieldType, relation }) => {
2820
const filter = createSpatialFilterWithGeometry({
2921
geometry: this.props.feature.geometry,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class FeatureProperties extends React.Component {
3030

3131
componentDidUpdate() {
3232
this._loadProperties();
33-
this.props.reevaluateTooltipPosition();
3433
}
3534

3635
componentWillUnmount() {

x-pack/legacy/plugins/maps/public/connected_components/map/feature_properties.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const defaultProps = {
3434
layerId: `layer`,
3535
onCloseTooltip: () => {},
3636
showFilterButtons: false,
37-
reevaluateTooltipPosition: () => {},
3837
};
3938

4039
const mockTooltipProperties = [

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ export class FeatureTooltip extends React.Component {
154154
showFilterButtons={this.props.showFilterButtons}
155155
onCloseTooltip={this._onCloseTooltip}
156156
addFilters={this.props.addFilters}
157-
reevaluateTooltipPosition={this.props.reevaluateTooltipPosition}
158157
/>
159158
);
160159
}
@@ -352,7 +351,6 @@ export class FeatureTooltip extends React.Component {
352351
feature={currentFeature}
353352
geoFields={filteredGeoFields}
354353
addFilters={this.props.addFilters}
355-
reevaluateTooltipPosition={this.props.reevaluateTooltipPosition}
356354
/>
357355
);
358356
}

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

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,84 @@
66

77
import _ from 'lodash';
88
import React, { Component } from 'react';
9-
import ReactDOM from 'react-dom';
10-
import { EuiText } from '@elastic/eui';
9+
import { EuiPopover, EuiText } from '@elastic/eui';
1110
import { i18n } from '@kbn/i18n';
1211
import { DRAW_TYPE } from '../../../../../common/constants';
13-
import mapboxgl from 'mapbox-gl';
14-
import { I18nProvider } from '@kbn/i18n/react';
12+
13+
const noop = () => {};
1514

1615
export class DrawTooltip extends Component {
1716

17+
state = {
18+
x: undefined,
19+
y: undefined,
20+
isOpen: false,
21+
};
22+
1823
constructor(props) {
1924
super(props);
20-
this._tooltipContainer = document.createElement('div');
21-
this._mbPopup = new mapboxgl.Popup({
22-
closeButton: false,
23-
closeOnClick: false,
24-
offset: 12,
25-
anchor: 'left',
26-
maxWidth: '300px',
27-
});
25+
this._popoverRef = React.createRef();
2826
}
2927

3028
componentDidMount() {
31-
this._showTooltip();
3229
this.props.mbMap.on('mousemove', this._updateTooltipLocation);
3330
this.props.mbMap.on('mouseout', this._hideTooltip);
3431
}
3532

33+
componentDidUpdate() {
34+
if (this._popoverRef.current) {
35+
this._popoverRef.current.positionPopoverFluid();
36+
}
37+
}
38+
3639
componentWillUnmount() {
3740
this.props.mbMap.off('mousemove', this._updateTooltipLocation);
3841
this.props.mbMap.off('mouseout', this._hideTooltip);
39-
this._hideTooltip();
42+
this._updateTooltipLocation.cancel();
4043
}
4144

4245
render() {
43-
return null;
44-
}
45-
46-
_showTooltip = () => {
4746
const instructions = this.props.drawState.drawType === DRAW_TYPE.BOUNDS
4847
? i18n.translate('xpack.maps.drawTooltip.boundsInstructions', {
4948
defaultMessage: 'Click to start rectangle. Click again to finish.'
5049
})
5150
: i18n.translate('xpack.maps.drawTooltip.polygonInstructions', {
5251
defaultMessage: 'Click to add vertex. Double click to finish.'
5352
});
54-
ReactDOM.render((
55-
<I18nProvider>
56-
<div>
57-
<EuiText color="subdued" size="xs">
58-
{instructions}
59-
</EuiText>
60-
</div>
61-
</I18nProvider>
62-
), this._tooltipContainer);
6353

64-
this._mbPopup.setDOMContent(this._tooltipContainer)
65-
.addTo(this.props.mbMap);
54+
const tooltipAnchor = <div style={{ height: '26px', width: '26px', background: 'transparent' }}/>;
55+
56+
return (
57+
<EuiPopover
58+
id="drawInstructionsTooltip"
59+
button={tooltipAnchor}
60+
anchorPosition="rightCenter"
61+
isOpen={this.state.isOpen}
62+
closePopover={noop}
63+
ref={this._popoverRef}
64+
style={{
65+
pointerEvents: 'none',
66+
transform: `translate(${this.state.x - 13}px, ${this.state.y - 13}px)`
67+
}}
68+
>
69+
<EuiText color="subdued" size="xs">
70+
{instructions}
71+
</EuiText>
72+
</EuiPopover>
73+
);
6674
}
6775

6876
_hideTooltip = () => {
69-
if (this._mbPopup.isOpen()) {
70-
this._mbPopup.remove();
71-
ReactDOM.unmountComponentAtNode(this._tooltipContainer);
72-
}
77+
this._updateTooltipLocation.cancel();
78+
this.setState({ isOpen: false });
7379
}
7480

7581
_updateTooltipLocation = _.throttle(({ lngLat }) => {
76-
if (!this._mbPopup.isOpen()) {
77-
this._showTooltip();
78-
}
79-
this._mbPopup.setLngLat(lngLat);
82+
const mouseLocation = this.props.mbMap.project(lngLat);
83+
this.setState({
84+
isOpen: true,
85+
x: mouseLocation.x,
86+
y: mouseLocation.y,
87+
});
8088
}, 100)
8189
}

0 commit comments

Comments
 (0)