feat: move sensors in room when dragging

This commit is contained in:
2026-05-14 17:30:29 +02:00
parent 52605f1390
commit ff9329b823
+24
View File
@@ -188,6 +188,18 @@ roomsLayer.on('dragmove', (e) => {
if (_dimRoom && _dimRoom.id === draggedRoom.id) {
_showDimensions(_dimRoom, node.x(), node.y());
}
// Move sensors belonging to this room so they keep their relative position.
const newRoomX = node.x() / PPM;
const newRoomY = node.y() / PPM;
sensors.forEach(s => {
if (s.room_id !== roomId || s.floor_x == null) return;
const sg = sensorsLayer.findOne(`#sensor-${s.id}`);
if (!sg) return;
sg.x((newRoomX + s.floor_x) * PPM);
sg.y((newRoomY + s.floor_y) * PPM);
});
sensorsLayer.batchDraw();
});
// ---------------------------------------------------------------------------
@@ -298,6 +310,18 @@ function _onRoomDragEnd(room, group) {
});
}
// Reposition sensor groups to reflect any normalization shift.
sensors.forEach(s => {
if (s.floor_x == null) return;
const r = rooms.find(r => r.id === s.room_id);
if (!r) return;
const sg = sensorsLayer.findOne(`#sensor-${s.id}`);
if (!sg) return;
sg.x((r.x + s.floor_x) * PPM);
sg.y((r.y + s.floor_y) * PPM);
});
sensorsLayer.batchDraw();
// Keep dimensions visible at the final position after normalization.
if (_dimRoom && _dimRoom.id === room.id) {
_showDimensions(room, group.x(), group.y());