Allow renderer switching via style metadata

This commit is contained in:
Lukas Martinelli 2016-12-16 17:13:05 +01:00
parent b46598c33f
commit f1a21eca0c
2 changed files with 21 additions and 2 deletions

View file

@ -100,6 +100,7 @@ export default class App extends React.Component {
}
render() {
const renderer = this.state.currentStyle.getIn(['metadata', 'maputnik:renderer'], 'mbgljs')
const mapProps = {
mapStyle: this.state.currentStyle,
accessToken: this.state.accessToken,
@ -120,8 +121,8 @@ export default class App extends React.Component {
accessToken={this.state.accessToken}
onAccessTokenChanged={this.onAccessTokenChanged.bind(this)}
/>
{this.state.mapRenderer == 'ol3' && <OpenLayers3Map {...mapProps} />}
{this.state.mapRenderer == 'gl' && <MapboxGlMap {...mapProps} />}
{renderer == 'ol3' && <OpenLayers3Map {...mapProps} />}
{renderer == 'mbgljs' && <MapboxGlMap {...mapProps} />}
</div>
}
}

View file

@ -1,6 +1,7 @@
import React from 'react'
import Immutable from 'immutable'
import Select from 'rebass/dist/Select'
import Overlay from 'rebass/dist/Overlay'
import Panel from 'rebass/dist/Panel'
import PanelHeader from 'rebass/dist/PanelHeader'
@ -29,6 +30,11 @@ class SettingsModal extends React.Component {
this.props.onStyleChanged(changedStyle)
}
onRendererChange(e) {
const changedStyle = this.props.mapStyle.setIn(['metadata', 'maputnik:renderer'], e.target.value)
this.props.onStyleChanged(changedStyle)
}
render() {
return <Overlay open={this.props.open} >
<Panel theme={'secondary'}>
@ -62,6 +68,18 @@ class SettingsModal extends React.Component {
value={this.props.mapStyle.get('glyphs')}
onChange={this.onChange.bind(this, "glyphs")}
/>
<Input
name="glyphs"
label="Glyphs URL"
value={this.props.mapStyle.get('glyphs')}
onChange={this.onChange.bind(this, "glyphs")}
/>
<Select
label="Style Renderer"
name="renderer"
onChange={this.onRendererChange.bind(this)}
options={[{children: 'Mapbox GL JS', value: 'mbgljs'}, {children: 'Open Layers 3', value: 'ol3'}]}
/>
<PanelFooter>
<Space auto />