Files
superset2/superset/assets/visualizations/deckgl/layers/path.jsx
Maxime Beauchemin e0bbb0c77e [geo] introduce "Auto Zoom" control (#4389)
* [geo] introduce "Auto Zoom" control

On geospatial visualization, checking the "Auto Zoom" control makes it
such that the viewport is fitted to the data upon rendering the chart.

For dashboards with region filters, the map should jump to the right
position.

Eventually we should enhance this to fly and ease to the position in an
animated way.

* Added TODO notes
2018-02-13 11:10:15 -08:00

72 lines
1.6 KiB
JavaScript

import React from 'react';
import ReactDOM from 'react-dom';
import { PathLayer } from 'deck.gl';
import DeckGLContainer from './../DeckGLContainer';
import * as common from './common';
import sandboxedEval from '../../../javascripts/modules/sandbox';
function getLayer(formData, payload, slice) {
const fd = formData;
const c = fd.color_picker;
const fixedColor = [c.r, c.g, c.b, 255 * c.a];
let data = payload.data.features.map(feature => ({
...feature,
path: feature.path,
width: fd.line_width,
color: fixedColor,
}));
if (fd.js_data_mutator) {
const jsFnMutator = sandboxedEval(fd.js_data_mutator);
data = jsFnMutator(data);
}
return new PathLayer({
id: `path-layer-${fd.slice_id}`,
data,
rounded: true,
widthScale: 1,
...common.commonLayerProps(fd, slice),
});
}
function getPoints(data) {
let points = [];
data.forEach((d) => {
points = points.concat(d.path);
});
return points;
}
function deckPath(slice, payload, setControlValue) {
const layer = getLayer(slice.formData, payload, slice);
let viewport = {
...slice.formData.viewport,
width: slice.width(),
height: slice.height(),
};
if (slice.formData.autozoom) {
viewport = common.fitViewport(viewport, getPoints(payload.data.features));
}
ReactDOM.render(
<DeckGLContainer
mapboxApiAccessToken={payload.data.mapboxApiKey}
viewport={viewport}
layers={[layer]}
mapStyle={slice.formData.mapbox_style}
setControlValue={setControlValue}
/>,
document.getElementById(slice.containerId),
);
}
module.exports = {
default: deckPath,
getLayer,
};