Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -17,7 +17,7 @@ import {
setSelectedLayer,
setTimeFilters,
setRefreshConfig,
setGoto,
setGotoWithCenter,
replaceLayerList,
setQuery,
} from '../actions/store_actions';
Expand Down Expand Up @@ -85,7 +85,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)),
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';
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