Skip to content

Commit

Permalink
[mapbox] fix viewport alterations
Browse files Browse the repository at this point in the history
Since explorev2 it appears that altering the viewport hasn't been
changing the controls as it used to. This PR addresses it.
  • Loading branch information
mistercrunch committed Aug 15, 2017
1 parent 9c6248f commit 9c7257e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class ChartContainer extends React.PureComponent {
const mockSlice = this.getMockedSliceObject();
this.setState({ mockSlice });
try {
visMap[this.props.viz_type](mockSlice, this.props.queryResponse);
visMap[this.props.viz_type](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
19 changes: 9 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 @@ -273,7 +271,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 +329,7 @@ function mapbox(slice, json) {
clusterer={clusterer}
pointRadius={DEFAULT_POINT_RADIUS}
aggregatorName={aggName}
setControlValue={setControlValue || NOOP}
/>,
div.node(),
);
Expand Down

0 comments on commit 9c7257e

Please sign in to comment.