Vue3 + Photo-sphere-viewer 全景
Photo Sphere Viewer是一款基于Three.js的360X180度全景图预览js插件。该js插件可以360度旋转查看全景图,也可以上下180度查看图片。使用该插件的唯一要求是浏览器支持canvas或WebGL。
这只是一个简单的全景图,我们还可以在全景图上面不同位置添加标注,修改、删除标注等操作。
一、插件引入
1、npm 安装
npm install phoyo-sphere-viewer
2、直接导入
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/photo-sphere-viewer.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/three/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/uevent@2/browser.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/photo-sphere-viewer.min.js"></script>
但是在此处,个人建议使用 npm 进行安装。
二、全景图的基本使用
1、插件引入
import { Viewer } from 'photo-sphere-viewer' // 引入插件
import 'photo-sphere-viewer/dist/photo-sphere-viewer.css' //引入CSS样式
2、创建容器
<div id="viewer"></div>
3、正式使用
// 全景视图
let panoramaViewer = null
// 全景图初始化
const initViewer = async function () {panoramaViewer = new Viewer({container: document.querySelector('#viewer'), // 容器panorama: img, // 全景图片地址navbar: ['autorotate','zoom','caption','fullscreen'],plugins: [], // 标记点size: {width: '100%',height: '100%'}})
}onBeforeMount(() => {initViewer()
})
4、多张全景图切换使用
在切换使用其他全景图之前,首先要注意销毁之前的全景图,然后在重新初始化新的全景图。
panoramaViewer.destroy() // 销毁全景图
三、全景图标注的使用
1、插件引入
import * as Marker from 'photo-sphere-viewer/dist/plugins/markers' // 引入插件
import 'photo-sphere-viewer/dist/plugins/markers.css' // 引入标注样式
2、基本使用
// 全景视图
let panoramaViewer = null
// 全景图初始化
const initViewer = async function () {// panoramaViewer.destroy()panoramaViewer = new Viewer({container: document.querySelector('#viewer'),panorama: img, // 全景图片地址navbar: ['autorotate','zoom','caption','fullscreen'],// 标记点plugins: [[Marker, {markers: [{id: '1',imageLayer: img,width: 120,height: 94,longitude: -0.22188456912854737,latitude: 6.1139406999543375,tooltip: 'test-1',content: '<div class="tooltip-content"><h3>test-1</h3><p>描述描述描述</p></div>'}]}]],size: {width: '100%',height: '100%'}})
}onBeforeMount(() => {initViewer()
})
3、标注比较高级使用
// 全景视图
let panoramaViewer = null
// 注标列表
const markerList = ref([])// 全景图初始化
const initViewer = async function () {panoramaViewer = new Viewer({container: document.querySelector('#viewer'),panorama: img, // 全景图片地址navbar: ['autorotate','zoom','caption','fullscreen'],// 标记点plugins: [[Marker.MarkersPlugin]],size: {width: '100%',height: '100%'}})markersPlugin = panoramaViewer.getPlugin(Marker.MarkersPlugin)readyEvents()
}onBeforeMount(() => {initViewer()
})// 全景图加载完毕
const readyEvents = function () {// 加载完毕panoramaViewer.once('ready', () => {// 初始化标注坐标initMarkers()})// 全景图点击事件panoramaViewer.on('click', (e, data) => {// console.log(`${data.rightclick ? 'right ' : ''}clicked at longitude: ${data.longitude} latitude: ${data.latitude}`)})// 选中标注事件markersPlugin.on('select-marker', (e, marker) => {// console.log('选中标注事件')})
}// 初始化标注坐标
const initMarkers = async function () {markersPlugin.clearMarkers()markerList.value.forEach(markerItem => {const { latitude, longitude, markerId, title, style } = markerItemmarkersPlugin.addMarker({longitude: longitude,latitude: latitude,width: 20,height: 20,id: markerId,data: markerItem})})
}
四、Photo-Sphere-Viewer常用的属性
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。当全景图准备就绪并且第一张图片显示时的回调函数。
五、参考文章
photo-sphere-viewe 官网:https://photo-sphere-viewer.js.org/
vue + photo-sphere-viewer 渲染全景图片:https://blog.csdn.net/qq_32051663/article/details/120955999
photo-sphere-viewer 中文文档:https://blog.csdn.net/weixin_42752574/article/details/122243459
Vue3 + Photo-sphere-viewer 全景相关推荐
- vue与单页面 使用Photo Sphere Viewer创建vr 360全景示例代码
图片资料来源于:http://resource.haorooms.com/uploads/demo/media/3Dqj/index.html 因本人注册账号下载参考之后再到vue项目中,若有侵权请 ...
- 开源全景插件 Photo Sphere Viewer
概述 日常中,我们比较常见的是街区全景,百度通过街景车采集街景数据,最后形成全景应用,百度的全景还拥有一定的交互功能,可以随着街道移动街景,作为个人开发者,有一些开源库能够满足我们对全景的应用与探索. ...
- Photo Sphere Viewer 全景图
Photo Sphere Viewer 一款基于 three.js 的简易3D插件,方便,实用,友好,看到网上有些API有错误,所以自己写一个修正版的 该js插件可以360度旋转查看全景图,也可以上 ...
- Photo Sphere Viewer渲染全景图片
下载 官方网站: ---- https://photo-sphere-viewer.js.org 附属依赖必选项: ---- three.js ---- browser.js 注: 可以直接使用 np ...
- Photo Sphere Viewer
Photo Sphere Viewer photo-sphere-viewer中文文档_陈坚泓的博客-CSDN博客_photo-sphere-viewer
- 全景效果实现(Photo Sphere,photo-sphere-viewer全景虚拟漫游)
简述:全景效果我们都知道,常用于虚拟场景体验,具体怎么实现,这里给大家推荐一款组件,便于实现全景的真实效果,Photo Sphere: 使用详细: 1.下载依赖: npm install photo- ...
- 使用Vue3实现360度全景效果
全景展示是一种很炫酷的效果,能够带给用户身临其境的感觉,特别是在旅游.房产等行业非常实用.本文将介绍如何使用Vue3来实现360度全景效果. 步骤一:安装相关依赖 首先,我们需要安装两个库:panne ...
- VUE3+ThreeJs实现3D全景场景,可自由旋转视角
介绍 文章中使用到的案例图片都来源于:Humus - Textures 这个网站里面有很多免费的资源.每个资源里面都提供6个不同方位的图片.我们只需要通过threejs稍微处理一下,就能实现3d场景了 ...
- 13个可以为网站创建360度全景视图的工具
英文 | https://niemvuilaptrinh.medium.com/14-libraries-create-360-degree-views-for-website-c4c177ef7d1 ...
最新文章
- leetcode算法题--Triangle
- Redis的常用命令——hash的常用命令
- kafka笔记3(生产者)
- python 程序停止打印日志_优雅停止 SpringBoot 服务,拒绝 kill -9 暴力停止!
- c语言实现socket转json,C++解析JSON进行网络传输--一个通过JSON方式的socket传输
- 【BZOJ2243】 [SDOI2011]染色
- react中IOS手机里面两个input同时存在时,聚焦focus失效解决办法
- 用16进制编辑器编写一个DLL文件
- 大学一年级计算机科学与技术,计算机科学与技术系授课计划及课程表一年级.pdf...
- DQN的e-greedy策略理解
- LP前缀是什么意思?
- java中封装类Feild和使用setter和getter方法访问封装的类Feild
- 草根精神改变历史,山寨模式创造未来
- 计算机知识与技能竞赛配图,“高教杯”全国大学生先进制图技术与技能大赛
- C# Microsoft.Office.Interop.Word设置Word页脚之添加当前页数
- Java SE基础(十六)集合
- 10. 项目沟通管理与干系人管理
- 云服务器安装并配置nginx
- 武汉星起航:“短视频+电商”如何抓住用户“关键时刻”?
- MT4如何添加交易品种?