"use client"; import React, { useEffect, useRef, useState } from 'react'; interface PanoramaViewerProps { imageUrl: string; className?: string; } declare global { interface Window { pannellum: any; } } const PanoramaViewer: React.FC = ({ imageUrl, className }) => { const viewerRef = useRef(null); const pannellumInstance = useRef(null); const [error, setError] = useState(null); useEffect(() => { // Check if pannellum is loaded const initViewer = () => { if (!window.pannellum) { console.warn("Pannellum not loaded yet, retrying..."); setTimeout(initViewer, 500); return; } if (viewerRef.current && imageUrl) { // Destroy existing instance if it exists if (pannellumInstance.current) { try { pannellumInstance.current.destroy(); } catch (e) { console.warn("Error destroying pannellum instance:", e); } } try { // Initialize Pannellum pannellumInstance.current = window.pannellum.viewer(viewerRef.current, { type: 'equirectangular', panorama: imageUrl, autoLoad: true, showControls: true, compass: false, // Set to false by default for cleaner look mouseZoom: true, hfov: 100, vaov: 180, haov: 360, crossOrigin: "anonymous" }); setError(null); } catch (err: any) { console.error("Pannellum initialization error:", err); setError(err.message); } } }; initViewer(); return () => { if (pannellumInstance.current) { try { pannellumInstance.current.destroy(); } catch (e) { } } }; }, [imageUrl]); if (error) { return (

Error loading viewer: {error}
Image might be too large or inaccessible.

); } return (
); }; export default PanoramaViewer;