Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0a7fb90
add fit to data button (outline)
thomasneirynck Jan 15, 2019
64e0f86
split into two action-creators
thomasneirynck Jan 16, 2019
04fb07f
use action to dispatch fitToExtent, since we need filtering
thomasneirynck Jan 16, 2019
3383d0d
tmp commit
thomasneirynck Jan 16, 2019
3d9ecd2
start moving duplicated code
thomasneirynck Jan 16, 2019
73a1747
more simplification
thomasneirynck Jan 16, 2019
05c7ba0
add getbonuds implementation for es-sources
thomasneirynck Jan 16, 2019
7ebcbb3
add fallback implementation
thomasneirynck Jan 16, 2019
c5eea52
remove some cruft
thomasneirynck Jan 16, 2019
df66b1e
add implementaiton for heatmaps
thomasneirynck Jan 16, 2019
3f9a0d3
deal with empty responses
thomasneirynck Jan 16, 2019
1e70874
Merge branch 'master' into maps/add_fittobounds
thomasneirynck Jan 22, 2019
a218805
move implementation to layer
thomasneirynck Jan 22, 2019
4a90d74
fix merge error
thomasneirynck Jan 23, 2019
776d395
move buttons to context menu
thomasneirynck Jan 24, 2019
ab57327
Merge branch 'master' into maps/add_fittobounds
thomasneirynck Jan 24, 2019
05e4669
fix cruft
thomasneirynck Jan 24, 2019
ec4d050
feedback
thomasneirynck Jan 24, 2019
c12bb4e
add guard
thomasneirynck Jan 24, 2019
cc6ff14
Merge branch 'master' into maps/add_fittobounds
thomasneirynck Jan 24, 2019
f252dc8
fIx TOC icon alignment
cchaos Jan 24, 2019
5100de5
Merge branch 'master' into maps/add_fittobounds
thomasneirynck Jan 24, 2019
f69365b
Merge branch 'maps/add_fittobounds/design' of https://github.com/ccha…
thomasneirynck Jan 24, 2019
82978c8
fix merge error
thomasneirynck Jan 25, 2019
5016435
remove debug cruft
thomasneirynck Jan 25, 2019
d7bed68
remove methods
thomasneirynck Jan 25, 2019
b63fe4f
move tooltip to top
thomasneirynck Jan 25, 2019
7baf4c7
improve text
thomasneirynck Jan 25, 2019
4c5366a
fix layername loading
thomasneirynck Jan 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions x-pack/plugins/gis/public/actions/store_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,35 @@ export function clearMouseCoordinates() {
return { type: CLEAR_MOUSE_COORDINATES };
}

export function setGoto({ lat, lon, zoom }) {

export function fitToLayerExtent(layerId) {
return async function (dispatch, getState) {
const targetLayer = getLayerList(getState()).find(layer => {
return layer.getId() === layerId;
});

if (targetLayer) {
const dataFilters = getDataFilters(getState());
const bounds = await targetLayer.getBounds(dataFilters);
if (bounds) {
await dispatch(setGotoWithBounds(bounds));
}
}
};
}

export function setGotoWithBounds(bounds) {
return {
type: SET_GOTO,
lat,
lon,
zoom,
bounds: bounds
};
}


export function setGotoWithCenter({ lat, lon, zoom }) {
return {
type: SET_GOTO,
center: { lat, lon, zoom }
};
}

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/gis/public/angular/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
setSelectedLayer,
setTimeFilters,
setRefreshConfig,
setGoto,
setGotoWithCenter,
replaceLayerList,
setQuery,
} from '../actions/store_actions';
Expand Down Expand Up @@ -82,7 +82,7 @@ app.controller('GisMapController', ($scope, $route, config, kbnUrl, localStorage
queryFromSavedObject = mapState.query;
const timeFilters = mapState.timeFilters ? mapState.timeFilters : timefilter.getTime();
store.dispatch(setTimeFilters(timeFilters));
store.dispatch(setGoto({
store.dispatch(setGotoWithCenter({
lat: mapState.center.lat,
lon: mapState.center.lon,
zoom: mapState.zoom,
Expand Down
11 changes: 9 additions & 2 deletions x-pack/plugins/gis/public/components/layer_panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
import { connect } from 'react-redux';
import { LayerPanel } from './view';
import { getSelectedLayer } from '../../selectors/map_selectors';
import {
fitToLayerExtent
} from '../../actions/store_actions';

function mapStateToProps(state = {}) {
return {
selectedLayer: getSelectedLayer(state)
};
}

function mapDispatchToProps(/* dispatch */) {
return {};
function mapDispatchToProps(dispatch) {
return {
fitToBounds: (layerId) => {
dispatch(fitToLayerExtent(layerId));
}
};
}

const connectedLayerPanel = connect(mapStateToProps, mapDispatchToProps)(LayerPanel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function mapStateToProps(state = {}) {
maxZoom: selectedLayer.getMaxZoom(),
minZoom: selectedLayer.getMinZoom(),
renderSourceDetails: selectedLayer.renderSourceDetails,
renderSourceSettingsEditor: selectedLayer.renderSourceSettingsEditor,
renderSourceSettingsEditor: selectedLayer.renderSourceSettingsEditor
};
}

Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/gis/public/components/layer_panel/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FlyoutFooter } from './flyout_footer';
import { SettingsPanel } from './settings_panel';

import {
EuiButtonIcon,
EuiFlexItem,
EuiTitle,
EuiPanel,
Expand Down Expand Up @@ -70,7 +71,9 @@ export class LayerPanel extends React.Component {
<EuiFlyoutHeader hasBorder className="gisLayerPanel__header">
<EuiFlexGroup responsive={false} alignItems="center" gutterSize="s">
<EuiFlexItem grow={false}>
{selectedLayer.getIcon()}
<EuiButtonIcon iconType={selectedLayer.getLayerTypeIconName()} iconSide="right" onClick={this.props.fitToBounds}>
Fit
</EuiButtonIcon>
</EuiFlexItem>
<EuiFlexItem>
<EuiTitle size="s">
Expand Down
34 changes: 28 additions & 6 deletions x-pack/plugins/gis/public/components/map/mb/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ResizeChecker } from 'ui/resize_checker';
import { syncLayerOrder, removeOrphanedSourcesAndLayers, createMbMapInstance } from './utils';
import { inspectorAdapters } from '../../../kibana_services';
import { DECIMAL_DEGREES_PRECISION, ZOOM_PRECISION } from '../../../../common/constants';
import mapboxgl from 'mapbox-gl';

export class MBMapContainer extends React.Component {

Expand Down Expand Up @@ -61,7 +62,8 @@ export class MBMapContainer extends React.Component {
}

async _initializeMap() {
this._mbMap = await createMbMapInstance(this.refs.mapContainer, this.props.goto);

this._mbMap = await createMbMapInstance(this.refs.mapContainer, this.props.goto ? this.props.goto.center : null);

// Override mapboxgl.Map "on" and "removeLayer" methods so we can track layer listeners
// Tracked layer listerners are used to clean up event handlers
Expand All @@ -88,6 +90,7 @@ export class MBMapContainer extends React.Component {

this.assignSizeWatch();


// moveend callback is debounced to avoid updating map extent state while map extent is still changing
// moveend is fired while the map extent is still changing in the following scenarios
// 1) During opening/closing of layer details panel, the EUI animation results in 8 moveend events
Expand Down Expand Up @@ -169,11 +172,23 @@ export class MBMapContainer extends React.Component {
}

clearGoto();
this._mbMap.setZoom(goto.zoom);
this._mbMap.setCenter({
lng: goto.lon,
lat: goto.lat
});

if (goto.bounds) {
//clamping ot -89/89 latitudes since Mapboxgl does not seem to handle bounds that contain the poles (logs errors to the console when using -90/90)
const lnLatBounds = new mapboxgl.LngLatBounds(
new mapboxgl.LngLat(clamp(goto.bounds.min_lon, -180, 180), clamp(goto.bounds.min_lat, -89, 89)),
Comment thread
thomasneirynck marked this conversation as resolved.
new mapboxgl.LngLat(clamp(goto.bounds.max_lon, -180, 180), clamp(goto.bounds.max_lat, -89, 89)),
);
this._mbMap.fitBounds(lnLatBounds);
} else if (goto.center) {
this._mbMap.setZoom(goto.center.zoom);
this._mbMap.setCenter({
lng: goto.center.lon,
lat: goto.center.lat
});
}


};

_syncMbMapWithLayerList = () => {
Expand Down Expand Up @@ -217,3 +232,10 @@ export class MBMapContainer extends React.Component {
);
}
}


function clamp(val, min, max) {
if (val > max) val = max;
else if (val < min) val = min;
return val;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
opacity: 0.5;
}

.gisTocEntry__grab {
margin-left: $euiSizeXS;
}

.gisTocEntry__grab:hover {
cursor: grab;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import _ from 'lodash';
import { connect } from 'react-redux';
import { TOCEntry } from './toc_entry';
import { TOCEntry } from './view';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you renaming this to view? It is a lot more difficult in the debugger and IDE when every file is called view. Why not name the view files so there is less name collision?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency with namings for our other components that use an index file

Copy link
Copy Markdown
Contributor

@nreese nreese Jan 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why not go the other way, and rename all view.js files to aNameThatActuallyMeansSomething.js? Seems like reverting to view.js goes backwards

import { updateFlyout, FLYOUT_STATE } from '../../../../../store/ui';
import { setSelectedLayer, toggleLayerVisible } from '../../../../../actions/store_actions';
import { fitToLayerExtent, setSelectedLayer, toggleLayerVisible } from '../../../../../actions/store_actions';

function mapStateToProps(state = {}) {
return {
Expand All @@ -22,7 +22,12 @@ function mapDispatchToProps(dispatch) {
dispatch(setSelectedLayer(layerId));
dispatch(updateFlyout(FLYOUT_STATE.LAYER_PANEL));
},
toggleVisible: layerId => dispatch(toggleLayerVisible(layerId))
toggleVisible: layerId => {
dispatch(toggleLayerVisible(layerId));
},
fitToBounds: (layerId) => {
dispatch(fitToLayerExtent(layerId));
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiLoadingSpinner,
EuiToolTip,
EuiIconTip,
EuiSpacer
} from '@elastic/eui';
import { VisibilityToggle } from '../../../../../shared/components/visibility_toggle';
import { LayerTocActions } from '../../../../../shared/components/layer_toc_actions';

export class TOCEntry extends React.Component {

Expand All @@ -26,69 +23,44 @@ export class TOCEntry extends React.Component {

componentDidMount() {
this._isMounted = true;
this._updateDisplayName();
}

componentWillUnmount() {
this._isMounted = false;
}

_renderVisibilityToggle() {
const { layer, toggleVisible } = this.props;
return (
<VisibilityToggle
id={layer.getId()}
checked={layer.isVisible()}
onChange={() => toggleVisible(layer.getId())}
size={'l'}
>
{layer.getIcon()}
</VisibilityToggle>
);
}

render() {

const { layer, openLayerPanel, zoom } = this.props;

const displayName = layer.getDisplayName();
Promise.resolve(displayName).then(label => {
if (this._isMounted) {
if (label !== this.state.displayName) {
this.setState({
displayName: label
});
}
async _updateDisplayName() {
const label = await this.props.layer.getDisplayName();
if (this._isMounted) {
if (label !== this.state.displayName) {
this.setState({
displayName: label
});
}
});

let visibilityIndicator;
if (layer.dataHasLoadError()) {
visibilityIndicator = (
<EuiIconTip
aria-label="Load warning"
size="m"
type="alert"
color="warning"
content={layer.getDataLoadError()}
/>
);
} else if (layer.isLayerLoading()) {
visibilityIndicator = <EuiLoadingSpinner size="m"/>;
} else if (!layer.showAtZoomLevel(zoom)) {
const { minZoom, maxZoom } = layer.getZoomConfig();
visibilityIndicator = (
<EuiToolTip
position="left"
content={`Map is at zoom level ${zoom}.
This layer is only visible between zoom levels ${minZoom} to ${maxZoom}.`}
>
{this._renderVisibilityToggle()}
</EuiToolTip>
);
} else {
visibilityIndicator = this._renderVisibilityToggle();
}
}

componentDidUpdate() {
this._updateDisplayName();
}

render() {

const { layer, openLayerPanel, zoom, toggleVisible, fitToBounds } = this.props;
const legendIcon = (
<LayerTocActions
layer={layer}
fitToBounds={() => {
fitToBounds(layer.getId());
}}
zoom={zoom}
toggleVisible={() => {
toggleVisible(layer.getId());
}}
/>
);
let tocDetails = layer.getTOCDetails();
if (tocDetails) {
tocDetails = (
Expand All @@ -106,15 +78,15 @@ export class TOCEntry extends React.Component {
data-layerid={layer.getId()}
>
<EuiFlexGroup
gutterSize="s"
gutterSize="none"
alignItems="center"
responsive={false}
className={
layer.isVisible() && layer.showAtZoomLevel(zoom) && !layer.dataHasLoadError() ? 'gisTocEntry-visible' : 'gisTocEntry-notVisible'
}
>
<EuiFlexItem grow={false}>
{visibilityIndicator}
{ legendIcon }
</EuiFlexItem>
<EuiFlexItem>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class LayerTOC extends React.Component {
render() {
const layerEntries = this._renderLayers();
return (
<div className="layerTOC" ref={node => this._domContainer = node}>
<div ref={node => this._domContainer = node}>
{layerEntries}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { connect } from 'react-redux';
import { SetView } from './set_view';
import { setGoto } from '../../../../actions/store_actions';
import { setGotoWithCenter } from '../../../../actions/store_actions';
import { getMapZoom, getMapCenter } from "../../../../selectors/map_selectors";
import { closeSetView } from '../../../../store/ui';

Expand All @@ -21,7 +21,7 @@ function mapDispatchToProps(dispatch) {
return {
onSubmit: ({ lat, lon, zoom }) => {
dispatch(closeSetView());
dispatch(setGoto({ lat, lon, zoom }));
dispatch(setGotoWithCenter({ lat, lon, zoom }));
}
};
}
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/gis/public/shared/components/_index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
@import './map_listing';
@import './visibility_toggle';
Loading