Skip to content

Commit

Permalink
[mapbox] fix viewport alterations (#3293)
Browse files Browse the repository at this point in the history
* [mapbox] fix viewport alterations

Since explorev2 it appears that altering the viewport hasn't been
changing the controls as it used to. This PR addresses it.

* lint
  • Loading branch information
mistercrunch authored Aug 16, 2017
1 parent d1d1c49 commit ccf505a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ class ChartContainer extends React.PureComponent {
const mockSlice = this.getMockedSliceObject();
this.setState({ mockSlice });
try {
visMap[this.props.viz_type](mockSlice, this.props.queryResponse);
const viz = visMap[this.props.viz_type];
viz(mockSlice, this.props.queryResponse, this.props.actions.setControlValue);
} catch (e) {
this.props.actions.chartRenderingFailed(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ const defaultProps = {
export default class TextControl extends React.Component {
constructor(props) {
super(props);
const value = props.value ? props.value.toString() : '';
this.state = { value };
this.onChange = this.onChange.bind(this);
}
onChange(event) {
let value = event.target.value || '';
this.setState({ value });

// Validation & casting
const errors = [];
Expand All @@ -58,6 +55,7 @@ export default class TextControl extends React.Component {
this.props.onChange(value, errors);
}
render() {
const value = this.props.value ? this.props.value.toString() : '';
return (
<div>
<ControlHeader {...this.props} />
Expand All @@ -66,7 +64,7 @@ export default class TextControl extends React.Component {
type="text"
placeholder=""
onChange={this.onChange}
value={this.state.value}
value={value}
/>
</FormGroup>
</div>
Expand Down
20 changes: 10 additions & 10 deletions superset/assets/visualizations/mapbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ScatterPlotOverlay from 'react-map-gl/dist/overlays/scatterplot.react';
import Immutable from 'immutable';
import supercluster from 'supercluster';
import ViewportMercator from 'viewport-mercator-project';

import {
kmToPixels,
rgbLuminance,
Expand All @@ -17,8 +18,9 @@ import {
DEFAULT_LATITUDE,
DEFAULT_ZOOM,
} from '../utils/common';
import './mapbox.css';

require('./mapbox.css');
const NOOP = () => {};

class ScatterPlotGlowOverlay extends ScatterPlotOverlay {
drawText(ctx, pixel, options = {}) {
Expand Down Expand Up @@ -201,9 +203,10 @@ class MapboxViz extends React.Component {
}

onChangeViewport(viewport) {
this.setState({
viewport,
});
this.setState({ viewport });
this.props.setControlValue('viewport_longitude', viewport.longitude);
this.props.setControlValue('viewport_latitude', viewport.latitude);
this.props.setControlValue('viewport_zoom', viewport.zoom);
}

render() {
Expand All @@ -220,11 +223,6 @@ class MapboxViz extends React.Component {
const clusters = this.props.clusterer.getClusters(bbox, Math.round(this.state.viewport.zoom));
const isDragging = this.state.viewport.isDragging === undefined ? false :
this.state.viewport.isDragging;

d3.select('#viewport_longitude').attr('value', this.state.viewport.longitude);
d3.select('#viewport_latitude').attr('value', this.state.viewport.latitude);
d3.select('#viewport_zoom').attr('value', this.state.viewport.zoom);

return (
<MapGL
{...this.state.viewport}
Expand Down Expand Up @@ -259,6 +257,7 @@ class MapboxViz extends React.Component {
MapboxViz.propTypes = {
aggregatorName: PropTypes.string,
clusterer: PropTypes.object,
setControlValue: PropTypes.func,
globalOpacity: PropTypes.number,
mapStyle: PropTypes.string,
mapboxApiKey: PropTypes.string,
Expand All @@ -273,7 +272,7 @@ MapboxViz.propTypes = {
viewportZoom: PropTypes.number,
};

function mapbox(slice, json) {
function mapbox(slice, json, setControlValue) {
const div = d3.select(slice.selector);
const DEFAULT_POINT_RADIUS = 60;
const DEFAULT_MAX_ZOOM = 16;
Expand Down Expand Up @@ -331,6 +330,7 @@ function mapbox(slice, json) {
clusterer={clusterer}
pointRadius={DEFAULT_POINT_RADIUS}
aggregatorName={aggName}
setControlValue={setControlValue || NOOP}
/>,
div.node(),
);
Expand Down

0 comments on commit ccf505a

Please sign in to comment.