mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-27 08:15:24 +01:00
Support different source types
This commit is contained in:
parent
29bf0c2b61
commit
044cdf5332
3 changed files with 130 additions and 22 deletions
|
@ -113,8 +113,8 @@ export default class Toolbar extends React.Component {
|
|||
<SourcesModal
|
||||
mapStyle={this.props.mapStyle}
|
||||
onStyleChanged={this.props.onStyleChanged}
|
||||
isOpen={this.state.openSourcesModal}
|
||||
//isOpen={true}
|
||||
//isOpen={this.state.openSourcesModal}
|
||||
isOpen={true}
|
||||
toggle={() => this.toggleSources.bind(this)}
|
||||
/>
|
||||
<ToolbarAction style={{
|
||||
|
|
|
@ -3,6 +3,8 @@ import Modal from './Modal'
|
|||
import Heading from '../Heading'
|
||||
import InputBlock from '../inputs/InputBlock'
|
||||
import StringInput from '../inputs/StringInput'
|
||||
import SourceTypeEditor from '../sources/SourceTypeEditor'
|
||||
|
||||
import publicSources from '../../config/tilesets.json'
|
||||
import colors from '../../config/colors'
|
||||
import { margins, fontSizes } from '../../config/scales'
|
||||
|
@ -36,11 +38,10 @@ class PublicSource extends React.Component {
|
|||
}}>
|
||||
<div>
|
||||
<span style={{fontWeight: 700}}>{this.props.title}</span><br/>
|
||||
<span style={{fontSize: fontSizes[5]}}>{this.props.id}</span>
|
||||
<span style={{fontSize: fontSizes[5]}}>#{this.props.id}</span>
|
||||
</div>
|
||||
<span style={{flexGrow: 1}} />
|
||||
<a style={{
|
||||
display: 'table',
|
||||
cursor: 'pointer',
|
||||
backgroundColor: colors.midgray,
|
||||
color: colors.lowgray,
|
||||
|
@ -54,7 +55,7 @@ class PublicSource extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
class SourceEditor extends React.Component {
|
||||
class SourceEditorLayout extends React.Component {
|
||||
static propTypes = {
|
||||
sourceId: React.PropTypes.string.isRequired,
|
||||
source: React.PropTypes.object.isRequired,
|
||||
|
@ -64,21 +65,34 @@ class SourceEditor extends React.Component {
|
|||
const inputProps = { }
|
||||
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 style={{
|
||||
backgroundColor: colors.gray,
|
||||
color: colors.lowgray,
|
||||
padding: margins[1],
|
||||
display: 'flex',
|
||||
fontSize: fontSizes[4],
|
||||
flexDirection: 'row',
|
||||
}}>
|
||||
<span style={{fontSize: fontSizes[4], lineHeight: 2}}>#{this.props.sourceId}</span>
|
||||
<span style={{flexGrow: 1}} />
|
||||
<a style={{
|
||||
cursor: 'pointer',
|
||||
backgroundColor: colors.midgray,
|
||||
color: colors.lowgray,
|
||||
padding: margins[1],
|
||||
borderRadius: 2,
|
||||
}}>
|
||||
Remove
|
||||
</a>
|
||||
</div>
|
||||
<div style={{
|
||||
borderColor: colors.gray,
|
||||
borderWidth: 2,
|
||||
borderStyle: 'solid',
|
||||
padding: margins[1],
|
||||
}}>
|
||||
<SourceTypeEditor source={this.props.source} />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
@ -94,10 +108,10 @@ class SourcesModal extends React.Component {
|
|||
render() {
|
||||
const activeSources = Object.keys(this.props.mapStyle.sources).map(sourceId => {
|
||||
const source = this.props.mapStyle.sources[sourceId]
|
||||
return <SourceEditor sourceId={sourceId} source={source} />
|
||||
return <SourceEditorLayout sourceId={sourceId} source={source} />
|
||||
})
|
||||
|
||||
const tilesetOptions = publicSources.map(tileset => {
|
||||
const tilesetOptions = publicSources.filter(tileset => !(tileset.id in this.props.mapStyle.sources)).map(tileset => {
|
||||
return <PublicSource
|
||||
id={tileset.id}
|
||||
type={tileset.type}
|
||||
|
|
94
src/components/sources/SourceTypeEditor.jsx
Normal file
94
src/components/sources/SourceTypeEditor.jsx
Normal file
|
@ -0,0 +1,94 @@
|
|||
import React from 'react'
|
||||
import InputBlock from '../inputs/InputBlock'
|
||||
import StringInput from '../inputs/StringInput'
|
||||
|
||||
class TileJSONSourceEditor extends React.Component {
|
||||
static propTypes = {
|
||||
url: React.PropTypes.string.isRequired,
|
||||
}
|
||||
|
||||
render() {
|
||||
return <InputBlock label={"TileJSON URL"}>
|
||||
<StringInput
|
||||
value={this.props.url}
|
||||
/>
|
||||
</InputBlock>
|
||||
}
|
||||
}
|
||||
|
||||
class TileURLSourceEditor extends React.Component {
|
||||
static propTypes = {
|
||||
tiles: React.PropTypes.array.isRequired,
|
||||
minZoom: React.PropTypes.number.isRequired,
|
||||
maxZoom: React.PropTypes.number.isRequired,
|
||||
}
|
||||
|
||||
renderTileUrls() {
|
||||
return this.props.tiles.map((tileUrl, tileIndex) => {
|
||||
<InputBlock key={tileIndex} label={"Tile URL " + tileIndex}>
|
||||
<StringInput
|
||||
value={this.props.data}
|
||||
/>
|
||||
</InputBlock>
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return <div>
|
||||
{this.renderTileUrls()}
|
||||
<InputBlock label={"GeoJSON Data"}>
|
||||
<StringInput
|
||||
value={this.props.data}
|
||||
/>
|
||||
</InputBlock>
|
||||
<InputBlock label={"Min Zoom"}>
|
||||
<StringInput
|
||||
value={this.props.minZoom}
|
||||
/>
|
||||
</InputBlock>
|
||||
<InputBlock label={"Max Zoom"}>
|
||||
<StringInput
|
||||
value={this.props.maxZoom}
|
||||
/>
|
||||
</InputBlock>
|
||||
</div>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class GeoJSONSourceEditor extends React.Component {
|
||||
static propTypes = {
|
||||
data: React.PropTypes.string.isRequired,
|
||||
}
|
||||
|
||||
render() {
|
||||
return <InputBlock label={"GeoJSON Data"}>
|
||||
<StringInput
|
||||
value={this.props.data}
|
||||
/>
|
||||
</InputBlock>
|
||||
}
|
||||
}
|
||||
|
||||
class SourceTypeEditor extends React.Component {
|
||||
static propTypes = {
|
||||
source: React.PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
render() {
|
||||
const source = this.props.source
|
||||
if(source.type === "geojson") {
|
||||
return <GeoJSONSourceEditor data={source.data} />
|
||||
}
|
||||
if(source.type === "vector") {
|
||||
if(source.url) {
|
||||
return <TileJSONSourceEditor url={source.url}/>
|
||||
} else {
|
||||
return <TileURLSourceEditor tiles={source.tiles} minZoom={source.minZoom} maxZoom={source.maxZoom}/>
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export default SourceTypeEditor
|
Loading…
Reference in a new issue