mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 15:21:20 +01:00
Added support for raw GeoJSON
This commit is contained in:
parent
201ecac156
commit
19e82e5890
2 changed files with 41 additions and 6 deletions
|
@ -52,7 +52,14 @@ function editorMode(source) {
|
|||
if(source.tiles) return 'tilexyz_vector'
|
||||
return 'tilejson_vector'
|
||||
}
|
||||
if(source.type === 'geojson') return 'geojson'
|
||||
if(source.type === 'geojson') {
|
||||
if (typeof(source.data) === "string") {
|
||||
return 'geojson_url';
|
||||
}
|
||||
else {
|
||||
return 'geojson_json';
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
@ -106,10 +113,14 @@ class AddSource extends React.Component {
|
|||
defaultSource(mode) {
|
||||
const source = (this.state || {}).source || {}
|
||||
switch(mode) {
|
||||
case 'geojson': return {
|
||||
case 'geojson_url': return {
|
||||
type: 'geojson',
|
||||
data: source.data || 'http://localhost:3000/geojson.json'
|
||||
}
|
||||
case 'geojson_json': return {
|
||||
type: 'geojson',
|
||||
data: source.data || {}
|
||||
}
|
||||
case 'tilejson_vector': return {
|
||||
type: 'vector',
|
||||
url: source.url || 'http://localhost:3000/tilejson.json'
|
||||
|
@ -155,7 +166,8 @@ class AddSource extends React.Component {
|
|||
<InputBlock label={"Source Type"} doc={latest.source_vector.type.doc}>
|
||||
<SelectInput
|
||||
options={[
|
||||
['geojson', 'GeoJSON'],
|
||||
['geojson_json', 'GeoJSON (JSON)'],
|
||||
['geojson_url', 'GeoJSON (URL)'],
|
||||
['tilejson_vector', 'Vector (TileJSON URL)'],
|
||||
['tilexyz_vector', 'Vector (XYZ URLs)'],
|
||||
['tilejson_raster', 'Raster (TileJSON URL)'],
|
||||
|
|
|
@ -5,6 +5,7 @@ import InputBlock from '../inputs/InputBlock'
|
|||
import StringInput from '../inputs/StringInput'
|
||||
import NumberInput from '../inputs/NumberInput'
|
||||
import SelectInput from '../inputs/SelectInput'
|
||||
import JSONEditor from '../layers/JSONEditor'
|
||||
|
||||
|
||||
class TileJSONSourceEditor extends React.Component {
|
||||
|
@ -86,14 +87,14 @@ class TileURLSourceEditor extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
class GeoJSONSourceEditor extends React.Component {
|
||||
class GeoJSONSourceUrlEditor extends React.Component {
|
||||
static propTypes = {
|
||||
source: PropTypes.object.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
render() {
|
||||
return <InputBlock label={"GeoJSON Data"} doc={latest.source_geojson.data.doc}>
|
||||
return <InputBlock label={"GeoJSON URL"} doc={latest.source_geojson.data.doc}>
|
||||
<StringInput
|
||||
value={this.props.source.data}
|
||||
onChange={data => this.props.onChange({
|
||||
|
@ -105,6 +106,27 @@ class GeoJSONSourceEditor extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
class GeoJSONSourceJSONEditor extends React.Component {
|
||||
static propTypes = {
|
||||
source: PropTypes.object.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
render() {
|
||||
return <InputBlock label={"GeoJSON"} doc={latest.source_geojson.data.doc}>
|
||||
<JSONEditor
|
||||
layer={this.props.source.data}
|
||||
onChange={data => {
|
||||
this.props.onChange({
|
||||
...this.props.source,
|
||||
data,
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</InputBlock>
|
||||
}
|
||||
}
|
||||
|
||||
class SourceTypeEditor extends React.Component {
|
||||
static propTypes = {
|
||||
mode: PropTypes.string.isRequired,
|
||||
|
@ -118,7 +140,8 @@ class SourceTypeEditor extends React.Component {
|
|||
onChange: this.props.onChange,
|
||||
}
|
||||
switch(this.props.mode) {
|
||||
case 'geojson': return <GeoJSONSourceEditor {...commonProps} />
|
||||
case 'geojson_url': return <GeoJSONSourceUrlEditor {...commonProps} />
|
||||
case 'geojson_json': return <GeoJSONSourceJSONEditor {...commonProps} />
|
||||
case 'tilejson_vector': return <TileJSONSourceEditor {...commonProps} />
|
||||
case 'tilexyz_vector': return <TileURLSourceEditor {...commonProps} />
|
||||
case 'tilejson_raster': return <TileJSONSourceEditor {...commonProps} />
|
||||
|
|
Loading…
Reference in a new issue