-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTooltip.jsx
More file actions
50 lines (40 loc) · 1.31 KB
/
Tooltip.jsx
File metadata and controls
50 lines (40 loc) · 1.31 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { PropTypes } from 'react';
import {Popup, PropTypes as LeafletPropTypes } from 'react-leaflet';
import { Map, popup } from 'leaflet';
import assign from 'lodash/object/assign';
export default class Tooltip extends Popup {
static propTypes = {
children: PropTypes.node,
map: PropTypes.instanceOf(Map),
tooltipContainer: PropTypes.object,
position: LeafletPropTypes.latlng,
};
componentWillMount() {
super.componentWillMount();
const { children, map, ...props } = this.props;
const options = assign({}, props);
options.className = options.className ? options.className + ' panorama-leaflet-tip' : 'panorama-leaflet-tip';
options.closeButton = false;
options.offset = options.offset || [0, -3];
this.leafletElement = popup(options);
}
componentDidMount() {}
componentDidUpdate(prevProps) {
const { map, position, isOpen, content } = this.props;
if (position !== prevProps.position) {
this.leafletElement.setLatLng(position);
}
if (content !== prevProps.content) {
this.leafletElement.setContent(content);
}
if (isOpen !== prevProps.isOpen) {
if (isOpen) {
this.leafletElement.openOn(map);
this.renderPopupContent();
} else {
map.closePopup();
this.removePopupContent();
}
}
}
}