Add support to change source TileJSON url

This commit is contained in:
lukasmartinelli 2016-09-21 22:47:17 +02:00
parent 604e76212b
commit e524765c13
3 changed files with 21 additions and 1 deletions

View file

@ -21,6 +21,7 @@ class UnsupportedSource extends React.Component {
class VectorSource extends React.Component {
static propTypes = {
source: React.PropTypes.instanceOf(Immutable.Map).isRequired,
onSourceChanged: React.PropTypes.func.isRequired,
}
constructor(props) {
@ -30,7 +31,11 @@ class VectorSource extends React.Component {
render() {
return <div>
<Input name="url" label="TileJSON url" value={this.props.source.get("url")} />
<Input
onChange={e => this.props.onSourceChanged(this.props.source.set('url', e.target.value))}
name="url" label="TileJSON url"
value={this.props.source.get("url")}
/>
<Input name="minzoom" label="Minimum zoom level" value={this.props.source.get("minzoom")} />
<Input name="maxzoom" label="Maximum zoom level" value={this.props.source.get("maxzoom")} />
</div>
@ -41,6 +46,7 @@ export class SourceEditor extends React.Component {
static propTypes = {
sourceId: React.PropTypes.string.isRequired,
source: React.PropTypes.instanceOf(Immutable.Map).isRequired,
onSourceChanged: React.PropTypes.func.isRequired,
}
constructor(props) {
@ -58,6 +64,7 @@ export class SourceEditor extends React.Component {
sourceFromType(type) {
if (type === "vector") {
return <VectorSource
onSourceChanged={s => this.props.onSourceChanged(this.props.sourceId, s)}
source={this.props.source}
/>
}

View file

@ -14,6 +14,7 @@ import PureRenderMixin from 'react-addons-pure-render-mixin';
export class SourceList extends React.Component {
static propTypes = {
sources: React.PropTypes.instanceOf(Immutable.Map).isRequired,
onSourcesChanged: React.PropTypes.func.isRequired,
}
constructor(props) {
@ -21,12 +22,18 @@ export class SourceList extends React.Component {
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
onSourceChanged(sourceId, changedSource) {
const changedSources = this.props.sources.set(sourceId, changedSource)
this.props.onSourcesChanged(changedSources)
}
render() {
const sourceEditors = this.props.sources.map((source, sourceId) => {
return <SourceEditor
key={sourceId}
sourceId={sourceId}
source={source}
onSourceChanged={this.onSourceChanged.bind(this)}
/>
}).toIndexedSeq()

View file

@ -22,11 +22,17 @@ export class WorkspaceDrawer extends React.Component {
this.props.onStyleChanged(changedStyle)
}
onSourcesChanged(changedSources) {
const changedStyle = this.props.mapStyle.set('sources', changedSources)
this.props.onStyleChanged(changedStyle)
}
render() {
let workspaceContent = null
if(this.props.workContext === "sources") {
workspaceContent = <SourceList
onSourcesChanged={this.onSourcesChanged.bind(this)}
sources={this.props.mapStyle.get('sources')}
/>
}