From 19e82e5890ba25368fbcf2fef2adb41ea41ed522 Mon Sep 17 00:00:00 2001 From: orangemug Date: Sat, 19 Oct 2019 13:11:29 +0100 Subject: [PATCH] Added support for raw GeoJSON --- src/components/modals/SourcesModal.jsx | 18 ++++++++++--- src/components/sources/SourceTypeEditor.jsx | 29 ++++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/components/modals/SourcesModal.jsx b/src/components/modals/SourcesModal.jsx index eee6c85..06f0aeb 100644 --- a/src/components/modals/SourcesModal.jsx +++ b/src/components/modals/SourcesModal.jsx @@ -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 { + return 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 + { + this.props.onChange({ + ...this.props.source, + data, + }) + }} + /> + + } +} + 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 + case 'geojson_url': return + case 'geojson_json': return case 'tilejson_vector': return case 'tilexyz_vector': return case 'tilejson_raster': return