# Vue中实现全景房看图3D
# 快速导航
# 示例效果
# 示例代码
# 安装photo-sphere-viewer
yarn add -D photo-sphere-viewer
1
# 组件引入插件
import { Viewer } from 'photo-sphere-viewer';
import 'photo-sphere-viewer/dist/photo-sphere-viewer.css'; // 引入样式
import MarkersPlugin from 'photo-sphere-viewer/dist/plugins/markers'; // 引入标记
1
2
3
2
3
# 完整组件
<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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93