vue3使用panolens.js实现全景,带有上一个下一个,全屏功能

panolens官方文档Home - Panolens

1.加载核心js库 (文件在untils里面)

import '@/utils/panolens/three.min.js';

import '@/utils/panolens/panolens.min.js';

/项目中 /railway/modalIframe/playPanorama/player/js/panolens-ht.js 为修改后版本 可以获取在全景点击获取坐标

//<script src="js/panolens-ht.js"></script>

2.创建全景容器

复制代码
 <div id="newqj" :style="{ display: tabBcnclick == 1 ? 'block' : 'none' }"
                            style="width: 60%;height: 422px;margin: 0 auto;margin-top: 30px;position: relative;overflow: hidden;">
                            <div style="" class="leftArr">
                                <el-icon style="font-size: 24px !important;cursor: pointer;" @click.stop="leftArrowFnc">
                                    <ArrowLeft />
                                </el-icon>
                            </div>
                            <div class="rightArr" style="">
                                <el-icon style="font-size: 24px !important;cursor: pointer;"
                                    @click.stop="rightArrowFnc">
                                    <ArrowRight />
                                </el-icon>
                            </div>
                        </div>

3,加载函数和默认值

const currentIndex = ref(0);

const imgUrl = ref('')

const panorama = ref('')

const viewer = ref('')

panoramaFilesList为后端返回的数组,包含file_path

复制代码
function panoramaFnc() {
    imgUrl.value = formData.value.panoramaFilesList[currentIndex.value].file_path;
    panorama.value = new PANOLENS.ImagePanorama(imgUrl.value);//将全景鱼眼图片生成全景

    // 加载图片数据
    viewer.value = new PANOLENS.Viewer({
        container: document.getElementById('newqj'),//选中容器承载视图
        autoHideInfospot: false,//点击非热点区域 自动隐藏信息点 true:触发,false:不触发 默认值为true
        controlButtons: ['fullscreen'],//全景底部按钮 默认值 ['fullscreen', 'setting', 'video'] fullscreen设置全屏 setting添加设置按钮

    });
    viewer.value.add(panorama.value);//生成的全景必须放入viewer视图中才能显示
}

4.上一个下一个方法

复制代码
function leftArrowFnc(e) {

    if (currentIndex.value > 0) {
        currentIndex.value--;
        panorama.value.load(formData.value.panoramaFilesList[currentIndex.value].file_path)
    } else {
        return 
    }

}
function rightArrowFnc() {
    if (currentIndex.value < formData.value.panoramaFilesList.length - 1) {
        currentIndex.value++;
        panorama.value.load(formData.value.panoramaFilesList[currentIndex.value].file_path)
    } else {
        return
    }
}

5.切换到360全景方法

复制代码
function tabBtnClickFnc(item) {
    tabBcnclick.value = item.value
    console.log(tabBcnclick.value);
    nextTick(() => {
        panoramaFnc()
        // panorama.value.load(formData.value.panoramaFilesList[currentIndex.value].file_path)
    })

}

效果图:

相关推荐
小羊没烦恼!2 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
三十而立洋2 天前
Cookie 详解:从产生到安全,一次讲透
前端·javascript
伞伞悦读2 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
卡布鲁2 天前
把一个 Vite + Vue3 应用塞进 qiankun (React + Umi3) 主站:十个坑的复盘
前端·javascript·react.js
C语言小火车2 天前
C/C++ 为什么需要编译器?
开发语言·c++
李少兄2 天前
JavaScript 隐式全局变量解析
javascript
霍霍的袁2 天前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio
孙启超2 天前
【AI开发之Rust】第 11 课:智能指针与内部可变性
开发语言·后端·rust
此生决int2 天前
深入理解C++系列(20)——C++11(下)
开发语言·c++
沙蒿同学2 天前
我用 Go 搭了一条 AI Agent 流水线:从 1 张商品图到一整套淘宝详情页
前端·javascript·后端