mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 15:21:20 +01:00
Change map style to add layer
This commit is contained in:
parent
29cfb58a56
commit
d1b8f8d63e
2 changed files with 26 additions and 2 deletions
|
@ -159,9 +159,9 @@ export default class Toolbar extends React.Component {
|
|||
<AddModal
|
||||
mapStyle={this.props.mapStyle}
|
||||
sources={this.props.sources}
|
||||
onStyleChanged={this.props.onStyleChanged}
|
||||
isOpen={this.state.isOpen.add}
|
||||
onOpenToggle={this.toggleModal.bind(this, 'add')}
|
||||
onStyleChange={this.props.onStyleChanged}
|
||||
/>
|
||||
<ToolbarLink
|
||||
href={"https://github.com/maputnik/editor"}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import React from 'react'
|
||||
|
||||
import Button from '../Button'
|
||||
import InputBlock from '../inputs/InputBlock'
|
||||
import StringInput from '../inputs/StringInput'
|
||||
import SelectInput from '../inputs/SelectInput'
|
||||
|
@ -14,7 +15,7 @@ import LayerSourceLayerBlock from '../layers/LayerSourceLayerBlock'
|
|||
class AddModal extends React.Component {
|
||||
static propTypes = {
|
||||
mapStyle: React.PropTypes.object.isRequired,
|
||||
onStyleChanged: React.PropTypes.func.isRequired,
|
||||
onStyleChange: React.PropTypes.func.isRequired,
|
||||
isOpen: React.PropTypes.bool.isRequired,
|
||||
onOpenToggle: React.PropTypes.func.isRequired,
|
||||
|
||||
|
@ -22,6 +23,24 @@ class AddModal extends React.Component {
|
|||
sources: React.PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
addLayer() {
|
||||
const changedLayers = this.props.mapStyle.layers.slice(0)
|
||||
changedLayers.push({
|
||||
id: this.state.id,
|
||||
type: this.state.type,
|
||||
source: this.state.source,
|
||||
'source-layer': this.state['source-layer'],
|
||||
})
|
||||
|
||||
const changedStyle = {
|
||||
...this.props.mapStyle,
|
||||
layers: changedLayers,
|
||||
}
|
||||
|
||||
this.props.onStyleChange(changedStyle)
|
||||
this.props.onOpenToggle(false)
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
|
@ -31,6 +50,7 @@ class AddModal extends React.Component {
|
|||
|
||||
if(props.sources.length > 0) {
|
||||
this.state.source = Object.keys(this.props.sources)[0]
|
||||
this.state['source-layer'] = this.props.sources[this.state.source][0]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +59,7 @@ class AddModal extends React.Component {
|
|||
if(!this.state.source && sourceIds.length > 0) {
|
||||
this.setState({
|
||||
source: sourceIds[0],
|
||||
'source-layer': this.state['source-layer'] || nextProps.sources[sourceIds[0]][0]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +89,9 @@ class AddModal extends React.Component {
|
|||
value={this.state['source-layer']}
|
||||
onChange={v => this.setState({ 'source-layer': v })}
|
||||
/>
|
||||
<Button onClick={this.addLayer.bind(this)}>
|
||||
Add Layer
|
||||
</Button>
|
||||
</Modal>
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue