console
const sourceRoot = 'https://unpkg.com/vr-panorama@1.0.0/assets';
const box = document.querySelector('#container');
const data = getNaviData();
const traveller = new VrTraveller(data, box);
const glassesButton = new VrTraveller.GlassesButton();
traveller.setGlassesButton(glassesButton);
function getSphereSliceUrl(key) {
const list = [];
for (let i = 0; i < 8; i++) {
const a = [];
for (let j = 0; j < 4; j++) {
a.push(`${sourceRoot}/sphereSource/${key}/pano${i}-${j}.jpg`);
}
list.push(a);
}
return list;
}
function getCubeSliceUrl(key) {
var arr = [];
for(var i = 1; i < 7; i++) {
arr.push(`${sourceRoot}/cubeSource/${key}/pano${i}.jpg`);
}
return arr;
}
function getNaviData() {
return [{
"scene": {
"photo_key": "1",
"correction": [0, 0, 0],
"rotation": [180, 0, 0],
"title": "卧室",
"sphereSource": {
thumb: `${sourceRoot}/sphereSource/1/thumb.jpg`,
slices: getSphereSliceUrl(1)
},
"cubeSource": {
thumb: `${sourceRoot}/cubeSource/1/thumb.jpg`,
slices: getCubeSliceUrl(1)
},
"is_main": 1
},
"overlays": [{
"title": "洗手间",
"x": 4.6720072719141,
"y": -0.52291666726088,
"next_photo_key": "2"
},
{
"title": "厨房",
"x": 4.6720072719141,
"y": 0.52291666726088,
"next_photo_key": "2"
}]
},
{
"scene": {
"photo_key": "2",
"correction": [0, 0, 0],
"rotation": [180, 0, 0],
"title": "卫生间",
"sphereSource": {
thumb: `${sourceRoot}/sphereSource/2/thumb.jpg`,
slices: getSphereSliceUrl(2)
},
"cubeSource": {
thumb: `${sourceRoot}/cubeSource/2/thumb.jpg`,
slices: getCubeSliceUrl(2)
},
"is_main": 0
},
"overlays": [{
"title": "卧室",
"x": 3.4483749837697,
"y": -0.7169249148447,
"next_photo_key": "1"
}]
}];
}
<div id="container">
</div>
body,
html {
margin: 0;
height: 100%;
}
#container {
height: 100%;
width: 100%;
border: 1px solid #000;
margin: 0;
position: relative;
overflow: hidden;
}
.overlay {
z-index: 10000;
position: absolute;
width: 120px;
top: 0px;
left: 0px;
text-align: center;
margin-left: -60px;
cursor: pointer;
}
.overlay-label {
position: absolute;
width: 120px;
text-align: center;
top: -20px;
color: rgb(255, 255, 255);
display: block;
font-size: 14px;
text-shadow: black 2px 2px 2px;
cursor: pointer;
}
.overlay-arrow {
width: 40px;
height: 28px;
cursor: pointer;
}
.glass-btn {
position: absolute;
width: 30px;
right: 10px;
top: 10px;
}
.glass-exitbtn {
position: absolute;
width: 60px;
left: 10px;
top: 10px;
padding: 4px;
color: #fff;
text-align: center;
font-size: 14px;
border-radius: 5px;
background: rgba(0, 0, 0, .7);
}
.glass-exitbtn1 {
top: 50%;
left: 82%;
margin-top: -15px;
margin-left: 0;
transform: rotate(90deg);
}
.glass-exitbtn2 {
top: 5;
left: 50%;
margin-top: 0;
margin-left: -30px;
transform: rotate(0deg);
}
.test-btn {
display: none;
position: absolute;
width: 100px;
left: 100px;
top: 0;
color: #fff;
background: rgba(0, 0, 0, .7)
}
.center-point {
display: none;
position: absolute;
left: 0;
top: 0;
background: #fff;
box-shadow: 2px 2px 2px #000;
}
.controls {
position: absolute;
top: 10px;
right: 10px;
}
.row {
display: flex;
margin: 10px 0;
}
.label {
width: 50px;
}
#add-overlay,
#save-rotation {
background: rgb(25, 143, 123);
border-radius: 5px;
cursor: pointer;
padding: 4px;
color: #fff;
}
#scene-list {
position: absolute;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, .7);
display: flex;
justify-content: center;
}
.scene-item {
width: 120px;
height: 80px;
position: relative;
margin: 0 8px;
overflow: hidden;
cursor: pointer;
}
.scene-item img {
width: 100%;
height: auto;
}
.scene-item .title {
position: absolute;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, .7);
text-align: center;
color: #fff;
}
.scene-item .btn {
position: absolute;
top: 0;
width: 100%;
text-align: center;
color: #fff;
}