前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Vue中实现全景房看图3D

Vue中实现全景房看图3D

作者头像
itclanCoder
发布2023-09-14 17:39:18
3290
发布2023-09-14 17:39:18
举报
文章被收录于专栏:itclanCoderitclanCoder

示例代码

安装photo-sphere-viewer

代码语言:javascript
复制
yarn add -D photo-sphere-viewer

组件引入插件

代码语言:javascript
复制
import { Viewer } from 'photo-sphere-viewer';
import 'photo-sphere-viewer/dist/photo-sphere-viewer.css'; // 引入样式
import MarkersPlugin from 'photo-sphere-viewer/dist/plugins/markers'; // 引入标记

完整组件

代码语言:javascript
复制
<template>
    <div class="PSViewer" ref="psvdbg"  :style="{height:height,width:width}"></div>
  </template>
  
  <script>
  import { Viewer } from 'photo-sphere-viewer';
  import 'photo-sphere-viewer/dist/photo-sphere-viewer.css';
  import MarkersPlugin from 'photo-sphere-viewer/dist/plugins/markers';
  import BaseImg from "./base.jpg";
  export default {
    name: 'quanjing3D',
    props: {
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '700px'
      }
    },
    data() {
      return {
        img: BaseImg
      };
    },
    mounted() {
      this.init();
    },
    methods: {
      init() {
        var PSV = new Viewer({
          panorama: this.img, //图片
          caption: '室内',
          container: this.$refs.psvdbg, //id
          size: {
            width: '100%',
            height: this.$refs.psvdbg.offsetHeight
          },
          navbar: ['autorotate', 'zoom', 'caption', 'fullscreen'],
          plugins: [
            [
              MarkersPlugin,
              {
                markers: [
                  {
                    id: 'image',
                    longitude: 0.931,
                    latitude: 0.3,
                    image: require('./exit.png'),
                    anchor: 'bottom center',
                    width: 48,
                    height: 48,
                    tooltip: 'A image marker. <b>Click me!</b>',
                    content: '这是一个marker标记'
                  },
                  {
                    // 具有自定义样式的html标记
                    id: 'text',
                    longitude: 0,
                    latitude: 0,
                    html: 'HTML <b>marker</b> ♥',
                    anchor: 'bottom right',
                    style: {
                      maxWidth: '100px',
                      color: 'white',
                      fontSize: '20px',
                      fontFamily: 'Helvetica, sans-serif',
                      textAlign: 'center'
                    },
                    tooltip: {
                      content: '一个标记',
                      position: 'right'
                    }
                  }
                ]
              }
            ]
          ]
        });
        PSV.on('click', function(e) {
          // console.log(e);
          // console.log(MarkersButton);
          // console.log(PSV.buttons.MarkersButton);
        });
      }
    }
  };
  </script>
  <style lang="scss" scoped>
  
  </style>
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-09-11 08:00,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 itclanCoder 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档