File tree Expand file tree Collapse file tree 5 files changed +86
-1
lines changed
components/NavigationControl Expand file tree Collapse file tree 5 files changed +86
-1
lines changed Original file line number Diff line number Diff line change
1
+ A ` NavigationControl ` control contains zoom buttons and a compass.
2
+
3
+ ``` jsx
4
+ < MapGL
5
+ style= {{ width: ' 100%' , height: ' 400px' }}
6
+ mapStyle= ' mapbox://styles/mapbox/light-v9'
7
+ accessToken= {MAPBOX_ACCESS_TOKEN }
8
+ latitude= {37.78 }
9
+ longitude= {- 122.41 }
10
+ zoom= {11 }
11
+ >
12
+ < NavigationControl showCompass showZoom position= ' top-left' / >
13
+ < / MapGL>
14
+ ```
Original file line number Diff line number Diff line change 3
3
import type Map from 'mapbox-gl/src/ui/map' ;
4
4
import type Popup from 'mapbox-gl/src/ui/popup' ;
5
5
import type Marker from 'mapbox-gl/src/ui/marker' ;
6
+ import type NavigationControl from 'mapbox-gl/src/ui/control/navigation_control' ;
6
7
import type { Map as ImmutableMap } from 'immutable' ;
7
8
import type { MapMouseEvent , MapTouchEvent } from 'mapbox-gl/src/ui/events' ;
8
9
@@ -20,6 +21,8 @@ declare type MapboxPopup = Popup;
20
21
21
22
declare type MapboxMarker = Marker ;
22
23
24
+ declare type MapboxNavigationControl = NavigationControl ;
25
+
23
26
declare type MapboxLngLatBoundsLike = LngLatBoundsLike ;
24
27
25
28
declare type MapboxLayerSpecification = LayerSpecification ;
Original file line number Diff line number Diff line change
1
+ // @flow
2
+
3
+ import { PureComponent , createElement } from 'react' ;
4
+
5
+ import MapContext from '../MapContext' ;
6
+ import mapboxgl from '../../utils/mapbox-gl' ;
7
+
8
+ type Props = {
9
+ /* If true the compass button is included. */
10
+ showCompass : boolean ,
11
+
12
+ /* If true the zoom-in and zoom-out buttons are included. */
13
+ showZoom : boolean ,
14
+
15
+ /* A string representing the position of the control on the map. */
16
+ position ?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
17
+ } ;
18
+
19
+ /**
20
+ * A `NavigationControl` control contains zoom buttons and a compass.
21
+ */
22
+ class NavigationControl extends PureComponent < Props > {
23
+ _map : MapboxMap ;
24
+
25
+ _control : MapboxNavigationControl ;
26
+
27
+ static defaultProps = {
28
+ position : 'top-right'
29
+ } ;
30
+
31
+ componentDidMount ( ) {
32
+ const map : MapboxMap = this . _map ;
33
+ const { showCompass, showZoom, position } = this . props ;
34
+
35
+ const control : MapboxNavigationControl = new mapboxgl . NavigationControl ( {
36
+ showCompass,
37
+ showZoom
38
+ } ) ;
39
+
40
+ map . addControl ( control , position ) ;
41
+ this . _control = control ;
42
+ }
43
+
44
+ componentWillUnmount ( ) {
45
+ if ( ! this . _map ) {
46
+ return ;
47
+ }
48
+
49
+ this . _map . removeControl ( this . _control ) ;
50
+ }
51
+
52
+ render ( ) {
53
+ return createElement ( MapContext . Consumer , { } , ( map ) => {
54
+ if ( map ) {
55
+ this . _map = map ;
56
+ }
57
+ return null ;
58
+ } ) ;
59
+ }
60
+ }
61
+
62
+ export default NavigationControl ;
Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ export { default as Source } from './components/Source';
6
6
export { default as Popup } from './components/Popup' ;
7
7
export { default as Marker } from './components/Marker' ;
8
8
export { default as Cluster } from './components/Cluster' ;
9
+ export { default as NavigationControl } from './components/NavigationControl' ;
Original file line number Diff line number Diff line change @@ -23,7 +23,8 @@ module.exports = {
23
23
'src/components/Layer/index.js' ,
24
24
'src/components/Popup/index.js' ,
25
25
'src/components/Marker/index.js' ,
26
- 'src/components/Cluster/index.js'
26
+ 'src/components/Cluster/index.js' ,
27
+ 'src/components/NavigationControl/index.js'
27
28
]
28
29
} ,
29
30
{
@@ -80,6 +81,10 @@ module.exports = {
80
81
{
81
82
name : 'Change Map style' ,
82
83
content : 'docs/change-map-style.md'
84
+ } ,
85
+ {
86
+ name : 'Navigation Control' ,
87
+ content : 'docs/navigation-control.md'
83
88
}
84
89
]
85
90
}
You can’t perform that action at this time.
0 commit comments