Skip to content

Commit

Permalink
Add support to change source TileJSON url
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmartinelli committed Sep 21, 2016
1 parent 604e762 commit e524765
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sources/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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>
Expand All @@ -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) {
Expand All @@ -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}
/>
}
Expand Down
7 changes: 7 additions & 0 deletions src/sources/list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ 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) {
super(props)
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()

Expand Down
6 changes: 6 additions & 0 deletions src/workspace.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
/>
}
Expand Down

0 comments on commit e524765

Please sign in to comment.