Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Feat] Display mouse coordinate (#550)

Shan Hed57544a52278
diff --git a/src/actions/vis-state-actions.js b/src/actions/vis-state-actions.js
index 41c629915..531d938b9 100644
--- a/src/actions/vis-state-actions.js
+++ b/src/actions/vis-state-actions.js
@@ -371,6 +371,23 @@ export function onMapClick() {
};
}
+/**
+ * Trigger map mouse moveevent, payload would be
+ * React-map-gl PointerEvent
+ * https://uber.github.io/react-map-gl/#/documentation/api-reference/pointer-event
+ *
+ * @memberof visStateActions
+ * @param {Object} evt - PointerEvent
+ * @returns {{type: ActionTypes.MAP_CLICK}}
+ * @public
+ */
+export function onMouseMove(evt) {
+ return {
+ type: ActionTypes.MOUSE_MOVE,
+ evt
+ };
+}
+
/**
* Toggle visibility of a layer in a split map
* @memberof visStateActions
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index 83cea38fc..4a04efacf 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -209,7 +209,8 @@ function KeplerGlFactory(
datasets,
layerData,
hoverInfo,
- clicked
+ clicked,
+ mousePos
} = visState;
const notificationPanelFields = {
@@ -249,6 +250,7 @@ function KeplerGlFactory(
interactionConfig,
hoverInfo,
clicked,
+ mousePos,
toggleMapControl: uiStateActions.toggleMapControl,
onViewStateChange,
uiStateActions,
diff --git a/src/components/map-container.js b/src/components/map-container.js
index 8a86fb392..bd330786c 100644
--- a/src/components/map-container.js
+++ b/src/components/map-container.js
@@ -23,6 +23,7 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types';
import MapboxGLMap from 'react-map-gl';
import DeckGL from 'deck.gl';
+import WebMercatorViewport from 'viewport-mercator-project';
// components
import MapPopoverFactory from 'components/map/map-popover';
@@ -68,6 +69,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
mapState: PropTypes.object.isRequired,
mapStyle: PropTypes.object.isRequired,
mapControls: PropTypes.object.isRequired,
+ mousePos: PropTypes.object.isRequired,
mapboxApiAccessToken: PropTypes.string.isRequired,
toggleMapControl: PropTypes.func.isRequired,
visStateActions: PropTypes.object.isRequired,
@@ -90,9 +92,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
constructor(props) {
super(props);
- this.state = {
- mousePosition: [0, 0]
- };
+
this.previousLayers = {
// [layers.id]: mapboxLayerConfig
};
@@ -117,21 +117,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
});
};
- _onWebGLInitialized = gl => {
- onWebGLInitialized(gl);
- // allow Uint32 indices in building layer
- // gl.getExtension('OES_element_index_uint');
- };
-
- _onMouseMove = evt => {
- const {interactionConfig: {brush}} = this.props;
-
- if (evt.nativeEvent && brush.enabled) {
- this.setState({
- mousePosition: [evt.nativeEvent.offsetX, evt.nativeEvent.offsetY]
- });
- }
- };
+ _onWebGLInitialized = onWebGLInitialized;
_handleMapToggleLayer = layerId => {
const {index: mapIndex = 0, visStateActions} = this.props;
@@ -187,7 +173,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
/* component render functions */
/* eslint-disable complexity */
- _renderObjectLayerPopover() {
+ _renderMapPopover() {
// TODO: move this into reducer so it can be tested
const {
mapState,
@@ -196,60 +182,67 @@ export default function MapContainerFactory(MapPopover, MapControl) {
datasets,
interactionConfig,
layers,
- mapLayers
+ mapLayers,
+ mousePos: {mousePosition, coordinate, pinned}
} = this.props;
- // if clicked something, ignore hover behavior
- const objectInfo = clicked || hoverInfo;
- if (
- !interactionConfig.tooltip.enabled ||
- !objectInfo ||
- !objectInfo.picked
- ) {
- // nothing hovered
+ if (!mousePosition) {
return null;
}
-
- const {lngLat, object, layer: overlay} = objectInfo;
-
- // deckgl layer to kepler-gl layer
- const layer = layers[overlay.props.idx];
+ // if clicked something, ignore hover behavior
+ const objectInfo = clicked || hoverInfo;
+ let layerHoverProp = null;
+ let position = {x: mousePosition[0], y: mousePosition[1]};
if (
- !layer ||
- !layer.config.isVisible ||
- !object ||
- !layer.getHoverData ||
- (mapLayers && !mapLayers[layer.id].isVisible)
+ interactionConfig.tooltip.enabled &&
+ objectInfo &&
+ objectInfo.picked
) {
- // layer is not visible
- return null;
+ // if anything hovered
+ const {object, layer: overlay} = objectInfo;
+
+ // deckgl layer to kepler-gl layer
+ const layer = layers[overlay.props.idx];
+
+ if (
+ layer.config.isVisible &&
+ layer.getHoverData &&
+ (!mapLayers || mapLayers[layer.id].isVisible)
+ ) {
+
+ // if layer is visible and have hovered data
+ const {config: {dataId}} = layer;
+ const {allData, fields} = datasets[dataId];
+ const data = layer.getHoverData(object, allData);
+ const fieldsToShow = interactionConfig.tooltip.config.fieldsToShow[dataId];
+
+ layerHoverProp = {
+ data,
+ fields,
+ fieldsToShow,
+ layer
+ }
+ }
}
- const {config: {dataId}} = layer;
- const {allData, fields} = datasets[dataId];
- const data = layer.getHoverData(object, allData);
-
- // project lnglat to screen so that tooltip follows the object on zoom
- const {viewport} = overlay.context;
- const {x, y} = this._getHoverXY(viewport, lngLat) || objectInfo;
-
- const popoverProps = {
- data,
- fields,
- fieldsToShow: interactionConfig.tooltip.config.fieldsToShow[dataId],
- layer,
- isVisible: true,
- x,
- y,
- freezed: Boolean(clicked),
- onClose: this._onCloseMapPopover,
- mapState
- };
-
+ if (pinned || clicked) {
+ // project lnglat to screen so that tooltip follows the object on zoom
+ const viewport = new WebMercatorViewport(mapState);
+ const lngLat = clicked ? clicked.lngLat : pinned.coordinate;
+ position = this._getHoverXY(viewport, lngLat);
+ }
return (
<div>
- <MapPopover {...popoverProps} />
+ <MapPopover
+ {...position}
+ layerHoverProp={layerHoverProp}
+ coordinate={interactionConfig.coordinate.enabled && ((pinned || {}).coordinate || coordinate)}
+ freezed={Boolean(clicked || pinned)}
+ onClose={this._onCloseMapPopover}
+ mapW={mapState.width}
+ mapH={mapState.height}
+ />
</div>
);
}
@@ -276,9 +269,10 @@ export default function MapContainerFactory(MapPopover, MapControl) {
clicked,
mapLayers,
mapState,
- interactionConfig
+ interactionConfig,
+ mousePos
} = this.props;
- const {mousePosition} = this.state;
+ const {mousePosition} = mousePos;
const layer = layers[idx];
const data = layerData[idx];
@@ -400,7 +394,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {
mapState, mapStyle, mapStateActions, mapLayers, layers, MapComponent,
datasets, mapboxApiAccessToken, mapControls, toggleMapControl
} = this.props;
- const {onMapClick} = mapStateActions;
if (!mapStyle.bottomMapStyle) {
// style not yet loaded
@@ -416,7 +409,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
};
return (
- <StyledMapContainer style={MAP_STYLE.container} onMouseMove={this._onMouseMove}>
+ <StyledMapContainer style={MAP_STYLE.container}>
<MapControl
datasets={datasets}
dragRotate={mapState.dragRotate}
@@ -438,9 +431,9 @@ export default function MapContainerFactory(MapPopover, MapControl) {
key="bottom"
ref={this._setMapboxMap}
mapStyle={mapStyle.bottomMapStyle}
- onClick={onMapClick}
getCursor={this.props.hoverInfo ? () => 'pointer' : undefined}
transitionDuration={TRANSITION_DURATION}
+ onMouseMove={this.props.visStateActions.onMouseMove}
>
{this._renderOverlay()}
{this._renderMapboxOverlays()}
@@ -454,7 +447,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
/>
</div>
)}
- {this._renderObjectLayerPopover()}
+ {this._renderMapPopover()}
</StyledMapContainer>
);
}
diff --git a/src/components/map/coordinate-info.js b/src/components/map/coordinate-info.js
new file mode 100644
index 000000000..fb28e7dcc
--- /dev/null
+++ b/src/components/map/coordinate-info.js
@@ -0,0 +1,55 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React from 'react';
+import {preciseRound} from 'utils/data-utils';
+import {CursorClick} from 'components/common/icons';
+import {StyledLayerName} from './layer-hover-info';
+
+// 6th decimal is worth up to 0.11 m
+// https://gis.stackexchange.com/questions/8650/measuring-accuracy-of-latitude-and-longitude
+const DECIMAL = 6;
+
+const CoordinateInfoFactory = () => {
+ const CoordinateInfo = ({coordinate}) => (
+ <div>
+ <StyledLayerName className="map-popover__layer-name">
+ <CursorClick height="12px" />
+ Coordinate
+ </StyledLayerName>
+ <table>
+ <tbody>
+ <tr className="row">
+ <td className="row__value">
+ {preciseRound(coordinate[1], DECIMAL)},
+ </td>
+ <td className="row__value">
+ {preciseRound(coordinate[0], DECIMAL)}
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ );
+
+ return CoordinateInfo;
+};
+
+export default CoordinateInfoFactory;
diff --git a/src/components/map/layer-hover-info.js b/src/components/map/layer-hover-info.js
new file mode 100644
index 000000000..f2c723e8c
--- /dev/null
+++ b/src/components/map/layer-hover-info.js
@@ -0,0 +1,156 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+import React from 'react';
+import styled from 'styled-components';
+import {CenterFlexbox} from 'components/common/styled-components';
+import {Layers} from 'components/common/icons';
+import {FIELD_DISPLAY_FORMAT} from 'constants/default-settings';
+import PropTypes from 'prop-types';
+
+export const StyledLayerName = styled(CenterFlexbox)`
+ color: ${props => props.theme.textColorHl};
+ font-size: 12px;
+ letter-spacing: 0.43px;
+ text-transform: capitalize;
+ padding-left: 14px;
+ margin-top: 12px;
+
+ svg {
+ margin-right: 4px;
+ }
+`;
+
+const Row = ({name, value, url}) => {
+ // Set 'url' to 'value' if it looks like a url
+ if (!url && value && typeof value === 'string' && value.match(/^http/)) {
+ url = value;
+ }
+
+ const asImg = /<img>/.test(name);
+ return (
+ <tr className="row" key={name}>
+ <td className="row__name">{name}</td>
+ <td className="row__value">
+ {asImg ? (
+ <img src={value} />
+ ) : url ? (
+ <a target="_blank" rel="noopener noreferrer" href={url}>
+ {value}
+ </a>
+ ) : (
+ value
+ )}
+ </td>
+ </tr>
+ );
+};
+
+const EntryInfo = ({fieldsToShow, fields, data}) => (
+ <tbody>
+ {fieldsToShow.map(name => (
+ <EntryInfoRow key={name} name={name} fields={fields} data={data} />
+ ))}
+ </tbody>
+);
+
+const EntryInfoRow = ({name, fields, data}) => {
+ const field = fields.find(f => f.name === name);
+ if (!field) {
+ return null;
+ }
+
+ const valueIdx = field.tableFieldIndex - 1;
+ const format = _getCellFormat(field.type);
+
+ return (
+ <Row name={name} value={format ? format(data[valueIdx]) : data[valueIdx]} />
+ );
+};
+
+const CellInfo = ({data, layer}) => {
+ const {colorField, sizeField} = layer.config;
+
+ return (
+ <tbody>
+ <Row
+ name={'total points'}
+ key="count"
+ value={data.points && data.points.length}
+ />
+ {colorField && layer.visualChannels.color ? (
+ <Row
+ name={layer.getVisualChannelDescription('color').measure}
+ key="color"
+ value={data.colorValue || 'N/A'}
+ />
+ ) : null}
+ {sizeField && layer.visualChannels.size ? (
+ <Row
+ name={layer.getVisualChannelDescription('size').measure}
+ key="size"
+ value={data.elevationValue || 'N/A'}
+ />
+ ) : null}
+ </tbody>
+ );
+};
+
+function _getCellFormat(type) {
+ return FIELD_DISPLAY_FORMAT[type];
+}
+
+const LayerHoverInfoFactory = () => {
+ const LayerHoverInfo = props => {
+ const {data, layer, fieldsToShow} = props;
+
+ if (!data || !layer || !fieldsToShow.length) {
+ return null;
+ }
+
+ return (
+ <div>
+ <StyledLayerName className="map-popover__layer-name">
+ <Layers height="12px" />
+ {props.layer.config.label}
+ </StyledLayerName>
+ <table className="map-popover__table">
+ {props.layer.isAggregated ? (
+ <CellInfo {...props} />
+ ) : (
+ <EntryInfo {...props} />
+ )}
+ </table>
+ </div>
+ );
+ };
+
+ LayerHoverInfo.propTypes = {
+ fields: PropTypes.arrayOf(PropTypes.any),
+ fieldsToShow: PropTypes.arrayOf(PropTypes.any),
+ layer: PropTypes.object,
+ data: PropTypes.oneOfType([
+ PropTypes.arrayOf(PropTypes.any),
+ PropTypes.object
+ ])
+ }
+ return LayerHoverInfo;
+};
+
+export default LayerHoverInfoFactory;
diff --git a/src/components/map/map-popover.js b/src/components/map/map-popover.js
index 45952b902..1ff2b5eb4 100644
--- a/src/components/map/map-popover.js
+++ b/src/components/map/map-popover.js
@@ -18,15 +18,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {Component} from 'react';
+import React, {PureComponent} from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import classnames from 'classnames';
-import {CenterFlexbox} from 'components/common/styled-components';
-import {Pin, Layers} from 'components/common/icons';
-import {FIELD_DISPLAY_FORMAT} from 'constants/default-settings';
+import {Pin} from 'components/common/icons';
+import LayerHoverInfoFactory from './layer-hover-info';
+import CoordinateInfoFactory from './coordinate-info';
-const MAX_WIDTH = 400;
+const MAX_WIDTH = 500;
const MAX_HEIGHT = 600;
const StyledMapPopover = styled.div`
@@ -79,221 +79,113 @@ const StyledPin = styled.div`
}
`;
-const StyledLayerName = styled(CenterFlexbox)`
- color: ${props => props.theme.textColorHl};
- font-size: 12px;
- letter-spacing: 0.43px;
- text-transform: capitalize;
- padding-left: 14px;
- margin-top: 12px;
-
- svg {
- margin-right: 4px;
- }
-`;
-
-export class MapPopover extends Component {
- static propTypes = {
- fields: PropTypes.arrayOf(PropTypes.any),
- fieldsToShow: PropTypes.arrayOf(PropTypes.any),
- isVisible: PropTypes.bool,
- layer: PropTypes.object,
- data: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.any), PropTypes.object]),
- freezed: PropTypes.bool,
- x: PropTypes.number,
- y: PropTypes.number,
- onClose: PropTypes.func,
- mapState: PropTypes.object.isRequired
- };
-
- constructor(props) {
- super(props);
- this.state = {
- isMouseOver: false,
- width: 380,
- height: 160
+MapPopoverFactory.deps = [LayerHoverInfoFactory, CoordinateInfoFactory];
+
+export default function MapPopoverFactory(LayerHoverInfo, CoordinateInfo) {
+ class MapPopover extends PureComponent {
+ static propTypes = {
+ layerHoverProp: PropTypes.object,
+ coordinate: PropTypes.oneOfType([PropTypes.array, PropTypes.bool]),
+ freezed: PropTypes.bool,
+ x: PropTypes.number,
+ y: PropTypes.number,
+ mapW: PropTypes.number.isRequired,
+ mapH: PropTypes.number.isRequired,
+ onClose: PropTypes.func.isRequired
};
- }
-
- componentDidMount() {
- this._setContainerSize();
- }
- componentDidUpdate() {
- this._setContainerSize();
- }
-
- _setContainerSize() {
- const node = this.popover;
- if (!node) {
- return;
+ constructor(props) {
+ super(props);
+ this.state = {
+ isMouseOver: false,
+ width: 380,
+ height: 160
+ };
}
- const width = Math.min(node.scrollWidth, MAX_WIDTH);
- const height = Math.min(node.scrollHeight, MAX_HEIGHT);
-
- if (width !== this.state.width || height !== this.state.height) {
- this.setState({width, height});
+ componentDidMount() {
+ this._setContainerSize();
}
- }
- _getPosition(x, y) {
- const topOffset = 30;
- const leftOffset = 30;
- const {mapState} = this.props;
- const {width, height} = this.state;
- const pos = {};
- if (x + leftOffset + width > mapState.width) {
- pos.right = mapState.width - x + leftOffset;
- } else {
- pos.left = x + leftOffset;
+ componentDidUpdate() {
+ this._setContainerSize();
}
- if (y + topOffset + height > mapState.height) {
- pos.bottom = 10;
- } else {
- pos.top = y + topOffset;
- }
-
- return pos;
- }
+ _setContainerSize() {
+ const node = this.popover;
+ if (!node) {
+ return;
+ }
- render() {
- const {
- x,
- y,
- isVisible,
- data,
- layer,
- freezed,
- fields,
- fieldsToShow = []
- } = this.props;
- const hidden = !isVisible && !this.state.isMouseOver;
- const {width} = this.state;
+ const width = Math.min(Math.round(node.scrollWidth), MAX_WIDTH);
+ const height = Math.min(Math.round(node.scrollHeight), MAX_HEIGHT);
- if (!data || !layer || !fieldsToShow.length) {
- return null;
+ if (width !== this.state.width || height !== this.state.height) {
+ this.setState({width, height});
+ }
}
- const infoProps = {data, layer, fieldsToShow, fields};
-
- const style =
- Number.isFinite(x) && Number.isFinite(y) ? this._getPosition(x, y) : {};
+ _getPosition(x, y) {
+ const topOffset = 20;
+ const leftOffset = 20;
+ const {mapW, mapH} = this.props;
+ const {width, height} = this.state;
+ const pos = {};
+ if (x + leftOffset + width > mapW) {
+ pos.right = mapW - x + leftOffset;
+ } else {
+ pos.left = x + leftOffset;
+ }
+
+ if (y + topOffset + height > mapH) {
+ pos.bottom = 10;
+ } else {
+ pos.top = y + topOffset;
+ }
+
+ return pos;
+ }
- return (
- <StyledMapPopover
- ref={comp => {
- this.popover = comp;
- }}
- className={classnames('map-popover', {hidden})}
- style={{
- ...style,
- maxWidth: width
- }}
- onMouseEnter={() => {
- this.setState({isMouseOver: true});
- }}
- onMouseLeave={() => {
- this.setState({isMouseOver: false});
- }}
- >
- {freezed ? (
- <div className="map-popover__top">
- <div className="gutter" />
- <StyledPin className="popover-pin" onClick={this.props.onClose}>
- <Pin height="16px" />
- </StyledPin>
- </div>
- ) : null}
- <StyledLayerName className="map-popover__layer-name">
- <Layers height="12px"/>{layer.config.label}</StyledLayerName>
- <table className="map-popover__table">
- {layer.isAggregated ? (
- <CellInfo {...infoProps} />
- ) : (
- <EntryInfo {...infoProps} />
+ render() {
+ const {x, y, freezed, coordinate, layerHoverProp} = this.props;
+ const hidden = !this.state.isMouseOver;
+
+ const style =
+ Number.isFinite(x) && Number.isFinite(y) ? this._getPosition(x, y) : {};
+
+ return (
+ <StyledMapPopover
+ ref={comp => {
+ this.popover = comp;
+ }}
+ className={classnames('map-popover', {hidden})}
+ style={{
+ ...style,
+ maxWidth: MAX_WIDTH
+ }}
+ onMouseEnter={() => {
+ this.setState({isMouseOver: true});
+ }}
+ onMouseLeave={() => {
+ this.setState({isMouseOver: false});
+ }}
+ >
+ {freezed ? (
+ <div className="map-popover__top">
+ <div className="gutter" />
+ <StyledPin className="popover-pin" onClick={this.props.onClose}>
+ <Pin height="16px" />
+ </StyledPin>
+ </div>
+ ) : null}
+ {Array.isArray(coordinate) && (
+ <CoordinateInfo coordinate={coordinate} />
)}
- </table>
- </StyledMapPopover>
- );
- }
-}
-
-const Row = ({name, value, url}) => {
- // Set 'url' to 'value' if it looks like a url
- if (!url && value && typeof value === 'string' && value.match(/^http/)) {
- url = value;
- }
-
- const asImg = /<img>/.test(name);
- return (
- <tr className="row" key={name}>
- <td className="row__name">{name}</td>
- <td className="row__value">
- {asImg ? (
- <img src={value} />
- ) : url ? (
- <a target="_blank" rel="noopener noreferrer" href={url}>
- {value}
- </a>
- ) : (
- value
- )}
- </td>
- </tr>
- );
-};
-
-const EntryInfo = ({fieldsToShow, fields, data}) => (
- <tbody>
- {fieldsToShow.map(name => (
- <EntryInfoRow key={name} name={name} fields={fields} data={data} />
- ))}
- </tbody>
-);
-
-const EntryInfoRow = ({name, fields, data}) => {
- const field = fields.find(f => f.name === name);
- if (!field) {
- return null;
+ {layerHoverProp && <LayerHoverInfo {...layerHoverProp} />}
+ </StyledMapPopover>
+ );
+ }
}
- const valueIdx = field.tableFieldIndex - 1;
- const format = _getCellFormat(field.type);
-
- return (
- <Row name={name} value={format ? format(data[valueIdx]) : data[valueIdx]} />
- );
-};
-
-const CellInfo = ({data, layer}) => {
- const {colorField, sizeField} = layer.config;
-
- return (
- <tbody>
- <Row name={'total points'} key="count" value={data.points && data.points.length} />
- {colorField && layer.visualChannels.color ? (
- <Row
- name={layer.getVisualChannelDescription('color').measure}
- key="color"
- value={data.colorValue || 'N/A'}
- />
- ) : null}
- {sizeField && layer.visualChannels.size ? (
- <Row
- name={layer.getVisualChannelDescription('size').measure}
- key="size"
- value={data.elevationValue || 'N/A'}
- />
- ) : null}
- </tbody>
- );
-};
-
-function _getCellFormat(type) {
- return FIELD_DISPLAY_FORMAT[type];
+ return MapPopover;
}
-
-const MapPopoverFactory = () => MapPopover;
-export default MapPopoverFactory;
diff --git a/src/components/side-panel/interaction-panel/interaction-panel.js b/src/components/side-panel/interaction-panel/interaction-panel.js
index d416e42b7..da4818203 100644
--- a/src/components/side-panel/interaction-panel/interaction-panel.js
+++ b/src/components/side-panel/interaction-panel/interaction-panel.js
@@ -114,7 +114,7 @@ function InteractionPanelFactory(TooltipConfig, BrushConfig) {
/>
</div>
</StyledPanelHeader>
- {config.enabled && (
+ {(config.enabled && template) && (
<StyledPanelContent className="interaction-panel__content">
{template}
</StyledPanelContent>
diff --git a/src/constants/action-types.js b/src/constants/action-types.js
index 81f42834a..c3e4ce2be 100644
--- a/src/constants/action-types.js
+++ b/src/constants/action-types.js
@@ -70,6 +70,7 @@ const ActionTypes = keyMirror({
LAYER_HOVER: null,
LAYER_CLICK: null,
MAP_CLICK: null,
+ MOUSE_MOVE: null,
REMOVE_FILTER: null,
REMOVE_LAYER: null,
REMOVE_DATASET: null,
diff --git a/src/layers/point-layer/point-layer.js b/src/layers/point-layer/point-layer.js
index 178e5b745..43bd543ea 100644
--- a/src/layers/point-layer/point-layer.js
+++ b/src/layers/point-layer/point-layer.js
@@ -260,7 +260,7 @@ export default class PointLayer extends Layer {
// get all distinct characters in the text labels
const getRadius = rScale
- ? d => this.getEncodedChannelValue(rScale, d.data, sizeField)
+ ? d => this.getEncodedChannelValue(rScale, d.data, sizeField, 0)
: 1;
const getFillColor = cScale
@@ -370,7 +370,7 @@ export default class PointLayer extends Layer {
// TODO: support setting stroke and fill simultaneously
stroked: this.config.visConfig.outline,
filled: this.config.visConfig.filled,
- radiusMinPixels: 1,
+ radiusMinPixels: 0,
lineWidthMinPixels: this.config.visConfig.thickness,
radiusScale,
...(this.config.visConfig.fixedRadius ? {} : {radiusMaxPixels: 500})
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index 375307cad..5441ef2b5 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -20,6 +20,7 @@
import {console as Console} from 'global/window';
import Task, {disableStackCapturing, withTask} from 'react-palm/tasks';
+import cloneDeep from 'lodash.clonedeep';
// Tasks
import {LOAD_FILE_TASK} from 'tasks/tasks';
@@ -146,6 +147,7 @@ export const INITIAL_VIS_STATE = {
layerBlending: 'normal',
hoverInfo: undefined,
clicked: undefined,
+ mousePos: {},
// TODO: not used anywhere, delete it
fileLoading: false,
@@ -420,9 +422,13 @@ export function interactionConfigChangeUpdater(state, action) {
...{[config.id]: config}
};
- if (config.enabled && !state.interactionConfig[config.id].enabled) {
+ // Don't enable tooltip and brush at the same time
+ // but coordinates can be shown at all time
+ const contradict = ['brush', 'tooltip'];
+
+ if (contradict.includes(config.id) && config.enabled && !state.interactionConfig[config.id].enabled) {
// only enable one interaction at a time
- Object.keys(interactionConfig).forEach(k => {
+ contradict.forEach(k => {
if (k !== config.id) {
interactionConfig[k] = {...interactionConfig[k], enabled: false};
}
@@ -911,6 +917,10 @@ export const layerHoverUpdater = (state, action) => ({
*/
export const layerClickUpdater = (state, action) => ({
...state,
+ mousePos: state.interactionConfig.coordinate.enabled ? {
+ ...state.mousePos,
+ pinned: state.mousePos.pinned ? null : cloneDeep(state.mousePos)
+ } : state.mousePos,
clicked: action.info && action.info.picked ? action.info : null
});
@@ -921,11 +931,28 @@ export const layerClickUpdater = (state, action) => ({
* @returns {Object} nextState
* @public
*/
-export const mapClickUpdater = (state) => ({
+export const mapClickUpdater = (state) => {
+ return {
...state,
clicked: null
-});
+}
+};
+
+export const mouseMoveUpdater = (state, {evt}) => {
+ if (Object.values(state.interactionConfig).some(config => config.enabled)) {
+ return {
+ ...state,
+ mousePos: {
+ ...state.mousePos,
+ mousePosition: [...evt.point],
+ coordinate: [...evt.lngLat]
+ }
+ };
+ }
+
+ return state;
+}
/**
* Toggle visibility of a layer for a split map
* @memberof visStateUpdaters
diff --git a/src/reducers/vis-state.js b/src/reducers/vis-state.js
index f10bd6e25..41d763567 100644
--- a/src/reducers/vis-state.js
+++ b/src/reducers/vis-state.js
@@ -55,6 +55,8 @@ const actionHandler = {
[ActionTypes.MAP_CLICK]: visStateUpdaters.mapClickUpdater,
+ [ActionTypes.MOUSE_MOVE]: visStateUpdaters.mouseMoveUpdater,
+
[ActionTypes.RECEIVE_MAP_CONFIG]: visStateUpdaters.receiveMapConfigUpdater,
[ActionTypes.REMOVE_DATASET]: visStateUpdaters.removeDatasetUpdater,
diff --git a/src/utils/interaction-utils.js b/src/utils/interaction-utils.js
index e0655e11d..8cb626226 100644
--- a/src/utils/interaction-utils.js
+++ b/src/utils/interaction-utils.js
@@ -24,7 +24,7 @@ import {
ALL_FIELD_TYPES,
TRIP_POINT_FIELDS
} from 'constants/default-settings';
-import {Messages, Crosshairs} from 'components/common/icons/index';
+import {Messages, Crosshairs, CursorClick} from 'components/common/icons/index';
export function getDefaultInteraction() {
return {
@@ -44,6 +44,12 @@ export function getDefaultInteraction() {
// size is in km
size: 0.5
}
+ },
+ coordinate: {
+ id: 'coordinate',
+ enabled: false,
+ iconComponent: CursorClick,
+ position: null
}
};
}
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index 61aaac7f2..8424cf511 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -20,8 +20,7 @@
import {KeplerGlLayers} from 'layers';
const {PointLayer, ArcLayer, HexagonLayer, GeojsonLayer} = KeplerGlLayers;
-
-import {Messages, Crosshairs} from 'components/common/icons';
+import {getDefaultInteraction} from 'utils/interaction-utils';
import {DEFAULT_TEXT_LABEL} from 'layers/layer-factory';
export const savedStateV0 = {
@@ -1502,22 +1501,17 @@ export const mergedLayers = [
mergedLayer4
];
+const defaultInteraction = getDefaultInteraction();
export const mergedInteractions = {
+ ...defaultInteraction,
tooltip: {
- id: 'tooltip',
+ ...defaultInteraction.tooltip,
enabled: true,
config: {
fieldsToShow: {
'9h10t7fyb': ['int_range', 'detail', 'type_boolean'],
v79816te8: ['ID', 'ZIP_CODE']
}
- },
- iconComponent: Messages
- },
- brush: {
- id: 'brush',
- enabled: false,
- config: {size: 0.5},
- iconComponent: Crosshairs
+ }
}
};
diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.js
index 80e59f98e..4e19a9221 100644
--- a/test/fixtures/state-saved-v1-1.js
+++ b/test/fixtures/state-saved-v1-1.js
@@ -21,6 +21,7 @@
import GeojsonLayer from 'layers/geojson-layer/geojson-layer';
import {Messages, Crosshairs} from 'components/common/icons';
import {DEFAULT_TEXT_LABEL} from 'layers/layer-factory';
+import {getDefaultInteraction} from 'utils/interaction-utils';
export const savedStateV1 = {
datasets: [
@@ -2764,10 +2765,11 @@ mergedLayer1.dataToFeature = mergedLayer0.dataToFeature;
export const mergedLayers = [mergedLayer0, mergedLayer1];
+const defaultInteraction = getDefaultInteraction();
export const mergedInteraction = {
+ ...defaultInteraction,
tooltip: {
- id: 'tooltip',
- iconComponent: Messages,
+ ...defaultInteraction.tooltip,
enabled: false,
config: {
fieldsToShow: {
@@ -2776,9 +2778,8 @@ export const mergedInteraction = {
}
},
brush: {
- id: 'brush',
+ ...defaultInteraction.brush,
enabled: false,
- iconComponent: Crosshairs,
config: {
size: 1
}
diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.js
index 035d1db0a..46d42f1dc 100644
--- a/test/node/reducers/vis-state-merger-test.js
+++ b/test/node/reducers/vis-state-merger-test.js
@@ -33,6 +33,7 @@ import SchemaManager from 'schemas';
import visStateReducer from 'reducers/vis-state';
import {updateVisData} from 'actions/vis-state-actions';
import {receiveMapConfig} from 'actions/actions';
+import {getDefaultInteraction} from 'utils/interaction-utils';
// fixtures
import {
@@ -577,25 +578,7 @@ test('VisStateMerger.v0 -> mergeInteractions -> toEmptyState', t => {
} else if (key === 'interactionConfig') {
t.deepEqual(
mergedState.interactionConfig,
- {
- tooltip: {
- id: 'tooltip',
- enabled: true,
- config: {
- fieldsToShow: {}
- },
- iconComponent: Messages
- },
- brush: {
- id: 'brush',
- enabled: false,
- config: {
- size: 0.5
- },
- iconComponent: Crosshairs
- }
- },
-
+ oldState.visState.interactionConfig,
'Should disable interaction: null'
);
} else {
@@ -678,12 +661,13 @@ test('VisStateMerger.v0 -> mergeInteractions -> toWorkingState', t => {
// load data into reducer
const stateWData = visStateReducer(mergedState, updateVisData(parsedData));
+ const defaultInteraction = getDefaultInteraction();
const expectedInteractions = {
+ ...defaultInteraction,
tooltip: {
- id: 'tooltip',
+ ...defaultInteraction.tooltip,
enabled: true,
- iconComponent: Messages,
config: {
fieldsToShow: {
'190vdll3di': [
@@ -698,12 +682,6 @@ test('VisStateMerger.v0 -> mergeInteractions -> toWorkingState', t => {
v79816te8: ['ID', 'ZIP_CODE']
}
}
- },
- brush: {
- id: 'brush',
- enabled: false,
- iconComponent: Crosshairs,
- config: {size: 0.5}
}
};
@@ -731,6 +709,7 @@ test('VisStateMerger.v1 -> mergeInteractions -> toEmptyState', t => {
// merge interactions
const mergedState = mergeInteractions(oldState.visState, parsedInteraction);
+ const defaultInteraction = getDefaultInteraction();
Object.keys(oldVisState).forEach(key => {
if (key === 'interactionToBeMerged') {
@@ -750,25 +729,24 @@ test('VisStateMerger.v1 -> mergeInteractions -> toEmptyState', t => {
t.deepEqual(
mergedState.interactionConfig,
{
+ ...defaultInteraction,
tooltip: {
- id: 'tooltip',
+ ...defaultInteraction.tooltip,
enabled: false,
config: {
fieldsToShow: {}
- },
- iconComponent: Messages
+ }
},
brush: {
- id: 'brush',
+ ...defaultInteraction.brush,
enabled: false,
config: {
size: 1
- },
- iconComponent: Crosshairs
+ }
}
},
- 'Should disable interaction: null'
+ 'Should disable tooltip'
);
} else {
t.deepEqual(
@@ -819,6 +797,7 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
// merge interactions
const mergedState = mergeInteractions(oldState.visState, parsedInteraction);
+ const defaultInteraction = getDefaultInteraction();
const expectedInteractionToBeMerged = {
tooltip: {
@@ -840,9 +819,9 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
t.deepEqual(
mergedState.interactionConfig,
{
+ ...defaultInteraction,
tooltip: {
- id: 'tooltip',
- iconComponent: Messages,
+ ...defaultInteraction.tooltip,
enabled: false,
config: {
fieldsToShow: {
@@ -857,10 +836,10 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
}
}
},
+
brush: {
- id: 'brush',
+ ...defaultInteraction.brush,
enabled: false,
- iconComponent: Crosshairs,
config: {
size: 1
}
@@ -884,10 +863,10 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
const stateWData = visStateReducer(mergedState, updateVisData(parsedData));
const expectedInteractions = {
+ ...defaultInteraction,
tooltip: {
- id: 'tooltip',
+ ...defaultInteraction.tooltip,
enabled: false,
- iconComponent: Messages,
config: {
fieldsToShow: {
'190vdll3di': [
@@ -903,9 +882,8 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
}
},
brush: {
- id: 'brush',
+ ...defaultInteraction.brush,
enabled: false,
- iconComponent: Crosshairs,
config: {size: 1}
}
};
@@ -914,7 +892,7 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
t.deepEqual(
stateWData.interactionConfig,
expectedInteractions,
- 'should merge interactionconfig'
+ 'should merge interactionConfig'
);
t.deepEqual(stateWData.interactionToBeMerged, {}, 'should clear interaction');