gpt4 book ai didi

javascript - React 纯 Javascript 上的 Photo Sphere 查看器

转载 作者:行者123 更新时间:2023-11-30 07:49:17 25 4
gpt4 key购买 nike

我正在尝试在我的 React 组件上实现 Photo Sphere Viewer,我已经使用 Google Maps API 实现了它并且运行良好,但我使用的是相同的技术,但没有结果。如果有任何其他选项可以在 React 上实现 360 度照片查看器(已经使用过 Pannellum,不喜欢它,没有用)我愿意接受建议。

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

我的 html 代码来自:https://github.com/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.org/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{

componentDidMount() {
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.org/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);
}*

我想得到这样的东西。

当我尝试使用“导入自”语法直接导入脚本(three.min.js、photo-sphere-viewer.min.js)时,我收到错误“PhotoSphereViewer”未定义。

最佳答案

带有 useEffect 钩子(Hook)的 React 16.8 版本:

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 component instructions
return () => {
shperePlayerInstance.destroy();
};
}, [src]); // will only be called when the src prop gets updated


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

关于javascript - React 纯 Javascript 上的 Photo Sphere 查看器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56298812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com