PSV Visible Range 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>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/photo-sphere-viewer.css">
<script src="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/photo-sphere-viewer.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/plugins/visible-range.js"></script>
<div id="photosphere"></div>

CSS

html, body, #photosphere {
  margin: 0;
  width: 100%;
  height: 100%;
}

.custom-button {
  font-family: sans-serif;
  width: auto;
}

JavaScript

const viewer = new PhotoSphereViewer.Viewer({
  panorama: 'https://photo-sphere-viewer-data.netlify.app/assets/sphere-cropped.jpg',
  container: 'photosphere',
  loadingImg: 'https://photo-sphere-viewer.js.org/assets/photosphere-logo.gif',
  caption: 'Parc national du Mercantour <b>&copy; Damien Sorel</b>',
  touchmoveTwoFingers: true,
  mousewheelCtrlKey: true,
  defaultZoomLvl: 30,

  navbar: [
    'autorotate',
    // custom buttons to clear and set the range
      {
        content  : 'Clear range',
        className: 'custom-button',
        onClick  : () => {
          visibleRangePlugin.setLongitudeRange(null);
          visibleRangePlugin.setLatitudeRange(null);
        },
      },
      {
        content  : 'Set custom range',
        className: 'custom-button',
        onClick  : () => {
          visibleRangePlugin.setLongitudeRange([-Math.PI / 2, Math.PI / 2]);
          visibleRangePlugin.setLatitudeRange([-Math.PI / 3, Math.PI / 3]);
        },
      },
      {
        content  : 'Set range from panoData',
        className: 'custom-button',
        onClick  : () => {
          visibleRangePlugin.setRangesFromPanoData();
        },
      },
    'caption',
    'fullscreen',
  ],

  plugins: [
    [PhotoSphereViewer.VisibleRangePlugin, {
      usePanoData: true,
    }],
  ],
});

const visibleRangePlugin = viewer.getPlugin(PhotoSphereViewer.VisibleRangePlugin);