From 82ff2307706959b25ef037cf6ecc2f1b03f38956 Mon Sep 17 00:00:00 2001 From: Hugo Marcellin Date: Fri, 15 Mar 2024 14:32:16 +0100 Subject: [PATCH] Add equipment type to map lines to customize tooltip rendering Signed-off-by: Hugo Marcellin --- .../network/network-map.jsx | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/network-map-viewer/network/network-map.jsx b/src/components/network-map-viewer/network/network-map.jsx index f733cd63..89eda823 100644 --- a/src/components/network-map-viewer/network/network-map.jsx +++ b/src/components/network-map-viewer/network/network-map.jsx @@ -33,6 +33,7 @@ import mapboxgl from 'mapbox-gl'; import 'mapbox-gl/dist/mapbox-gl.css'; import maplibregl from 'maplibre-gl'; import 'maplibre-gl/dist/maplibre-gl.css'; +import { EQUIPMENT_TYPES } from '../utils/equipment-types.js'; // MouseEvent.button https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button const MOUSE_EVENT_BUTTON_LEFT = 0; @@ -124,8 +125,14 @@ const NetworkMap = (props) => { const mapEquipmentsLines = useMemo(() => { return [ - ...(props.mapEquipments?.lines ?? []), - ...(props.mapEquipments?.hvdcLines ?? []), + ...(props.mapEquipments?.lines.map((line) => ({ + ...line, + equipmentType: EQUIPMENT_TYPES.LINE, + })) ?? []), + ...(props.mapEquipments?.hvdcLines.map((hvdcLine) => ({ + ...hvdcLine, + equipmentType: EQUIPMENT_TYPES.HVDC_LINE, + })) ?? []), ]; }, [props.mapEquipments?.hvdcLines, props.mapEquipments?.lines]); @@ -245,7 +252,9 @@ const NetworkMap = (props) => { function renderTooltip() { return ( tooltip && - tooltip.visible && ( + tooltip.visible && + //As of now only base line tooltip has been implemented, to be removed or tweaked once other types of line tooltip are implemented + tooltip.equipmentType === EQUIPMENT_TYPES.LINE && (
{ top: tooltip.pointerY, }} > - {props.renderPopover(tooltip.equipmentId, divRef.current)} + {props.renderPopover( + tooltip.equipmentId, + tooltip.equipmentType, + divRef.current + )}
) ); @@ -417,6 +430,7 @@ const NetworkMap = (props) => { const lineObject = object?.line ?? object; setTooltip({ equipmentId: lineObject?.id, + equipmentType: lineObject?.equipmentType, pointerX: x, pointerY: y, visible: showTooltip,