mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-15 09:11:18 +01:00
DRY up the code.
This commit is contained in:
parent
4f19f6a08c
commit
79b251d8b9
1 changed files with 26 additions and 105 deletions
|
@ -6,100 +6,6 @@ import StringInput from '../inputs/StringInput'
|
||||||
import NumberInput from '../inputs/NumberInput'
|
import NumberInput from '../inputs/NumberInput'
|
||||||
import SelectInput from '../inputs/SelectInput'
|
import SelectInput from '../inputs/SelectInput'
|
||||||
|
|
||||||
class DemJSONSourceEditor extends React.Component {
|
|
||||||
static propTypes = {
|
|
||||||
source: PropTypes.object.isRequired,
|
|
||||||
onChange: PropTypes.func.isRequired,
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return <div>
|
|
||||||
<InputBlock label={"Raster DEM URL"} doc={styleSpec.latest.source_raster_dem.url.doc}>
|
|
||||||
<StringInput
|
|
||||||
value={this.props.source.url}
|
|
||||||
onChange={url => this.props.onChange({
|
|
||||||
...this.props.source,
|
|
||||||
url: url
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
</InputBlock>
|
|
||||||
<InputBlock label={"Encoding"} doc={styleSpec.latest.source_raster_dem.encoding.doc}>
|
|
||||||
<SelectInput
|
|
||||||
options={Object.keys(styleSpec.latest.source_raster_dem.encoding.values)}
|
|
||||||
onChange={encoding => this.props.onChange({
|
|
||||||
...this.props.source,
|
|
||||||
encoding: encoding
|
|
||||||
})}
|
|
||||||
value={this.props.source.encoding || styleSpec.latest.source_raster_dem.encoding.default}
|
|
||||||
/>
|
|
||||||
</InputBlock>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DemURLSourceEditor extends React.Component {
|
|
||||||
static propTypes = {
|
|
||||||
source: PropTypes.object.isRequired,
|
|
||||||
onChange: PropTypes.func.isRequired,
|
|
||||||
}
|
|
||||||
|
|
||||||
changeTileUrl(idx, value) {
|
|
||||||
const tiles = this.props.source.tiles.slice(0)
|
|
||||||
tiles[idx] = value
|
|
||||||
this.props.onChange({
|
|
||||||
...this.props.source,
|
|
||||||
tiles: tiles
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
renderTileUrls() {
|
|
||||||
const prefix = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th']
|
|
||||||
const tiles = this.props.source.tiles || []
|
|
||||||
return tiles.map((tileUrl, tileIndex) => {
|
|
||||||
return <InputBlock key={tileIndex} label={prefix[tileIndex] + " Tile URL"} doc={styleSpec.latest.source_vector.tiles.doc}>
|
|
||||||
<StringInput
|
|
||||||
value={tileUrl}
|
|
||||||
onChange={this.changeTileUrl.bind(this, tileIndex)}
|
|
||||||
/>
|
|
||||||
</InputBlock>
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return <div>
|
|
||||||
{this.renderTileUrls()}
|
|
||||||
<InputBlock label={"Min Zoom"} doc={styleSpec.latest.source_vector.minzoom.doc}>
|
|
||||||
<NumberInput
|
|
||||||
value={this.props.source.minzoom || 0}
|
|
||||||
onChange={minzoom => this.props.onChange({
|
|
||||||
...this.props.source,
|
|
||||||
minzoom: minzoom
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
</InputBlock>
|
|
||||||
<InputBlock label={"Max Zoom"} doc={styleSpec.latest.source_vector.maxzoom.doc}>
|
|
||||||
<NumberInput
|
|
||||||
value={this.props.source.maxzoom || 22}
|
|
||||||
onChange={maxzoom => this.props.onChange({
|
|
||||||
...this.props.source,
|
|
||||||
maxzoom: maxzoom
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
</InputBlock>
|
|
||||||
<InputBlock label={"Encoding"} doc={styleSpec.latest.source_raster_dem.encoding.doc}>
|
|
||||||
<SelectInput
|
|
||||||
options={Object.keys(styleSpec.latest.source_raster_dem.encoding.values)}
|
|
||||||
onChange={encoding => this.props.onChange({
|
|
||||||
...this.props.source,
|
|
||||||
encoding: encoding
|
|
||||||
})}
|
|
||||||
value={this.props.source.encoding || styleSpec.latest.source_raster_dem.encoding.default}
|
|
||||||
/>
|
|
||||||
</InputBlock>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TileJSONSourceEditor extends React.Component {
|
class TileJSONSourceEditor extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
@ -108,7 +14,8 @@ class TileJSONSourceEditor extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <InputBlock label={"TileJSON URL"} doc={styleSpec.latest.source_vector.url.doc}>
|
return <div>
|
||||||
|
<InputBlock label={"TileJSON URL"} doc={styleSpec.latest.source_vector.url.doc}>
|
||||||
<StringInput
|
<StringInput
|
||||||
value={this.props.source.url}
|
value={this.props.source.url}
|
||||||
onChange={url => this.props.onChange({
|
onChange={url => this.props.onChange({
|
||||||
|
@ -117,6 +24,8 @@ class TileJSONSourceEditor extends React.Component {
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</InputBlock>
|
</InputBlock>
|
||||||
|
{this.props.children}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +78,7 @@ class TileURLSourceEditor extends React.Component {
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</InputBlock>
|
</InputBlock>
|
||||||
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -211,8 +121,19 @@ class SourceTypeEditor extends React.Component {
|
||||||
case 'tilexyz_vector': return <TileURLSourceEditor {...commonProps} />
|
case 'tilexyz_vector': return <TileURLSourceEditor {...commonProps} />
|
||||||
case 'tilejson_raster': return <TileJSONSourceEditor {...commonProps} />
|
case 'tilejson_raster': return <TileJSONSourceEditor {...commonProps} />
|
||||||
case 'tilexyz_raster': return <TileURLSourceEditor {...commonProps} />
|
case 'tilexyz_raster': return <TileURLSourceEditor {...commonProps} />
|
||||||
case 'tilejson_raster-dem': return <DemJSONSourceEditor {...commonProps} />
|
case 'tilejson_raster-dem': return <TileJSONSourceEditor {...commonProps} />
|
||||||
case 'tilexyz_raster-dem': return <DemURLSourceEditor {...commonProps} />
|
case 'tilexyz_raster-dem': return <TileURLSourceEditor {...commonProps}>
|
||||||
|
<InputBlock label={"Encoding"} doc={styleSpec.latest.source_raster_dem.encoding.doc}>
|
||||||
|
<SelectInput
|
||||||
|
options={Object.keys(styleSpec.latest.source_raster_dem.encoding.values)}
|
||||||
|
onChange={encoding => this.props.onChange({
|
||||||
|
...this.props.source,
|
||||||
|
encoding: encoding
|
||||||
|
})}
|
||||||
|
value={this.props.source.encoding || styleSpec.latest.source_raster_dem.encoding.default}
|
||||||
|
/>
|
||||||
|
</InputBlock>
|
||||||
|
</TileURLSourceEditor>
|
||||||
default: return null
|
default: return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue