Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce disable tooltip on hover property #313

Merged
merged 1 commit into from
Mar 3, 2023
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
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