mirror of
https://gitlab.aliens-lyon.fr/encartes/web-interface.git
synced 2026-03-17 22:51:04 +01:00
Factorise code
This commit is contained in:
parent
6bef1fa4c7
commit
878f0fd50a
64
src/Map.js
64
src/Map.js
@ -184,46 +184,44 @@ function newPolygon(element, positions, selectedRoom, callbackRoomSelected, call
|
||||
// as well as a callback to display the room informations when the user clicks on the room
|
||||
// and for S or L, we add a Popup with the list of connected floors and possibility to load the
|
||||
// map of a connected floor
|
||||
const color = selectedRoom === element["id"] ? 'red' : 'grey';
|
||||
if (element["type"] === "S") {
|
||||
// In this case, the room is a staircase so we add a Stairs component
|
||||
return <Polygon positions={positions} key={element["id"] + color} color={color} evenHandlers={{ click: () => callbackRoomSelected(element["id"]) }}>
|
||||
<Tooltip>{roomNameList(element["names"])}</Tooltip>
|
||||
<Stairs position={polygonCenter(positions)} size={logoSize(positions)} body={<Popup>
|
||||
{floorList(element["connectedFloors"], callbackChangeFloor)}
|
||||
</Popup>
|
||||
const color = selectedRoom === element['id'] ? 'red' : 'grey';
|
||||
|
||||
if (element['type'] === 'C') { // Corridor
|
||||
return <Polygon positions={positions} key={element['id'] + color} color={'peru'} />
|
||||
}
|
||||
|
||||
var content = <></>
|
||||
if (element['type'] === 'S') { // Stair
|
||||
content = <Stairs
|
||||
position={polygonCenter(positions)}
|
||||
size={logoSize(positions)}
|
||||
body={<Popup>
|
||||
{floorList(element['connectedFloors'], callbackChangeFloor)}
|
||||
</Popup>}
|
||||
/>
|
||||
</Polygon>
|
||||
}
|
||||
else if (element["type"] === "L") {
|
||||
// In this case the room is a lift so we add a Lift component
|
||||
return <Polygon positions={positions} key={element["id"] + color} color={color} evenHandlers={{ click: () => callbackRoomSelected(element["id"]) }}>
|
||||
<Tooltip>{roomNameList(element["names"])}</Tooltip>
|
||||
<Lift position={polygonCenter(positions)} size={logoSize(positions)} body={<Popup>
|
||||
{floorList(element["connectedFloors"], callbackChangeFloor)}
|
||||
</Popup>
|
||||
}
|
||||
} else if (element['type'] === 'L') { // Lift
|
||||
content = <Lift
|
||||
position={polygonCenter(positions)}
|
||||
size={logoSize(positions)}
|
||||
body={<Popup>
|
||||
{floorList(element['connectedFloors'], callbackChangeFloor)}
|
||||
</Popup>}
|
||||
/>
|
||||
</Polygon>
|
||||
} else if (element['type'] === 'T') { // Toilets
|
||||
content = <Toilet position={polygonCenter(positions)} size={logoSize(positions)} />
|
||||
}
|
||||
else if (element["type"] === "T") {
|
||||
return <Polygon positions={positions} key={element["id"] + color} color={color} evenHandlers={{ click: () => callbackRoomSelected(element["id"]) }}>
|
||||
|
||||
|
||||
return <Polygon
|
||||
positions={positions}
|
||||
key={element["id"] + color}
|
||||
color={color}
|
||||
eventHandlers={{ click: () => callbackRoomSelected(element["id"]) }}
|
||||
>
|
||||
<Tooltip>{roomNameList(element["names"])}</Tooltip>
|
||||
<Toilet position={polygonCenter(positions)} size={logoSize(positions)} />
|
||||
{content}
|
||||
</Polygon>
|
||||
}
|
||||
else if (element["type"] === "R") {
|
||||
// In this case it is a regular room
|
||||
return <Polygon positions={positions} key={element["id"] + color} color={color} eventHandlers={{ click: () => callbackRoomSelected(element["id"]) }}>
|
||||
<Tooltip>{roomNameList(element["names"])}</Tooltip>
|
||||
</Polygon>
|
||||
}
|
||||
else if (element["type"] === "C") {
|
||||
// In this case it is a corridor
|
||||
return <Polygon positions={positions} key={element["id"] + color} color={"peru"} />
|
||||
}
|
||||
}
|
||||
|
||||
function list_polygons(request, center, callbackRoomSelected, selectedRoom, callbackChangeFloor) {
|
||||
// Main function to calculate the list of polygons (React components)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user