前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >photo-sphere-viewer的使用

photo-sphere-viewer的使用

作者头像
tianyawhl
发布2021-08-25 15:47:46
2.8K1
发布2021-08-25 15:47:46
举报
文章被收录于专栏:前端之攻略

展示点的信息比threejs方便

首先安装 photo-sphere-viewer

npm install photo-sphere-viewer

直接贴代码,

代码语言:javascript
复制
<template>
  <div style="overflow:hidden;border:1px solid #ccc">
    photeSphereViewer
    <div id="viewer"></div>
    <el-dialog :visible.sync="dialogVisible">
      {{dialogID}}
    </el-dialog>
  </div>
</template>

<script>
import { Viewer } from "photo-sphere-viewer";
// import PhotoSphereViewer from "photo-sphere-viewer"
import "photo-sphere-viewer/dist/photo-sphere-viewer.css";
import MarkersPlugin from "photo-sphere-viewer/dist/plugins/markers";
import "photo-sphere-viewer/dist/plugins/markers.css";

export default {
  data() {
    return {
      num:0,
      dialogID:"",
      dialogVisible:false,
    };
  },
  mounted() {
    this.showScene();
    setInterval(()=>{
       document.getElementById("text1").innerHTML = Math.round(50+10*Math.random())
    },5000)
  },
  methods: {
    showScene() {
      const viewer = new Viewer({
        container: document.querySelector("#viewer"),
        panorama: {
          left: "/static/lng/left1.jpg",
          right: "/static/lng/right1.jpg",
          top: "/static/lng/top1.jpg",
          bottom: "/static/lng/bottom1.jpg",
          front: "/static/lng/front1.jpg",
          back: "/static/lng/back1.jpg"
        },
        autorotateDelay: null,
        autorotateSpeed: "1rpm",
        plugins: [
          [
            MarkersPlugin,
            {
              markers: [
                {
                  id: "circle",
                  tooltip: "A circle of radius 30",
                  circle: 30,
                  svgStyle: {
                    fill: "rgba(255,255,0,0.3)",
                    stroke: "yellow",
                    strokeWidth: "2px"
                  },
                  longitude: -1.5,
                  latitude: -0.28,
                  anchor: "center right"
                },
                {
                  // 自定义样式的标记
                  id: "text",
                  longitude: 1,
                  latitude: 0,
                  // html: "HTML <b>marker</b> &hearts;", // 显示内容
                  html:
                    "<div class='textWrap' ><div id='text1'>HTML</div> <b>marker</b> &hearts;</div>", // 显示内容
                  anchor: "bottom right",
                  scale: [0.5, 1.5],
                  style: {
                    // maxWidth: "100px",
                    color: "white",
                    fontSize: "20px",
                    fontFamily: "Helvetica, sans-serif",
                    textAlign: "center"
                  },
                  tooltip: {
                    content: "An HTML marker",
                    position: "right"
                  }
                },
                {
                  // 自定义样式的标记
                  id: "text1",
                  longitude: 0,
                  latitude: 0,
                  html: "HTML <b>marker</b> &hearts;", // 显示内容
                
                  anchor: "bottom right",
                  scale: [0.5, 1.5],
                  style: {
                    // maxWidth: "100px",
                    color: "white",
                    fontSize: "20px",
                    fontFamily: "Helvetica, sans-serif",
                    textAlign: "center"
                  },
                  tooltip: {
                    content: "An HTML marker",
                    position: "right"
                  }
                }
              ]
            }
          ]
        ]
      });
      const markersPlugin = viewer.getPlugin(MarkersPlugin);
      console.log(markersPlugin);
      viewer.on("click",(e,data)=>{
       console.log(e)
       console.log(data)
       
      })
      markersPlugin.on("select-marker", (e, marker) => {
        console.log(marker);
        this.dialogVisible = true
        this.dialogID = marker.id
        viewer
          .animate({
            // longitude: marker.config.longitude,
            // latitude: marker.config.latitude,
            // zoom: 80,
            // speed: "-2rpm"
          })
          .then(() => {
            // markersPlugin.updateMarker({
            //   id: marker.id,
            //   longitude: -1.8,
            //   latitude: -0.28
            // });
          });
      });
    }
  }
};
</script>

<style scoped>
#viewer {
  width: 100vw;
  height: 90vh;
}
/deep/.textWrap{background:gray;border:1px solid red;padding:10px;}
</style>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

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

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

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