-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPanoramaViewer.tsx
142 lines (127 loc) · 3.22 KB
/
PanoramaViewer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use client';
import React, { useEffect, useRef } from "react";
import "./pannellum/css/pannellum.css";
import "./pannellum/css/style-textInfo.css";
import "./pannellum/js/libpannellum.js";
import "./pannellum/js/pannellum.js";
import "./pannellum/js/RequestAnimationFrame";
import "./styles.css"
export interface PanoramaViewerProps {
imagePath: string;
hotSpots?: HotspotProps[];
autoLoad?: boolean;
autoRotate?: number;
compass?: boolean;
showControls?: boolean;
width?: string;
height?: string;
haov?: number;
vaov?: number;
hotSpotDebug?: boolean;
}
export interface HotspotProps {
pitch: number;
yaw: number;
type: string;
text?: string;
URL?: string;
cssClass?: string;
onClick?: Function;
createTooltipFunc?: Function;
}
interface ViewerOptions {
type: string;
panorama: string;
autoLoad?: boolean;
autoRotate?: number;
hotSpotDebug?: boolean;
yaw?: number;
pitch?: number;
hfov?: number;
vaov?: number;
minHfov?: number;
maxHfov?: number;
minPitch?: number;
maxPitch?: number;
showControls?: boolean;
showZoomCtrl?: boolean;
keyboardZoom?: boolean;
mouseZoom?: boolean;
showFullscreenCtrl?: boolean;
compass?: boolean;
compassOffset?: [number, number];
hotSpots?: PanenellumHotSpot[];
}
interface PanenellumHotSpot {
pitch: number;
yaw: number;
type: string;
text?: string;
URL?: string;
cssClass?: string;
createTooltipFunc?: Function;
clickHandlerFunc?: Function;
}
const defaultConfig: ViewerOptions = {
type: 'equirectangular',
panorama: '',
autoLoad: true,
autoRotate: 0,
hotSpotDebug: false,
yaw: 0,
pitch: 0,
hfov: 100,
vaov: 75,
minHfov: 50,
maxHfov: 120,
minPitch: -90,
maxPitch: 90,
showZoomCtrl: true,
keyboardZoom: true,
mouseZoom: true,
showFullscreenCtrl: true,
compass: true,
compassOffset: [10, 10],
hotSpots: [],
};
const PanoramaViewer: React.FC<PanoramaViewerProps> = ({
imagePath,
hotSpots,
autoLoad,
autoRotate,
compass,
showControls,
width,
height,
hotSpotDebug
}) => {
const viewerRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
let viewer: pannellum.viewer | null = null;
// Initialize the Pannellum viewer
if (viewerRef.current) {
viewer = pannellum.viewer(viewerRef.current, {
type: 'equirectangular',
panorama: imagePath,
autoLoad: !!autoLoad,
autoRotate: autoRotate || 0,
hotSpotDebug: !!hotSpotDebug,
compass: !!compass,
showControls: !!showControls,
hotSpots: hotSpots && hotSpots.map(hotSpot => ({ ...hotSpot, clickHandlerFunc: hotSpot.onClick })),
});
}
// Clean up the viewer on component unmount
return () => {
if (viewer) {
viewer.destroy();
}
};
}, [imagePath, hotSpots]);
const divStyle = {
width: width || "100%",
height: height || "100%",
};
return <div ref={viewerRef} style={divStyle} />;
};
export default PanoramaViewer;