diff --git a/src/App.js b/src/App.js index 5f12f9c..77756d5 100644 --- a/src/App.js +++ b/src/App.js @@ -42,8 +42,8 @@ function ChangeFloor({ currentFloor, callbackFloorChanged }) { fullWidth > Monod - Premier étage - Monod - Troisième étage - Monod - Quatrième étage + Monod - Troisième étage + Monod - Quatrième étage diff --git a/src/Map.js b/src/Map.js index 80cec2d..45b3da5 100644 --- a/src/Map.js +++ b/src/Map.js @@ -140,10 +140,14 @@ function min_max(request) function floorList(connectedFloors, callbackChangeFloor) { + // Returns under html format a list of floors connected + // listed in connectedFloors let htmlFloorList = []; for (const floor in connectedFloors) { - htmlFloorList = [...htmlFloorList,
  • {callbackChangeFloor(floor["id"]);}}> {floor["name"]}
  • ]; + htmlFloorList = [...htmlFloorList,
  • {callbackChangeFloor(connectedFloors[floor]);}}> + {connectedFloors[floor]} +
  • ]; } return htmlFloorList; } @@ -159,7 +163,7 @@ function newPolygon(element, positions, selectedRoom, callbackRoomSelected, call return callbackRoomSelected(element["id"])}}> {element["id"]} - {floorList(element["connexions"], callbackChangeFloor)} + {floorList(element["connectedFloors"], callbackChangeFloor)} } /> @@ -171,7 +175,7 @@ function newPolygon(element, positions, selectedRoom, callbackRoomSelected, call return callbackRoomSelected(element["id"])}}> {element["id"]} - {floorList(element["connexions"], callbackChangeFloor)} + {floorList(element["connectedFloors"], callbackChangeFloor)} } /> @@ -205,7 +209,8 @@ function list_polygons(request, center, callbackRoomSelected, selectedRoom, call const element = request[ind]; // element can be a room, a lift, a staircase or toilets const positions = (element["surface"]).map((pt) => { - // This function rotates and recenters de the map (should not be necessary once the real data are gathered) + // This function rotates and recenters de the map (should not be necessary once the real data are gathered and + // only works for third floor) // It also changes the objects into lists of two coordinates to make it accepted by the "positions" attribute of // the "Polygon" react-leaflet component return [-(pt["y"] - center[1]) / 25, (pt["x"] - center[0]) / 25]; @@ -237,13 +242,16 @@ function Map({callbackRoomSelected, selectedRoom, floorID, callbackChangeFloor}) const [loading, setLoading] = useState(true); const [floor, setFloor] = useState(null); const [error, setError] = useState(null); + // We use the useEffect hook to fetch the data to build the Map useEffect(() => { fetch("https://encartes.aliens-lyon.fr/api/map/get_floor/"+floorID) .then(response => response.json()) .then(data => {setLoading(false); setFloor(data)}) .catch((error) => {setError("API unreachable");}); - }, []); + }, [floorID]); + // We distinguish wether to print an error, a loading message + // or the map if we got the answer if (error != null) { return