From 6e60344eeb4961f87bd2390d9d480129171aac7e Mon Sep 17 00:00:00 2001 From: Gabriel Dehame Date: Tue, 21 Feb 2023 20:31:45 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20de=20la=20gestion=20des=20changements?= =?UTF-8?q?=20d'etages=20depuis=20la=20carte=20via=20clique=20sur=20escali?= =?UTF-8?q?er/ascenseur=20(pas=20test=C3=A9=20car=20bug=20api/bdd=3F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 2 +- src/Map.js | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/App.js b/src/App.js index 81893dd..5f12f9c 100644 --- a/src/App.js +++ b/src/App.js @@ -121,7 +121,7 @@ export default function App() { return <>
- +
diff --git a/src/Map.js b/src/Map.js index fbc93b6..084f0ea 100644 --- a/src/Map.js +++ b/src/Map.js @@ -140,7 +140,17 @@ function min_max(request) return [minX, maxX, minY, maxY]; } -function newPolygon(element, positions, selectedRoom, callback) +function floorList(connectedFloors, callbackChangeFloor) +{ + let htmlFloorList = []; + for (const floor in connectedFloors) + { + htmlFloorList = [...htmlFloorList,
  • {callbackChangeFloor(floor["id"]);}}> {floor["name"]}
  • ]; + } + return htmlFloorList; +} + +function newPolygon(element, positions, selectedRoom, callbackRoomSelected, callbackChangeFloor) { // Auxiliary function to return the appropriate polygon depending // on wether it is a room, a lift, a staircase or toilets @@ -148,7 +158,7 @@ function newPolygon(element, positions, selectedRoom, callback) if (element["type"] === "S") { // In this case, the room is a staircase so we add a Stairs component - return callback(element["id"])}}> + return callbackRoomSelected(element["id"])}}> {element["id"]}
  • { console.log("escalier"); }}> @@ -165,7 +175,7 @@ function newPolygon(element, positions, selectedRoom, callback) else if (element["type"] === "L") { // In this case the room is a lift so we add a Lift component - return callback(element["id"])}}> + return callbackRoomSelected(element["id"])}}> {element["id"]}
  • { console.log("ascenseur"); }}> @@ -181,7 +191,7 @@ function newPolygon(element, positions, selectedRoom, callback) } else if (element["type"] === "T") { - return callback(element["id"])}}> + return callbackRoomSelected(element["id"])}}> {element["id"]}
  • { console.log("toilettes"); }}> @@ -198,13 +208,13 @@ function newPolygon(element, positions, selectedRoom, callback) else if (element["type"] === "R") { // In this case it is a regular room - return callback(element["id"])}}> + return callbackRoomSelected(element["id"])}}> {element["id"]} } } -function list_polygons(request, center, callback, selectedRoom) +function list_polygons(request, center, callbackRoomSelected, selectedRoom, callbackChangeFloor) { // Main function to calculate the list of polygons (React components) // Taking the request as parameter, the center of the points of the request @@ -221,13 +231,13 @@ function list_polygons(request, center, callback, selectedRoom) // the "Polygon" react-leaflet component return [-(pt["y"] - center[1]) / 25, (pt["x"] - center[0]) / 25]; }); - const pol = newPolygon(element, positions, selectedRoom, callback); + const pol = newPolygon(element, positions, selectedRoom, callbackRoomSelected, callbackChangeFloor); polygons = [...polygons, pol]; } return polygons; } -function buildPols(request, callback, selectedRoom) +function buildPols(request, callbackRoomSelected, selectedRoom, callbackChangeFloor) { // This function just calls the list_polygons one with appropriate parameters (precalculate center) const minMaxXY = min_max(request); @@ -236,11 +246,11 @@ function buildPols(request, callback, selectedRoom) const minY = minMaxXY[2]; const maxY = minMaxXY[3]; const center = [(maxX + minX) / 2, (maxY + minY) / 2]; - const polygons = list_polygons(request, center, callback, selectedRoom); + const polygons = list_polygons(request, center, callbackRoomSelected, selectedRoom, callbackChangeFloor); return polygons; } -function Map({callbackRoomSelected, selectedRoom, floorID}) +function Map({callbackRoomSelected, selectedRoom, floorID, callbackChangeFloor}) { // When the user selects a room on the map, call callbackRoomSelected. // The room that is currently selected is selectedRoom. It is null if no room @@ -264,7 +274,7 @@ function Map({callbackRoomSelected, selectedRoom, floorID}) }, [request, callbackRoomSelected, selectedRoom]); const polygons = createPolygons(request, callbackRoomSelected, selectedRoom); */ - const polygons = buildPols(request, callbackRoomSelected, selectedRoom); + const polygons = buildPols(request, callbackRoomSelected, selectedRoom, callbackChangeFloor); return {polygons}