当前位置: 代码迷 >> 综合 >> 如何在 vue 中使用 photo-sphere-viewer
  详细解决方案

如何在 vue 中使用 photo-sphere-viewer

热度:22   发布时间:2023-12-29 23:38:18.0

官网: photo-sphere-viewer

  • 安装 photo-sphere-viewer依赖
	npm install  photo-sphere-viewer --save-dev 
  • 在你需要用到的页面引入文件
    import PhotoSphereViewer from 'photo-sphere-viewer'import 'photo-sphere-viewer/dist/photo-sphere-viewer.css'

接下来就可以正常使用了

    <div :id="photosphere" class="photosphere"></div>
import PhotoSphereViewer from 'photo-sphere-viewer'
import 'photo-sphere-viewer/dist/photo-sphere-viewer.css'
data() {
    return {
    panoramadata: null,nextPano: {
    },loading_img:  require('../../static/pano/assets/photosphere-logo.gif'),photosphere: 'photosphere',imageLoaded: false,};},

显示

showPhoto() {
    let that = this;this.displayPanoramadata = true;// this.panoramadata this.panoramadata = PhotoSphereViewer({
    container: this.photosphere,panorama: this.nextPano.url,caption: this.nextPano.desc, //描述loading_img: this.loading_img, //默认值为null,在加载时显示的图片的路径。// longitude_range: [-7 * Math.PI / 8, 7 * Math.PI / 8], //可选,移动时每像素经过的经度值。latitude_range: [-3 * Math.PI / 4, 3 * Math.PI / 4], //可选,移动时每像素经过的纬度值。anim_speed: '-2rpm',autoload: true, //可选,默认值为true,true为自动调用全景图,false为在后面加载全景图(通过.load()方法)。fisheye: true,move_speed: 1.1,time_anim: false, //多少毫秒后自动播放size: {
    width: '100%',height: '100%',},navbar: false, //下面导航栏不显示// navbar: [// 'autorotate', 'zoom', 'download', 'markers',// ],markers: (function() {
    let a = that.nextPano.nodes;return a;}())});},

选中全景中标记:

this.panoramadata.on('select-marker', function(marker, dblclick) {
    //marker
});

为防止IOS上切换失败

swichPhoto(url) {
    let that = this;let photosphere = document.getElementById('photosphere');if (this.panoramadata) {
    photosphere.style.opacity = 0;this.imageLoaded = falsethis.panoramadata.setCaption(this.nextPano.desc);this.panoramadata.setPanorama(url, true, true).then(() => {
    this.imageLoaded = truephotosphere.style.opacity = 1;console.log('-------替换图片完成--------')});} else {
    this.showPhoto()}},

添加删除marker

        if(this.panoramadata.hud.markers) {
     //判断当前全景是否有标记:this.panoramadata.hud.clearMarkers();}for(let i = 0; i < this.nextPano.nodes.length; i+=1) {
    let node = this.nextPano.nodes[i];this.panoramadata.addMarker(node);}

复制代码
配置参数

下面是该全景图插件的所有可用配置参数:

panorama:必填参数,全景图的路径。
container:必填参数,放置全景图的div元素。
autoload:可选,默认值为true,true为自动调用全景图,false为在后面加载全景图(通过.load()方法)。
us empdata:可选,默认值为true,如果Photo Sphere Viewer必须读入XMP数据则为true。
default_position:可选,默认值为{},定义默认的位置,及用户看见的第一个点,例如:{long: Math.PI, lat: Math.PI/2}。
min_fov:可选,默认值为30,观察的最小区域,单位degrees,在1-179之间。
max_fov:可选,默认值为90,观察的最大区域,单位degrees,在1-179之间。
allow_user_interactions:可选,默认值为true,设置为false则禁止用户和全景图交互(导航条不可用)。
tilt_up_max:可选,默认值为Math.PI/2,向上倾斜的最大角度,单位radians。
tilt_down_max:可选,默认值为Math.PI/2,向下倾斜的最大角度,单位radians。
zoom_level:可选,默认值为0,默认的缩放级别,值在0-100之间。
long_offset:可选,默认值为 Math.PI/360,mouse/touch移动时每像素经过的经度值。
lat_offset:可选,默认值为 Math.PI/180,mouse/touch移动时每像素经过的纬度值。
time_anim:可选,默认值为2000,全景图在time_anim毫秒后会自动进行动画。(设置为false禁用它)
theta_offset:过时的选项,可选,默认值为1440,自动动画时水平方向的速度。
anim_speed:可选,默认值为2rpm,动画的速度,每秒/分钟多少radians/degrees/revolutions。
navbar:可选值,默认为false。显示导航条。
navbar_style:可选值,默认为{}。导航条的自定义样式。下面是可用的样式列表:
backgroundColor:导航条的背景颜色,默认值为rgba(61, 61, 61, 0.5)。
buttonsColor:按钮的前景颜色,默认值为transparent。
activeButtonsBackgroundColor:按钮激活状态的背景颜色,默认值为rgba(255, 255, 255, 0.1)。
buttonsHeight:按钮的高度,单位像素,默认值为20。
autorotateThickness:autorotate图标的厚度,单位像素,默认值为1。
zoomRangeWidth:缩放的范围,单位显示,默认值50。
zoomRangeThickness:缩放的范围的厚度,单位像素,默认值1。
zoomRangeDisk:缩放范围的圆盘直径,单位像素,默认值为7。
fullscreenRatio:全屏图标的比例,默认值为3/4。
fullscreenThickness:全屏图标的厚度,单位像素,默认值为2。
loading_msg:可选,默认值为Loading…,图片加载时的提示文字。
loading_img:可选,默认值为null,在加载时显示的图片的路径。
size:可选,默认值null,全景图容器的最终尺寸。例如:{width: 500, height: 300}。
onready:可选值,默认值为null。当全景图准备就绪并且第一张图片显示时的回调函数。

  相关解决方案