Skip to content

Commit 8eeaec3

Browse files
bcgov-brwangray-oxd
authored andcommitted
DBC22-1219: use popup ref when icon clicked
DBC22-1219: use popup ref when icon clicked to prevent popup onClick event got triggered.
1 parent c88c797 commit 8eeaec3

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/frontend/src/Components/Map.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export default function MapWrapper({
8484
const hoveredCamera = useRef();
8585
const hoveredEvent = useRef();
8686
const locationPinRef = useRef(null);
87+
const cameraPopupRef = useRef(null);
8788

8889
// States
8990
const [layersOpen, setLayersOpen] = useState(false);
@@ -414,6 +415,11 @@ export default function MapWrapper({
414415
popup.current.getElement().style.top = '40px';
415416

416417
updateClickedCamera(feature);
418+
419+
if (!cameraPopupRef.current) {
420+
cameraPopupRef.current = popup;
421+
}
422+
417423
}
418424
} else {
419425
// if it wasn't a webcam icon, check if it was an event
@@ -753,7 +759,7 @@ export default function MapWrapper({
753759
/>
754760
<div id="popup-content" className="ol-popup-content">
755761
{clickedCamera &&
756-
getCamPopup(clickedCamera, updateClickedCamera, navigate)
762+
getCamPopup(clickedCamera, updateClickedCamera, navigate, cameraPopupRef)
757763
}
758764

759765
{clickedEvent &&

src/frontend/src/Components/map/mapPopup.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,24 @@ function renderCamGroup(camFeature, setClickedCamera) {
4343
return res;
4444
}
4545

46-
export function getCamPopup(camFeature, setClickedCamera, navigate) {
46+
export function getCamPopup(camFeature, setClickedCamera, navigate, cameraPopupRef) {
4747
const rootCamData = camFeature.getProperties();
4848

4949
const camData = !rootCamData.groupIndex ? rootCamData : rootCamData.camGroup[rootCamData.groupIndex];
50+
51+
const handlePopupClick = (e) => {
52+
if (!cameraPopupRef.current) {
53+
navigate(`/cameras/${camData.id}`);
54+
}
55+
else{
56+
cameraPopupRef.current = null;
57+
return;
58+
}
59+
};
60+
5061
return (
5162
<div className="popup popup--camera">
52-
<div onClick={() => navigate(`/cameras/${camData.id}`)}>
63+
<div onClick={handlePopupClick}>
5364
<div className="popup__title">
5465
<p className="bold name">{camData.name}</p>
5566
<p className="bold orientation">{camData.orientation}</p>

0 commit comments

Comments
 (0)