Skip to content

Commit

Permalink
feat(FullscreenControl): add FullscreenControl
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed Jan 31, 2019
1 parent b434cac commit 4776dd8
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 20 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ You may also want to install `supercluster` package for `Cluster` component.
- [Cluster](https://urbica.github.io/react-map-gl/#cluster)
- [Popup](https://urbica.github.io/react-map-gl/#popup)
- [Marker](https://urbica.github.io/react-map-gl/#marker)
- [AttributionControl](https://urbica.github.io/react-map-gl/#attribution-control)
- [GeolocateControl](https://urbica.github.io/react-map-gl/#geolocate-control)
- [NavigationControl](https://urbica.github.io/react-map-gl/#navigation-control)
- [ScaleControl](https://urbica.github.io/react-map-gl/#scale-control)
- [AttributionControl](https://urbica.github.io/react-map-gl/#controls)
- [FullscreenControl](https://urbica.github.io/react-map-gl/#controls)
- [GeolocateControl](https://urbica.github.io/react-map-gl/#controls)
- [NavigationControl](https://urbica.github.io/react-map-gl/#controls)
- [ScaleControl](https://urbica.github.io/react-map-gl/#controls)

## Examples

Expand Down
27 changes: 27 additions & 0 deletions docs/controls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- A `NavigationControl` control contains zoom buttons and a compass.
- Geolocate the user and then track their current location on the map using the `GeolocateControl`.
- A `FullscreenControl` control contains a button for toggling the map in and out of fullscreen mode.
- A `ScaleControl` control displays the ratio of a distance on the map to the corresponding distance on the ground.
- An `AttributionControl` control presents the map's attribution information.

```jsx
<MapGL
style={{ width: '100%', height: '400px' }}
mapStyle='mapbox://styles/mapbox/light-v9'
accessToken={MAPBOX_ACCESS_TOKEN}
latitude={37.78}
longitude={-122.41}
zoom={11}
attributionControl={false}
>
<NavigationControl showCompass showZoom position='top-right' />
<GeolocateControl position='top-right' />
<FullscreenControl position='top-right' />
<AttributionControl
compact={false}
position='bottom-right'
customAttribution='Custom attribution'
/>
<ScaleControl unit='metric' position='bottom-right' />
</MapGL>
```
14 changes: 14 additions & 0 deletions docs/fullscreen-control.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
A `FullscreenControl` control contains a button for toggling the map in and out of fullscreen mode.

```jsx
<MapGL
style={{ width: '100%', height: '400px' }}
mapStyle='mapbox://styles/mapbox/light-v9'
accessToken={MAPBOX_ACCESS_TOKEN}
latitude={37.78}
longitude={-122.41}
zoom={11}
>
<FullscreenControl position='top-left' />
</MapGL>
```
2 changes: 1 addition & 1 deletion docs/scale-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ A `ScaleControl` control displays the ratio of a distance on the map to the corr
longitude={-122.41}
zoom={11}
>
<ScaleControl unit='metric' position='bottom-right' />
<ScaleControl unit='metric' position='top-right' />
</MapGL>
```
7 changes: 5 additions & 2 deletions flow-typed/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import type Map from 'mapbox-gl/src/ui/map';
import type Popup from 'mapbox-gl/src/ui/popup';
import type Marker from 'mapbox-gl/src/ui/marker';
import type AttributionControl from 'mapbox-gl/src/ui/control/attribution_control';
import type ScaleControl from 'mapbox-gl/src/ui/control/scale_control';
import type FullscreenControl from 'mapbox-gl/src/ui/control/fullscreen_control';
import type GeolocateControl from 'mapbox-gl/src/ui/control/geolocate_control';
import type NavigationControl from 'mapbox-gl/src/ui/control/navigation_control';
import type ScaleControl from 'mapbox-gl/src/ui/control/scale_control';
import type { Map as ImmutableMap } from 'immutable';
import type { MapMouseEvent, MapTouchEvent } from 'mapbox-gl/src/ui/events';

Expand All @@ -27,12 +28,14 @@ declare type MapboxMarker = Marker;

declare type MapboxAttributionControl = AttributionControl;

declare type MapboxScaleControl = ScaleControl;
declare type MapboxFullscreenControl = FullscreenControl;

declare type MapboxGeolocateControl = GeolocateControl;

declare type MapboxNavigationControl = NavigationControl;

declare type MapboxScaleControl = ScaleControl;

declare type MapboxLngLat = LngLat;

declare type MapboxLngLatBoundsLike = LngLatBoundsLike;
Expand Down
63 changes: 63 additions & 0 deletions src/components/FullscreenControl/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// @flow

import { PureComponent, createElement } from 'react';

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) {
return;
}

this._map.removeControl(this._control);
}

render() {
return createElement(MapContext.Consumer, {}, (map) => {
if (map) {
this._map = map;
}
return null;
});
}
}

export default FullscreenControl;
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ export { default as Source } from './components/Source';
export { default as Popup } from './components/Popup';
export { default as Marker } from './components/Marker';
export { default as Cluster } from './components/Cluster';
export { default as AttributionControl } from './components/AttributionControl';
export { default as FullscreenControl } from './components/FullscreenControl';
export { default as GeolocateControl } from './components/GeolocateControl';
export { default as NavigationControl } from './components/NavigationControl';
export { default as ScaleControl } from './components/ScaleControl';
35 changes: 22 additions & 13 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
'src/components/Marker/index.js',
'src/components/Cluster/index.js',
'src/components/AttributionControl/index.js',
'src/components/FullscreenControl/index.js',
'src/components/GeolocateControl/index.js',
'src/components/NavigationControl/index.js',
'src/components/ScaleControl/index.js'
Expand Down Expand Up @@ -85,22 +86,30 @@ module.exports = {
name: 'Change Map style',
content: 'docs/change-map-style.md'
},
{
name: 'Attribution Control',
content: 'docs/attribution-control.md'
},
{
name: 'Geolocate Control',
content: 'docs/geolocate-control.md'
},
{
name: 'Navigation Control',
content: 'docs/navigation-control.md'
}
// {
// name: 'Attribution Control',
// content: 'docs/attribution-control.md'
// },
// {
// name: 'Fullscreen Control',
// content: 'docs/fullscreen-control.md'
// },
// {
// name: 'Geolocate Control',
// content: 'docs/geolocate-control.md'
// },
// {
// name: 'Navigation Control',
// content: 'docs/navigation-control.md'
// }
// {
// name: 'Scale Control',
// content: 'docs/scale-control.md'
// }
// },
{
name: 'Controls',
content: 'docs/controls.md'
}
]
}
],
Expand Down

0 comments on commit 4776dd8

Please sign in to comment.