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)
    })

}

效果图:

相关推荐
山河木马7 分钟前
矩阵专题2-怎么创建视图矩阵(uViewMatrix)
javascript·webgl·计算机图形学
tangdou3690986551 小时前
AI真好玩系列-2分钟快速了解DeepAgents | Quick Guide to DeepAgents in 2 Minutes
前端·javascript·后端
张元清1 小时前
React useIntersectionObserver Hook:懒加载与可见性检测(2026)
javascript·react.js
彭于晏爱编程2 小时前
纯 JS + Node,一个下午手搓了能读懂公司代码的 AI 助手,老板以为我转行了
前端·javascript
妙码生花2 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十四):眨眼小人登录页制作
前端·javascript·ai编程
妙码生花3 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十三):前端路由初始化
前端·javascript·ai编程
PBitW3 小时前
GPT训练我的第四天,被打惨了!!!😭😭😭
前端·javascript·面试
DarkLONGLOVE3 小时前
快速上手 Pinia!Vue3 极简状态管理使用教程
javascript·vue.js
mackbob3 小时前
.eslintrc.js详细配置说明
javascript
用户298698530145 小时前
在 React 中使用 JavaScript 将 Excel 转换为 PDF
javascript·react.js·webassembly