Skip to content

Commit

Permalink
Introduce disable tooltip on hover property
Browse files Browse the repository at this point in the history
Added new property that allows users to disable tooltip
on hover. The default value is false to keep
backward compatability. We will revisit the ideal
default value based on user's feedback in later release.

Signed-off-by: Vijayan Balasubramanian <[email protected]>
  • Loading branch information
VijayanB committed Mar 2, 2023
1 parent 26aea7a commit 25da75c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const DOCUMENTS_MIN_MARKER_BORDER_THICKNESS = 0;
export const DOCUMENTS_MAX_MARKER_BORDER_THICKNESS = 100;
export const DOCUMENTS_DEFAULT_REQUEST_NUMBER = 1000;
export const DOCUMENTS_DEFAULT_SHOW_TOOLTIPS: boolean = false;
export const DOCUMENTS_DEFAULT_DISABLE_TOOLTIPS_ON_HOVER: boolean = false;
export const DOCUMENTS_DEFAULT_TOOLTIPS: string[] = [];
export const LAYER_PANEL_HIDE_LAYER_ICON = 'eyeClosed';
export const LAYER_PANEL_SHOW_LAYER_ICON = 'eye';
Expand Down
10 changes: 8 additions & 2 deletions public/components/map_container/map_container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import {
Query,
} from '../../../../../src/plugins/data/public';
import { MapState } from '../../model/mapState';
import { createPopup, getPopupLocation, isTooltipEnabledLayer } from '../tooltip/create_tooltip';
import {
createPopup,
getPopupLocation,
isTooltipEnabledLayer,
isTooltipEnabledOnHover,
} from '../tooltip/create_tooltip';
import {
handleDataLayerRender,
handleReferenceLayerRender,
Expand Down Expand Up @@ -153,11 +158,12 @@ export const MapContainer = ({
// remove previous popup
hoverPopup?.remove();

const tooltipEnabledLayersOnHover = layers.filter(isTooltipEnabledOnHover);
const features = maplibreRef.current?.queryRenderedFeatures(e.point);
if (features && maplibreRef.current) {
hoverPopup = createPopup({
features,
layers: tooltipEnabledLayers,
layers: tooltipEnabledLayersOnHover,
// enable close button to avoid occasional dangling tooltip that is not cleared during mouse leave action
showCloseButton: true,
showPagination: false,
Expand Down
6 changes: 6 additions & 0 deletions public/components/tooltip/create_tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export function isTooltipEnabledLayer(
);
}

export function isTooltipEnabledOnHover(
layer: MapLayerSpecification
): layer is DocumentLayerSpecification {
return isTooltipEnabledLayer(layer) && !layer.source?.disableTooltipsOnHover;
}

export function groupFeaturesByLayers(
features: MapGeoJSONFeature[],
layers: DocumentLayerSpecification[]
Expand Down
1 change: 1 addition & 0 deletions public/model/mapLayerType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type DocumentLayerSpecification = {
geoFieldName: string;
documentRequestNumber: number;
showTooltips: boolean;
disableTooltipsOnHover?: boolean;
tooltipFields: string[];
useGeoBoundingBoxFilter: boolean;
filters: Filter[];
Expand Down
2 changes: 2 additions & 0 deletions public/utils/getIntialConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
MAP_REFERENCE_LAYER_DEFAULT_OPACITY,
OPENSEARCH_MAP_LAYER,
CUSTOM_MAP,
DOCUMENTS_DEFAULT_DISABLE_TOOLTIPS_ON_HOVER,
} from '../../common';
import { MapState } from '../model/mapState';
import { ConfigSchema } from '../../common/config';
Expand Down Expand Up @@ -53,6 +54,7 @@ export const getLayerConfigMap = (mapConfig: ConfigSchema) => ({
documentRequestNumber: DOCUMENTS_DEFAULT_REQUEST_NUMBER,
tooltipFields: DOCUMENTS_DEFAULT_TOOLTIPS,
showTooltips: DOCUMENTS_DEFAULT_SHOW_TOOLTIPS,
disableTooltipsOnHover: DOCUMENTS_DEFAULT_DISABLE_TOOLTIPS_ON_HOVER,
},
style: {
...getStyleColor(),
Expand Down

0 comments on commit 25da75c

Please sign in to comment.