html - Photo Sphere Viewer on React pure Javascript - Stack Overflow

I am trying to implement Photo Sphere Viewer on my React Component, i already did it with Google Maps A

I am trying to implement Photo Sphere Viewer on my React Component, i already did it with Google Maps API and it worked fine, but i'm using the same technique, no results. If is there any other option to implement 360 Photo Viewer on React (Already used Pannellum, didn't like it, didn't worked) i'm open to suggestions.

/

i got the html code from: .html

<head>
    <meta charset="utf-8" />
    <title>Photo Sphere Viewer</title>
    <meta name="viewport" content="initial-scale=1.0" />
    <script src="./three.min.js"></script>
    <script src="./photo-sphere-viewer.min.js"></script>
    <style>
        html, body {
            margin: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        #container {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div id="container"></div>

    <script>
        var div = document.getElementById('container');
        var PSV = new PhotoSphereViewer({
                panorama: '.jpg',
                container: div,
                time_anim: 3000,
                navbar: true,
                navbar_style: {
                    backgroundColor: 'rgba(58, 67, 77, 0.7)'
                },
            });
    </script>
</body>


*import React from 'react'; 
import '../../index.css';


class ShperePanel extends React.Component{

    ponentDidMount() {
        this.renderSphere();
      }

    renderSphere = () => {
        loadScript('photo-sphere-viewer.min.js');
        loadScript('three.min.js');


        window.initSphere = this.initSphere;

      }
      initSphere = () => {
        const PVS = new window.PhotoSphereViewer({ 
        container: document.getElementByid('viewer'),
        panorama: '.jpg',
        time_anim: 3000,
        navbar: true,
        navbar_style: {
            backgroundColor: 'rgba(58, 67, 77, 0.7)'
        }
    })
      }
render(){
    return(
    <div id="viewer"> </div>
    );
}

}
export default ShperePanel

function loadScript(url) {
    var index = window.document.getElementsByTagName('script')[0];
    var script = window.document.createElement('script');
    script.src = url;
    script.async = true;
    script.defer = true;
    index.parentNode.insertBefore(script, index); 
  }*

i would like to get something like this.

When i try to import the scripts(three.min.js, photo-sphere-viewer.min.js), with the "import from " syntax, directly, i get an error "PhotoSphereViewer" undefined.

I am trying to implement Photo Sphere Viewer on my React Component, i already did it with Google Maps API and it worked fine, but i'm using the same technique, no results. If is there any other option to implement 360 Photo Viewer on React (Already used Pannellum, didn't like it, didn't worked) i'm open to suggestions.

https://photo-sphere-viewer.js/

i got the html code from: https://github./JeremyHeleine/Photo-Sphere-Viewer/blob/master/examples/example.html

<head>
    <meta charset="utf-8" />
    <title>Photo Sphere Viewer</title>
    <meta name="viewport" content="initial-scale=1.0" />
    <script src="./three.min.js"></script>
    <script src="./photo-sphere-viewer.min.js"></script>
    <style>
        html, body {
            margin: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        #container {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div id="container"></div>

    <script>
        var div = document.getElementById('container');
        var PSV = new PhotoSphereViewer({
                panorama: 'http://tassedecafe/wp-content/uploads/2013/01/parc-saint-pierre-amiens.jpg',
                container: div,
                time_anim: 3000,
                navbar: true,
                navbar_style: {
                    backgroundColor: 'rgba(58, 67, 77, 0.7)'
                },
            });
    </script>
</body>


*import React from 'react'; 
import '../../index.css';


class ShperePanel extends React.Component{

    ponentDidMount() {
        this.renderSphere();
      }

    renderSphere = () => {
        loadScript('photo-sphere-viewer.min.js');
        loadScript('three.min.js');


        window.initSphere = this.initSphere;

      }
      initSphere = () => {
        const PVS = new window.PhotoSphereViewer({ 
        container: document.getElementByid('viewer'),
        panorama: 'http://tassedecafe/wp-content/uploads/2013/01/parc-saint-pierre-amiens.jpg',
        time_anim: 3000,
        navbar: true,
        navbar_style: {
            backgroundColor: 'rgba(58, 67, 77, 0.7)'
        }
    })
      }
render(){
    return(
    <div id="viewer"> </div>
    );
}

}
export default ShperePanel

function loadScript(url) {
    var index = window.document.getElementsByTagName('script')[0];
    var script = window.document.createElement('script');
    script.src = url;
    script.async = true;
    script.defer = true;
    index.parentNode.insertBefore(script, index); 
  }*

i would like to get something like this.

When i try to import the scripts(three.min.js, photo-sphere-viewer.min.js), with the "import from " syntax, directly, i get an error "PhotoSphereViewer" undefined.

Share Improve this question edited Feb 4, 2021 at 3:16 neubert 16.8k26 gold badges135 silver badges252 bronze badges asked May 24, 2019 at 19:53 Hugo GuerreroHugo Guerrero 1391 gold badge4 silver badges9 bronze badges 2
  • Do you use webpack? If yes. Then also please show how do you import those packages. – Talgat Saribayev Commented May 24, 2019 at 20:15
  • Yes, i used create-react-app, those are installed and imported by default, right? – Hugo Guerrero Commented Jun 25, 2019 at 2:59
Add a ment  | 

2 Answers 2

Reset to default 5

React 16.8 version with useEffect hook:

import React, { useEffect } from 'react';
import PhotoSphereViewer from 'photo-sphere-viewer';

export default function Photo(props) {
  const sphereElementRef = React.createRef();
  const { src } = props;

  useEffect(() => {
    const shperePlayerInstance = PhotoSphereViewer({
      container: sphereElementRef.current,
      panorama: src,
      ... // other options
    });    

    // unmount ponent instructions
    return () => {
      shperePlayerInstance.destroy();
    };
  }, [src]); // will only be called when the src prop gets updated


  return (
    <div ref={sphereElementRef}/>
  );
}

I had similar problem and this is how I solve it:

npm install --save photo-sphere-viewer

and ponent look like this:

import React, { Component } from 'react'
import * as Sphere from "photo-sphere-viewer";
import "photo-sphere-viewer/dist/photo-sphere-viewer.min.css"


export default class SphereComponent extends Component {
    constructor(props) {
        super(props)
        this.divStyle = {
          width: '100%',
          height: '600px'
        };
        this.sphereDiv = element => {
            this.photoSphereViewer = element;
        };
        this.sphereDiv.appendChild = (elem) => {
            this.subDiv.appendChild(elem)
        }
    }

    ponentDidMount() {
        const PVS = Sphere({
            parent: this,
            container: this.sphereDiv,
            panorama: "https://photo-sphere-viewer.js/assets/Bryce-Canyon-National-Park-Mark-Doliner.jpg",
            navbar: [
                'autorotate',
                'zoom',
                'fullscreen'
            ]
        })
    }

    render() {
        return <div style={this.divStyle} ref={this.sphereDiv} id="viewer"><div ref={node => this.subDiv = node} style={this.divStyle}></div></div>
    }
}

That's it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744609470a4583674.html

相关推荐

  • html - Photo Sphere Viewer on React pure Javascript - Stack Overflow

    I am trying to implement Photo Sphere Viewer on my React Component, i already did it with Google Maps A

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信