PSV Settings Demo
by mistic100
HTML
<script src="https://cdn.jsdelivr.net/npm/uevent@2/browser.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/photo-sphere-viewer.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/photo-sphere-viewer.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/plugins/settings.css">
<script src="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/plugins/settings.js"></script>
<div id="photosphere"></div>
CSS
html, body, #photosphere {
margin: 0;
width: 100%;
height: 100%;
}
JavaScript
const viewer = new PhotoSphereViewer.Viewer({
panorama: 'https://photo-sphere-viewer-data.netlify.app/assets/sphere.jpg',
container: 'photosphere',
caption: 'Parc national du Mercantour <b>© Damien Sorel</b>',
loadingImg: 'https://photo-sphere-viewer.js.org/assets/photosphere-logo.gif',
touchmoveTwoFingers: true,
mousewheelCtrlKey: true,
plugins: [
PhotoSphereViewer.SettingsPlugin,
],
});
const settings = viewer.getPlugin(PhotoSphereViewer.SettingsPlugin);
let currentToggle = true;
let currentOption = 'option-a';
settings.addSetting({
id : 'custom-toggle-setting',
label : 'Toggle setting',
type : 'toggle',
active: () => currentToggle,
toggle: () => currentToggle = !currentToggle,
});
settings.addSetting({
id : 'custom-options-setting',
label : 'Options setting',
type : 'options',
current: () => currentOption,
options: () => ([
{ id: 'option-a', label: 'Option A' },
{ id: 'option-b', label: 'Option B' },
]),
apply : (option) => currentOption = option,
});