diff --git a/assets/konva/app.js b/assets/konva/app.js index 806ccfb..397a7da 100644 --- a/assets/konva/app.js +++ b/assets/konva/app.js @@ -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());