-
Notifications
You must be signed in to change notification settings - Fork 17.9k
[geo] Added DeckGL GeoJson layer #4097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
475c4d1
d72f067
cf8f474
e012d22
12a7164
1214022
b782166
1f90bbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ const timeColumnOption = { | |
| verbose_name: 'Time', | ||
| column_name: '__timestamp', | ||
| description: t( | ||
| 'A reference to the [Time] configuration, taking granularity into ' + | ||
| 'A reference to the [Time] configuration, taking granularity into ' + | ||
| 'account'), | ||
| }; | ||
| const sortAxisChoices = [ | ||
|
|
@@ -143,6 +143,22 @@ export const controls = { | |
| renderTrigger: true, | ||
| }, | ||
|
|
||
| fill_color_picker: { | ||
| label: t('Fill Color'), | ||
| description: t('Use to set fill color of geojson'), | ||
| type: 'ColorPickerControl', | ||
| default: colorPrimary, | ||
| renderTrigger: true, | ||
| }, | ||
|
|
||
| stroke_color_picker: { | ||
| label: t('Stroke Color'), | ||
| description: t('Use to set stroke color of geojson'), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| type: 'ColorPickerControl', | ||
| default: colorPrimary, | ||
| renderTrigger: true, | ||
| }, | ||
|
|
||
| metric: { | ||
| type: 'SelectControl', | ||
| label: t('Metric'), | ||
|
|
@@ -496,6 +512,25 @@ export const controls = { | |
| }), | ||
| }, | ||
|
|
||
| geojson: { | ||
| type: 'SelectControl', | ||
| label: t('GeoJson Column'), | ||
| validators: [v.nonEmpty], | ||
| description: t('Select the geojson column'), | ||
| mapStateToProps: state => ({ | ||
| choices: (state.datasource) ? state.datasource.all_cols : [], | ||
| }), | ||
| }, | ||
|
|
||
| point_radius_scale: { | ||
| type: 'SelectControl', | ||
| freeForm: true, | ||
| label: t('Point Radius Scale'), | ||
| validators: [v.integer], | ||
| default: null, | ||
| choices: formatSelectOptions([0, 100, 200, 300, 500]), | ||
| }, | ||
|
|
||
| all_columns_x: { | ||
| type: 'SelectControl', | ||
| label: 'X', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -455,6 +455,35 @@ export const visTypes = { | |
| }, | ||
| }, | ||
|
|
||
| deck_geojson: { | ||
| label: t('Deck.gl - geoJson'), | ||
| requiresTime: true, | ||
| controlPanelSections: [ | ||
| { | ||
| label: t('Query'), | ||
| expanded: true, | ||
| controlSetRows: [ | ||
| ['geojson'], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you can fit those 2 controls on the same row here |
||
| ['row_limit'], | ||
| ], | ||
| }, | ||
| { | ||
| label: t('Map'), | ||
| controlSetRows: [ | ||
| ['mapbox_style', 'viewport'], | ||
| ], | ||
| }, | ||
| { | ||
| label: t('GeoJson Settings'), | ||
| controlSetRows: [ | ||
| ['fill_color_picker', null], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fit 2 color pickers on one row |
||
| ['stroke_color_picker', null], | ||
| ['point_radius_scale', null], | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| deck_scatter: { | ||
| label: t('Deck.gl - Scatter plot'), | ||
| requiresTime: true, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import { GeoJsonLayer } from 'deck.gl'; | ||
|
|
||
| import DeckGLContainer from './DeckGLContainer'; | ||
|
|
||
|
|
||
| function DeckGeoJsonLayer(slice, payload, setControlValue) { | ||
| const fd = slice.formData; | ||
| const fc = fd.fill_color_picker; | ||
| const sc = fd.stroke_color_picker; | ||
| const data = payload.data.geojson.features.map(d => ({ | ||
| ...d, | ||
| properties: { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will fully override properties ind |
||
| fillColor: [fc.r, fc.g, fc.b, 255 * fc.a], | ||
| strokeColor: [sc.r, sc.g, sc.b, 255 * sc.a], | ||
| }, | ||
| })); | ||
|
|
||
| const layer = new GeoJsonLayer({ | ||
| id: 'geojson-layer', | ||
| data, | ||
| filled: true, | ||
| stroked: false, | ||
| extruded: true, | ||
| pointRadiusScale: fd.point_radius_scale, | ||
| }); | ||
|
|
||
| const viewport = { | ||
| ...fd.viewport, | ||
| width: slice.width(), | ||
| height: slice.height(), | ||
| }; | ||
| ReactDOM.render( | ||
| <DeckGLContainer | ||
| mapboxApiAccessToken={payload.data.mapboxApiKey} | ||
| viewport={viewport} | ||
| layers={[layer]} | ||
| mapStyle={fd.mapbox_style} | ||
| setControlValue={setControlValue} | ||
| />, | ||
| document.getElementById(slice.containerId), | ||
| ); | ||
| } | ||
| module.exports = DeckGeoJsonLayer; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1522,6 +1522,37 @@ def load_flights(): | |
| obj.fetch_metadata() | ||
|
|
||
|
|
||
| def load_paris_iris_geojson(): | ||
| tbl_name = 'paris_iris_mapping' | ||
|
|
||
| with gzip.open(os.path.join(DATA_FOLDER, 'paris_iris.json.gz')) as f: | ||
| df = pd.read_json(f) | ||
| df['features'] = df.features.map(json.dumps) | ||
|
|
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one empty line is enough |
||
| df.to_sql( | ||
| tbl_name, | ||
| db.engine, | ||
| if_exists='replace', | ||
| chunksize=500, | ||
| dtype={ | ||
| 'color': String(255), | ||
| 'name': String(255), | ||
| 'features': Text, | ||
| 'type': Text, | ||
| }, | ||
| index=False) | ||
| print("Creating table {} reference".format(tbl_name)) | ||
| tbl = db.session.query(TBL).filter_by(table_name=tbl_name).first() | ||
| if not tbl: | ||
| tbl = TBL(table_name=tbl_name) | ||
| tbl.description = "Map of Paris" | ||
| tbl.database = get_or_create_main_db() | ||
| db.session.merge(tbl) | ||
| db.session.commit() | ||
| tbl.fetch_metadata() | ||
|
|
||
|
|
||
| def load_bart_lines(): | ||
| tbl_name = 'bart_lines' | ||
| with gzip.open(os.path.join(DATA_FOLDER, 'bart-lines.json.gz')) as f: | ||
|
|
@@ -1550,3 +1581,6 @@ def load_bart_lines(): | |
| db.session.merge(tbl) | ||
| db.session.commit() | ||
| tbl.fetch_metadata() | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.