fix: use section ID for reliable beacon positioning
- Add sectionId to SearchResult interface - Search handler now looks up section by ID first - Falls back to code/name lookup for backwards compatibility - Fixes beacon offset in Room B (duplicate section codes)
This commit is contained in:
parent
5f774bb873
commit
56f134f7f7
2 changed files with 20 additions and 4 deletions
|
|
@ -9,6 +9,7 @@ interface SearchResult {
|
|||
sublabel: string;
|
||||
roomName: string;
|
||||
sectionCode: string;
|
||||
sectionId: string; // For reliable section lookup
|
||||
position: {
|
||||
roomX: number;
|
||||
roomY: number;
|
||||
|
|
@ -53,6 +54,7 @@ export function PlantSearch({ floorData, onSelectResult, onHighlightResults }: P
|
|||
sublabel: `${pos.plant.strain || 'Unknown'} • ${pos.plant.stage || 'N/A'}`,
|
||||
roomName: room.name,
|
||||
sectionCode: section.code || section.name,
|
||||
sectionId: section.id, // Added for reliable lookup
|
||||
position: {
|
||||
roomX: room.posX,
|
||||
roomY: room.posY,
|
||||
|
|
|
|||
|
|
@ -233,10 +233,24 @@ export default function Facility3DViewerPage() {
|
|||
const handleSearchSelect = useCallback((result: any) => {
|
||||
if (!floorData) return;
|
||||
|
||||
// Find the actual section to use grid-based position calculation
|
||||
const room = floorData.rooms.find(r => r.name === result.roomName);
|
||||
const section = room?.sections.find(s => (s.code || s.name) === result.sectionCode);
|
||||
if (!section) return;
|
||||
// Find the section - prefer ID lookup for reliability, fall back to code/name
|
||||
let section: Section3D | undefined;
|
||||
for (const room of floorData.rooms) {
|
||||
if (result.sectionId) {
|
||||
section = room.sections.find(s => s.id === result.sectionId);
|
||||
} else {
|
||||
// Fallback: must match both room and section code
|
||||
if (room.name === result.roomName) {
|
||||
section = room.sections.find(s => (s.code || s.name) === result.sectionCode);
|
||||
}
|
||||
}
|
||||
if (section) break;
|
||||
}
|
||||
|
||||
if (!section) {
|
||||
console.warn('[handleSearchSelect] Could not find section for result:', result);
|
||||
return;
|
||||
}
|
||||
|
||||
const { x, y, z } = calculatePlantCoords(
|
||||
section,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue