forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[geo] Added DeckGL GeoJson layer (apache#4097)
* added deckgl geojson layer * linting * fixed comments * addressed comments * added override with controls.color_picker > 0 * set var properly * set colors if property doesnt exist at all * refacator on property mapping
- Loading branch information
1 parent
ebcf3e9
commit d5e3201
Showing
9 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { GeoJsonLayer } from 'deck.gl'; | ||
import { hexToRGB } from '../../javascripts/modules/colors'; | ||
|
||
import DeckGLContainer from './DeckGLContainer'; | ||
|
||
const propertyMap = { | ||
fillColor: 'fillColor', | ||
color: 'fillColor', | ||
fill: 'fillColor', | ||
'fill-color': 'fillColor', | ||
strokeColor: 'strokeColor', | ||
'stroke-color': 'strokeColor', | ||
'stroke-width': 'strokeWidth', | ||
}; | ||
|
||
const convertGeoJsonColorProps = (p, colors) => { | ||
const obj = Object.assign(...Object.keys(p).map(k => ({ | ||
[(propertyMap[k]) ? propertyMap[k] : k]: p[k] }))); | ||
|
||
return { | ||
...obj, | ||
fillColor: (colors.fillColor[3] !== 0) ? colors.fillColor : hexToRGB(obj.fillColor), | ||
strokeColor: (colors.strokeColor[3] !== 0) ? colors.strokeColor : hexToRGB(obj.strokeColor), | ||
}; | ||
}; | ||
|
||
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: convertGeoJsonColorProps( | ||
d.properties, { | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters