mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-30 20:40:33 +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'
|
if(source.tiles) return 'tilexyz_vector'
|
||||||
return 'tilejson_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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,10 +113,14 @@ class AddSource extends React.Component {
|
||||||
defaultSource(mode) {
|
defaultSource(mode) {
|
||||||
const source = (this.state || {}).source || {}
|
const source = (this.state || {}).source || {}
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case 'geojson': return {
|
case 'geojson_url': return {
|
||||||
type: 'geojson',
|
type: 'geojson',
|
||||||
data: source.data || 'http://localhost:3000/geojson.json'
|
data: source.data || 'http://localhost:3000/geojson.json'
|
||||||
}
|
}
|
||||||
|
case 'geojson_json': return {
|
||||||
|
type: 'geojson',
|
||||||
|
data: source.data || {}
|
||||||
|
}
|
||||||
case 'tilejson_vector': return {
|
case 'tilejson_vector': return {
|
||||||
type: 'vector',
|
type: 'vector',
|
||||||
url: source.url || 'http://localhost:3000/tilejson.json'
|
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}>
|
<InputBlock label={"Source Type"} doc={latest.source_vector.type.doc}>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
options={[
|
options={[
|
||||||
['geojson', 'GeoJSON'],
|
['geojson_json', 'GeoJSON (JSON)'],
|
||||||
|
['geojson_url', 'GeoJSON (URL)'],
|
||||||
['tilejson_vector', 'Vector (TileJSON URL)'],
|
['tilejson_vector', 'Vector (TileJSON URL)'],
|
||||||
['tilexyz_vector', 'Vector (XYZ URLs)'],
|
['tilexyz_vector', 'Vector (XYZ URLs)'],
|
||||||
['tilejson_raster', 'Raster (TileJSON URL)'],
|
['tilejson_raster', 'Raster (TileJSON URL)'],
|
||||||
|
|
|
@ -5,6 +5,7 @@ import InputBlock from '../inputs/InputBlock'
|
||||||
import StringInput from '../inputs/StringInput'
|
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'
|
||||||
|
import JSONEditor from '../layers/JSONEditor'
|
||||||
|
|
||||||
|
|
||||||
class TileJSONSourceEditor extends React.Component {
|
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 = {
|
static propTypes = {
|
||||||
source: PropTypes.object.isRequired,
|
source: PropTypes.object.isRequired,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <InputBlock label={"GeoJSON Data"} doc={latest.source_geojson.data.doc}>
|
return <InputBlock label={"GeoJSON URL"} doc={latest.source_geojson.data.doc}>
|
||||||
<StringInput
|
<StringInput
|
||||||
value={this.props.source.data}
|
value={this.props.source.data}
|
||||||
onChange={data => this.props.onChange({
|
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 {
|
class SourceTypeEditor extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
mode: PropTypes.string.isRequired,
|
mode: PropTypes.string.isRequired,
|
||||||
|
@ -118,7 +140,8 @@ class SourceTypeEditor extends React.Component {
|
||||||
onChange: this.props.onChange,
|
onChange: this.props.onChange,
|
||||||
}
|
}
|
||||||
switch(this.props.mode) {
|
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 'tilejson_vector': return <TileJSONSourceEditor {...commonProps} />
|
||||||
case 'tilexyz_vector': return <TileURLSourceEditor {...commonProps} />
|
case 'tilexyz_vector': return <TileURLSourceEditor {...commonProps} />
|
||||||
case 'tilejson_raster': return <TileJSONSourceEditor {...commonProps} />
|
case 'tilejson_raster': return <TileJSONSourceEditor {...commonProps} />
|
||||||
|
|
Loading…
Reference in a new issue