-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ControlLayer
component to for use with Map
components
- Loading branch information
Nick Maher
committed
May 8, 2017
1 parent
da2d34e
commit 1ec5e64
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.root, .map { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
.map { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.root { | ||
width: 100%; | ||
height: 100%; | ||
position: relative; | ||
} | ||
|
||
.controlGroup { | ||
position: absolute; | ||
bottom: 0; | ||
left: 0; | ||
margin: var(--size-regular); | ||
z-index: var(--z-mapControls); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { PropTypes, Component, cloneElement } from 'react'; | ||
import cx from 'classnames'; | ||
|
||
import Control from '../Control/Control'; | ||
import ControlGroup from '../ControlGroup/ControlGroup'; | ||
import ControlIcon from '../Control/ControlIcon'; | ||
|
||
import css from './ControlLayer.css'; | ||
|
||
import { DEFAULT_ZOOM } from '../../../constants/mapbox'; | ||
|
||
export default class ControlLayer extends Component { | ||
static propTypes = { | ||
className: PropTypes.string, | ||
controlGroupClassName: PropTypes.string, | ||
children: PropTypes.element.isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
const { children: { zoom } } = props; | ||
|
||
this.state = { | ||
zoom: zoom || DEFAULT_ZOOM, | ||
}; | ||
} | ||
|
||
handleZoomOut = () => { | ||
this.setState(({ zoom }) => ({ zoom: zoom - 1 })); | ||
}; | ||
|
||
handleZoomIn = () => { | ||
this.setState(({ zoom }) => ({ zoom: zoom + 1 })); | ||
}; | ||
|
||
handleMoveEnd = (...args) => { | ||
const { children: child } = this.props; | ||
const { onMoveEnd: childOnMoveEnd } = child.props; | ||
const { zoom } = args[1]; | ||
|
||
this.setState({ zoom }); | ||
if (typeof childOnMoveEnd === 'function') childOnMoveEnd(...args); | ||
}; | ||
|
||
render() { | ||
const { children: child, className, controlGroupClassName } = this.props; | ||
const { zoom } = this.state; | ||
|
||
return ( | ||
<div className={ cx(css.root, className) }> | ||
<ControlGroup className={ cx(css.controlGroup, controlGroupClassName) }> | ||
<Control onClick={ this.handleZoomIn }> | ||
<ControlIcon name="plus" /> | ||
</Control> | ||
<Control onClick={ this.handleZoomOut }> | ||
<ControlIcon name="minus" /> | ||
</Control> | ||
</ControlGroup> | ||
{ cloneElement(child, { | ||
zoom, | ||
onMoveEnd: this.handleMoveEnd, | ||
}) } | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@kadira/storybook'; | ||
|
||
import ControlLayer from './ControlLayer'; | ||
import BaseMap from '../BaseMap'; | ||
|
||
storiesOf('Map Control Layer', module) | ||
.add('Default', () => ( | ||
<div style={ { height: '96vh' } }> | ||
<ControlLayer> | ||
<BaseMap /> | ||
</ControlLayer> | ||
</div> | ||
)); |