Parcourir la source

Fixed a bug in the marked points logic

Kirk Trombley il y a 5 ans
Parent
commit
9320632c69
1 fichiers modifiés avec 18 ajouts et 10 suppressions
  1. 18 10
      client/src/components/screens/RoundSummary/useMarkedPoints.jsx

+ 18 - 10
client/src/components/screens/RoundSummary/useMarkedPoints.jsx

@@ -36,7 +36,7 @@ const openMapInNewTab = ({ lat, lng }) => {
 }
 
 const makeMarker = (map, position, title, icon) => {
-  const marker = new google.maps.Marker({ 
+  const marker = new google.maps.Marker({
     clickable: true,
     map,
     position,
@@ -51,19 +51,27 @@ const makeMarker = (map, position, title, icon) => {
 
 export default (mapRef, selectedPoint, targetPoint) => {
   useEffect(() => {
-    const selectedMarker = makeMarker(mapRef.current, selectedPoint, "Selected", questionIcon);
+    const selectedMarker = selectedPoint
+      ? makeMarker(mapRef.current, selectedPoint, "Selected", questionIcon)
+      : null;
     const targetMarker = makeMarker(mapRef.current, targetPoint, "Goal", flagIcon);
 
-    const line = new google.maps.Polyline({
-      path: [ selectedPoint, targetPoint ],
-      map: mapRef.current,
-      ...lineSettings,
-    });
+    const line = selectedPoint
+      ? new google.maps.Polyline({
+        path: [ selectedPoint, targetPoint ],
+        map: mapRef.current,
+        ...lineSettings,
+      })
+      : null;
 
-    return () => { 
-      line.setMap(null); 
+    return () => {
+      if (line) {
+        line.setMap(null);
+      }
       targetMarker.setMap(null);
-      selectedMarker.setMap(null);
+      if (selectedMarker) {
+        selectedMarker.setMap(null);
+      }
     }
   }, [mapRef, selectedPoint, targetPoint]);
 }