Vue 全景图 photo-sphere-viewer的使用以及改变图片

1.安装 photo-sphere-viewer依赖

npm install photo-sphere-viewer --save

2.在你需要用到的页面引入文件

import PhotoSphereViewer from 'photo-sphere-viewer'
import 'photo-sphere-viewer/dist/photo-sphere-viewer.css'

3.使用

<div id="viewer"></div>
data() {
   return {
     imgUrl: require('../../assets/panorama-image/noImage.png')
  }
},
methods: {
  initPhotoSphere() {
    this.PSV = PhotoSphereViewer({
      container: document.getElementById('viewer'),
      panorama: this.imgUrl,
      size: {
        width: '100%',
        height: screen.availHeight
      },
      // caption: '鸟瞰图',
      caption: ' ',
      time_anim: false,
      default_long: 1.4441088145446443,
      default_lat: 0.0800613513013615,
      sphere_correction: {pan: 30.01, tilt: 0, roll: 0},
      // max_fov: 100, // 最大缩放值
      // min_fov: 99, // 最小缩放值
      default_fov: 100, // 默认缩放值,在1-179之间
      // latitude_range: [0,0],//禁止上下滑动
      // mousewheel: false, // 禁止鼠标滚轮缩放
      // navbar: false,
      navbar: [
        'autorotate',
        'zoom',
        'markers',
        'caption',
        'fullscreen'
      ],
      theta_offset: 1000, // 旋转速度
      // markers: this.markersData
    })
  }
}

兼容各端切换图片

// 兼容pc和安卓
if (this.PSV) {
  this.PSV.destroy()
}
this.$nextTick(() => {
  this.initPhotoSphere()
})


// 兼容ios  Cannot load image的报错
if (this.PSV) {
  this.PSV.setPanorama(this.imgUrl, true, true)
} else {
  this.initPhotoSphere()
}


// 兼容大频率切换图片,声明一个imageLoaded控制PSVError: Loading already in progress
if (this.PSV) {
  this.imageLoaded = false
  console.log(this.imageLoaded)
  this.PSV.setPanorama(this.imgUrl, true, true).then(() => {
  this.imageLoaded = true
  console.log('-------替换图片完成--------')
});
} else {
  this.initPhotoSphere()
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 `vue-photo-sphere-viewer` 库来集成 `photo-sphere-viewer` 到 Vue.js 4 中,然后在组件中使用这个库的 API 来实现图片切换。具体步骤如下: 1. 安装 `vue-photo-sphere-viewer` 库: ```bash npm install vue-photo-sphere-viewer --save ``` 2. 在组件中引入 `vue-photo-sphere-viewer` 库: ```javascript import PhotoSphereViewer from 'vue-photo-sphere-viewer'; import 'photo-sphere-viewer/dist/photo-sphere-viewer.css'; ``` 3. 在模板中使用 `PhotoSphereViewer` 组件,并绑定图片路径和其他属性: ```html <template> <div> <photo-sphere-viewer :panoramaUrl="panoramaUrl" :defaultLongitud="defaultLongitud" :defaultLatitud="defaultLatitud" :defaultZoom="defaultZoom" :size="size" :minZoom="minZoom" :maxZoom="maxZoom" @ready="onReady" ></photo-sphere-viewer> </div> </template> ``` 其中,`panoramaUrl` 是图片路径,`defaultLongitud`、`defaultLatitud` 和 `defaultZoom` 是初始位置和缩放级别,`size` 是全景图像素大小,`minZoom` 和 `maxZoom` 是缩放级别的最小值和最大值。 4. 在组件的 `methods` 中定义 `onReady` 方法来获取 `PhotoSphereViewer` 实例,并调用 `setPanorama` 方法来切换图片: ```javascript methods: { onReady(viewer) { this.viewer = viewer; }, switchImage(imagePath) { this.viewer.setPanorama(imagePath); }, } ``` 然后你可以在组件的其他方法中调用 `switchImage` 方法来切换图片。 ```javascript this.switchImage('/path/to/another/image.jpg'); ``` 注意,这里的 `vue-photo-sphere-viewer` 库只是 `photo-sphere-viewer` 的 Vue.js 封装,你还需要在项目中引入 `photo-sphere-viewer` 库本身。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值