maputnik/src/components/modals/SettingsModal.jsx

96 lines
2.9 KiB
React
Raw Normal View History

2016-12-16 16:52:16 +01:00
import React from 'react'
2017-01-09 22:37:21 +01:00
import GlSpec from 'mapbox-gl-style-spec/reference/latest.js'
import InputBlock from '../inputs/InputBlock'
import StringInput from '../inputs/StringInput'
import SelectInput from '../inputs/SelectInput'
import Modal from './Modal'
2016-12-16 16:52:16 +01:00
class SettingsModal extends React.Component {
static propTypes = {
2016-12-20 16:08:49 +01:00
mapStyle: React.PropTypes.object.isRequired,
2016-12-16 16:52:16 +01:00
onStyleChanged: React.PropTypes.func.isRequired,
2016-12-21 16:11:08 +01:00
isOpen: React.PropTypes.bool.isRequired,
2016-12-22 16:35:31 +01:00
onOpenToggle: React.PropTypes.func.isRequired,
2016-12-16 16:52:16 +01:00
}
constructor(props) {
super(props);
}
changeStyleProperty(property, value) {
const changedStyle = {
...this.props.mapStyle,
[property]: value
}
2016-12-16 16:52:16 +01:00
this.props.onStyleChanged(changedStyle)
}
changeMetadataProperty(property, value) {
2016-12-22 18:08:42 +01:00
const changedStyle = {
...this.props.mapStyle,
metadata: {
...this.props.mapStyle.metadata,
[property]: value
2016-12-22 18:08:42 +01:00
}
}
this.props.onStyleChanged(changedStyle)
}
2016-12-16 16:52:16 +01:00
render() {
const metadata = this.props.mapStyle.metadata || {}
2016-12-21 16:50:34 +01:00
const inputProps = { }
return <Modal
2016-12-21 16:11:08 +01:00
isOpen={this.props.isOpen}
2016-12-22 16:35:31 +01:00
onOpenToggle={this.props.onOpenToggle}
2017-01-09 22:37:21 +01:00
title={'Style Settings'}
>
2017-01-09 22:44:22 +01:00
<InputBlock label={"Name"} doc={GlSpec.$root.name.doc}>
<StringInput {...inputProps}
2016-12-20 16:08:49 +01:00
value={this.props.mapStyle.name}
onChange={this.changeStyleProperty.bind(this, "name")}
2016-12-16 16:52:16 +01:00
/>
</InputBlock>
2017-01-09 22:37:21 +01:00
<InputBlock label={"Owner"} doc={"Owner ID of the style. Used by Mapbox or future style APIs."}>
<StringInput {...inputProps}
2016-12-20 16:08:49 +01:00
value={this.props.mapStyle.owner}
onChange={this.changeStyleProperty.bind(this, "owner")}
2016-12-16 16:52:16 +01:00
/>
</InputBlock>
2017-01-09 22:44:22 +01:00
<InputBlock label={"Sprite URL"} doc={GlSpec.$root.sprite.doc}>
<StringInput {...inputProps}
2016-12-20 16:08:49 +01:00
value={this.props.mapStyle.sprite}
onChange={this.changeStyleProperty.bind(this, "sprite")}
2016-12-16 16:52:16 +01:00
/>
</InputBlock>
2017-01-09 22:44:22 +01:00
<InputBlock label={"Glyphs URL"} doc={GlSpec.$root.glyphs.doc}>
<StringInput {...inputProps}
2016-12-20 16:08:49 +01:00
value={this.props.mapStyle.glyphs}
onChange={this.changeStyleProperty.bind(this, "glyphs")}
/>
</InputBlock>
2017-01-09 22:37:21 +01:00
<InputBlock label={"Access Token"} doc={"Public access token for Mapbox GL."}>
<StringInput {...inputProps}
value={metadata['maputnik:access_token']}
onChange={this.changeMetadataProperty.bind(this, "maputnik:access_token")}
/>
</InputBlock>
2017-01-09 22:37:21 +01:00
<InputBlock label={"Style Renderer"} doc={"Choose the default Maputnik renderer for this style."}>
<SelectInput {...inputProps}
options={[
['mbgljs', 'MapboxGL JS'],
2016-12-24 14:42:57 +01:00
['ol3', 'Open Layers 3'],
]}
value={metadata['maputnik:renderer'] || 'mbgljs'}
onChange={this.changeMetadataProperty.bind(this, 'maputnik:renderer')}
/>
</InputBlock>
</Modal>
2016-12-16 16:52:16 +01:00
}
}
export default SettingsModal