2016-12-21 16:11:08 +01:00
|
|
|
import React from 'react'
|
|
|
|
import Modal from './Modal'
|
|
|
|
import Heading from '../Heading'
|
|
|
|
import InputBlock from '../inputs/InputBlock'
|
|
|
|
import StringInput from '../inputs/StringInput'
|
|
|
|
import publicSources from '../../config/tilesets.json'
|
|
|
|
import colors from '../../config/colors'
|
2016-12-21 16:50:34 +01:00
|
|
|
import { margins, fontSizes } from '../../config/scales'
|
|
|
|
|
|
|
|
import AddIcon from 'react-icons/lib/md/add-circle-outline'
|
2016-12-21 16:11:08 +01:00
|
|
|
|
|
|
|
class PublicSource extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
id: React.PropTypes.string.isRequired,
|
|
|
|
type: React.PropTypes.string.isRequired,
|
|
|
|
title: React.PropTypes.string.isRequired,
|
|
|
|
description: React.PropTypes.string.isRequired,
|
|
|
|
onSelect: React.PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <div style={{
|
|
|
|
verticalAlign: 'top',
|
|
|
|
marginTop: margins[2],
|
|
|
|
marginRight: margins[2],
|
2016-12-21 16:50:34 +01:00
|
|
|
backgroundColor: colors.gray,
|
2016-12-21 16:11:08 +01:00
|
|
|
display: 'inline-block',
|
|
|
|
width: 240,
|
2016-12-21 16:50:34 +01:00
|
|
|
fontSize: fontSizes[4],
|
|
|
|
color: colors.lowgray,
|
2016-12-21 16:11:08 +01:00
|
|
|
}}>
|
|
|
|
<div style={{
|
2016-12-21 16:50:34 +01:00
|
|
|
padding: margins[2],
|
2016-12-21 16:11:08 +01:00
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row',
|
|
|
|
}}>
|
2016-12-21 16:50:34 +01:00
|
|
|
<div>
|
|
|
|
<span style={{fontWeight: 700}}>{this.props.title}</span><br/>
|
|
|
|
<span style={{fontSize: fontSizes[5]}}>{this.props.id}</span>
|
|
|
|
</div>
|
2016-12-21 16:11:08 +01:00
|
|
|
<span style={{flexGrow: 1}} />
|
2016-12-21 16:50:34 +01:00
|
|
|
<a style={{
|
|
|
|
display: 'table',
|
|
|
|
cursor: 'pointer',
|
|
|
|
backgroundColor: colors.midgray,
|
|
|
|
color: colors.lowgray,
|
|
|
|
padding: margins[1],
|
|
|
|
borderRadius: 2,
|
|
|
|
}}>
|
|
|
|
Add
|
|
|
|
</a>
|
2016-12-21 16:11:08 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SourceEditor extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
sourceId: React.PropTypes.string.isRequired,
|
|
|
|
source: React.PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-12-21 16:50:34 +01:00
|
|
|
const inputProps = { }
|
2016-12-21 16:11:08 +01:00
|
|
|
return <div style={{
|
|
|
|
}}>
|
|
|
|
<InputBlock label={"Source ID"}>
|
|
|
|
<StringInput {...inputProps}
|
|
|
|
value={this.props.sourceId}
|
|
|
|
/>
|
|
|
|
</InputBlock>
|
|
|
|
<InputBlock label={"Source URL"}>
|
|
|
|
<StringInput {...inputProps}
|
|
|
|
value={this.props.source.url}
|
|
|
|
/>
|
|
|
|
</InputBlock>
|
|
|
|
<InputBlock label={"Source Type"}>
|
|
|
|
<StringInput {...inputProps}
|
|
|
|
value={this.props.source.type}
|
|
|
|
/>
|
|
|
|
</InputBlock>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SourcesModal extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
mapStyle: React.PropTypes.object.isRequired,
|
|
|
|
isOpen: React.PropTypes.bool.isRequired,
|
|
|
|
toggle: React.PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const activeSources = Object.keys(this.props.mapStyle.sources).map(sourceId => {
|
|
|
|
const source = this.props.mapStyle.sources[sourceId]
|
|
|
|
return <SourceEditor sourceId={sourceId} source={source} />
|
|
|
|
})
|
|
|
|
|
|
|
|
const tilesetOptions = publicSources.map(tileset => {
|
|
|
|
return <PublicSource
|
|
|
|
id={tileset.id}
|
|
|
|
type={tileset.type}
|
|
|
|
title={tileset.title}
|
|
|
|
description={tileset.description}
|
|
|
|
/>
|
|
|
|
})
|
|
|
|
|
2016-12-21 16:50:34 +01:00
|
|
|
const inputProps = { }
|
2016-12-21 16:11:08 +01:00
|
|
|
return <Modal
|
|
|
|
isOpen={this.props.isOpen}
|
|
|
|
toggleOpen={this.props.toggle}
|
|
|
|
title={'Sources'}
|
|
|
|
>
|
|
|
|
<Heading level={4}>Active Sources</Heading>
|
|
|
|
{activeSources}
|
|
|
|
|
|
|
|
<Heading level={4}>Add New Source</Heading>
|
|
|
|
<InputBlock label={"TileJSON URL"}>
|
|
|
|
<StringInput {...inputProps} />
|
|
|
|
</InputBlock>
|
|
|
|
<Heading level={4}>Choose Public Source</Heading>
|
2016-12-21 16:50:34 +01:00
|
|
|
<p style={{color: colors.lowgray, fontSize: fontSizes[5]}}>Add one of the publicly availble sources to your style.</p>
|
2016-12-21 16:11:08 +01:00
|
|
|
<div style={{maxwidth: 500}}>
|
|
|
|
{tilesetOptions}
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SourcesModal
|