Skip to content

Commit

Permalink
[Maps] disable maps interactions when using search session (#91229)
Browse files Browse the repository at this point in the history
* [Maps] disable maps interactions when using search session restore

* tslint

* tslint

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
nreese and kibanamachine authored Feb 16, 2021
1 parent b9bccf3 commit 7917632
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
28 changes: 24 additions & 4 deletions x-pack/plugins/maps/public/connected_components/mb_map/mb_map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export class MBMap extends Component<Props, State> {
private _checker?: ResizeChecker;
private _isMounted: boolean = false;
private _containerRef: HTMLDivElement | null = null;
private _prevDisableInteractive?: boolean;
private _navigationControl = new mapboxgl.NavigationControl({ showCompass: false });

state: State = {
prevLayerList: undefined,
Expand Down Expand Up @@ -181,7 +183,6 @@ export class MBMap extends Component<Props, State> {
style: mbStyle,
scrollZoom: this.props.scrollZoom,
preserveDrawingBuffer: getPreserveDrawingBuffer(),
interactive: !this.props.settings.disableInteractive,
maxZoom: this.props.settings.maxZoom,
minZoom: this.props.settings.minZoom,
};
Expand All @@ -197,9 +198,6 @@ export class MBMap extends Component<Props, State> {
const mbMap = new mapboxgl.Map(options);
mbMap.dragRotate.disable();
mbMap.touchZoomRotate.disableRotation();
if (!this.props.settings.disableInteractive) {
mbMap.addControl(new mapboxgl.NavigationControl({ showCompass: false }), 'top-left');
}

const tooManyFeaturesImageSrc =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAA7DgAAOw4BzLahgwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAARLSURBVHic7ZnPbxRVAMe/7735sWO3293ZlUItJsivCxEE0oTYRgu1FqTQoFSwKTYx8SAH/wHjj4vRozGGi56sMcW2UfqTEuOhppE0KJc2GIuKQFDY7qzdtrudX88D3YTUdFuQN8+k87lt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v07Ztg0AOzVNf03Ttu/S9T2PMlbjc25fdpyutmx2TLRbIAEA4M1otKo1EjmaoHQn4ZwBgA/kAVAK6MXXdzxv/ONcrq/HcbJBeAUWoEizqsaORaPbKglZrxMSZZyrM76f/ovzWx/m85PFWREUgQf4v7Hm/xcIA8gWkE0YQLaAbMIAsgVkEwaQLSCbMIBsAdmEAWQLyCYMIFtANmEA2QKyCQPIFpDNmg/wD3OFdEybUvJjAAAAAElFTkSuQmCC';
Expand Down Expand Up @@ -357,6 +355,28 @@ export class MBMap extends Component<Props, State> {
return;
}

if (
this._prevDisableInteractive === undefined ||
this._prevDisableInteractive !== this.props.settings.disableInteractive
) {
this._prevDisableInteractive = this.props.settings.disableInteractive;
if (this.props.settings.disableInteractive) {
this.state.mbMap.boxZoom.disable();
this.state.mbMap.doubleClickZoom.disable();
this.state.mbMap.dragPan.disable();
try {
this.state.mbMap.removeControl(this._navigationControl);
} catch (error) {
// ignore removeControl errors
}
} else {
this.state.mbMap.boxZoom.enable();
this.state.mbMap.doubleClickZoom.enable();
this.state.mbMap.dragPan.enable();
this.state.mbMap.addControl(this._navigationControl, 'top-left');
}
}

let zoomRangeChanged = false;
if (this.props.settings.minZoom !== this.state.mbMap.getMinZoom()) {
this.state.mbMap.setMinZoom(this.props.settings.minZoom);
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/maps/public/embeddable/map_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from '../../../../../src/plugins/data/public';
import {
replaceLayerList,
setMapSettings,
setQuery,
setRefreshConfig,
disableScrollZoom,
Expand Down Expand Up @@ -60,6 +61,7 @@ import {
getCoreI18n,
getHttp,
getChartsPaletteServiceGetColor,
getSearchService,
} from '../kibana_services';
import { LayerDescriptor } from '../../common/descriptor_types';
import { MapContainer } from '../connected_components/map_container';
Expand All @@ -77,6 +79,14 @@ import {
} from './types';
export { MapEmbeddableInput, MapEmbeddableOutput };

function getIsRestore(searchSessionId?: string) {
if (!searchSessionId) {
return false;
}
const searchSessionOptions = getSearchService().session.getSearchOptions(searchSessionId);
return searchSessionOptions ? searchSessionOptions.isRestore : false;
}

export class MapEmbeddable
extends Embeddable<MapEmbeddableInput, MapEmbeddableOutput>
implements ReferenceOrValueEmbeddable<MapByValueInput, MapByReferenceInput> {
Expand All @@ -85,6 +95,7 @@ export class MapEmbeddable
private _savedMap: SavedMap;
private _renderTooltipContent?: RenderToolTipContent;
private _subscription: Subscription;
private _prevIsRestore: boolean = false;
private _prevTimeRange?: TimeRange;
private _prevQuery?: Query;
private _prevRefreshConfig?: RefreshInterval;
Expand Down Expand Up @@ -234,6 +245,17 @@ export class MapEmbeddable
if (this.input.syncColors !== this._prevSyncColors) {
this._dispatchSetChartsPaletteServiceGetColor(this.input.syncColors);
}

const isRestore = getIsRestore(this.input.searchSessionId);
if (isRestore !== this._prevIsRestore) {
this._prevIsRestore = isRestore;
this._savedMap.getStore().dispatch(
setMapSettings({
disableInteractive: isRestore,
hideToolbarOverlay: isRestore,
})
);
}
}

_dispatchSetQuery({
Expand Down

0 comments on commit 7917632

Please sign in to comment.