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

}

效果图:

相关推荐
布莱克6056 小时前
Swift 类详解:从定义、继承到内存管理的完整指南
服务器·开发语言·ios·ssh·swift·类
是main不是漫7 小时前
【快慢指针 | LeetCode202 快乐数】鸽巢原理佐证环特性,快慢指针巧解快乐数
c语言·开发语言·c++·算法
布莱克6059 小时前
Swift 方法详解:实例方法、类型方法与 mutating 机制
服务器·开发语言·ios·ssh·swift·方法
Risehuxyc10 小时前
PHP能不能在参数里放匿名函数
开发语言·php
码云社区10 小时前
Java家政服务系统源码:人员技能、服务范围与多商家业务落地
java·开发语言·家政服务·家政小程序·家政系统
FRing0311 小时前
vue3干货总结3(defineOptions(Vue3.3)、defineModel(Vue3.4)、Pinia)
开发语言·前端·vue.js·vue3
whitelbwwww12 小时前
CUDA C++实战--中级
开发语言·前端·c++
FungLeo13 小时前
FengCMS · PHP+MySQL 升级实录 · 内容写入一致性:锁等待超时与跨模型子树删除竞态
开发语言·mysql·php·工程实践·fengcms
inksci13 小时前
用飞帆做了个小网页
前端·javascript·css·html
zhensherlock14 小时前
Protocol Launcher 系列:CodeHub 移动端 GitHub 协作利器
前端·javascript·typescript·node.js·自动化·github·js