Support setting access token

This commit is contained in:
lukasmartinelli
2016-09-10 16:26:39 +02:00
parent 8582496811
commit 2cc4055416
5 changed files with 52 additions and 15 deletions

View File

@@ -7,13 +7,17 @@ import Immutable from 'immutable'
export class Map extends React.Component {
static propTypes = {
mapStyle: React.PropTypes.instanceOf(Immutable.Map).isRequired,
accessToken: React.PropTypes.string,
}
componentWillReceiveProps(nextProps) {
const tokenChanged = nextProps.accessToken !== MapboxGl.accessToken
// If the id has changed a new style has been uplaoded and
// it is safer to do a full new render
const mapIdChanged = this.props.mapStyle.get('id') !== nextProps.mapStyle.get('id')
if(mapIdChanged) {
if(mapIdChanged || tokenChanged) {
this.state.map.setStyle(nextProps.mapStyle.toJS())
return
}
@@ -36,8 +40,7 @@ export class Map extends React.Component {
}
componentDidMount() {
//TODO: Read MapboxGL token from settings
MapboxGl.accessToken = "pk.eyJ1IjoibW9yZ2Vua2FmZmVlIiwiYSI6IjIzcmN0NlkifQ.0LRTNgCc-envt9d5MzR75w";
MapboxGl.accessToken = this.props.accessToken
const map = new MapboxGl.Map({
container: this.container,