-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.js
69 lines (54 loc) · 1.56 KB
/
index.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// @flow
import { PureComponent, createElement } from 'react';
import type MapboxMap from 'mapbox-gl/src/ui/map';
import type MapboxFullscreenControl from 'mapbox-gl/src/ui/control/fullscreen_control';
import MapContext from '../MapContext';
import mapboxgl from '../../utils/mapbox-gl';
type Props = {
/**
* container is the compatible DOM element which should be
* made full screen. By default, the map container element
* will be made full screen.
*/
container: string,
/* A string representing the position of the control on the map. */
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
};
/**
* A `FullscreenControl` control contains a button for toggling the map in
* and out of fullscreen mode.
*/
class FullscreenControl extends PureComponent<Props> {
_map: MapboxMap;
_control: MapboxFullscreenControl;
static defaultProps = {
position: 'top-right'
};
componentDidMount() {
const map: MapboxMap = this._map;
const { container, position } = this.props;
const control: MapboxFullscreenControl = new mapboxgl.FullscreenControl({
container
});
map.addControl(control, position);
this._control = control;
}
componentWillUnmount() {
if (!this._map || !this._map.getStyle()) {
return;
}
this._map.removeControl(this._control);
}
getControl() {
return this._control;
}
render() {
return createElement(MapContext.Consumer, {}, (map) => {
if (map) {
this._map = map;
}
return null;
});
}
}
export default FullscreenControl;