-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtour.js
143 lines (130 loc) · 4.46 KB
/
vtour.js
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
function anError(error, showHTML) {
var errorMsg = document.createElement('div');
errorMsg.className = 'pnlm-info-box';
var p = document.createElement('p');
if (showHTML)
p.innerHTML = error;
else
p.textContent = error;
errorMsg.appendChild(p);
document.getElementById('container').appendChild(errorMsg);
}
var viewer;
function parseURLParameters() {
var URL;
if (window.location.hash.length > 0) {
// Prefered method since parameters aren't sent to server
URL = window.location.hash.slice(1);
} else {
URL = window.location.search.slice(1);
}
var configFromURL = {};
configFromURL['config'] = 'vtour.json';
configFromURL['autoLoad'] = true;
URL = URL.split('&');
if (!URL) {
// Display error if no configuration parameters are specified
//anError('No configuration options were specified.');
//return;
}
for (var i = 0; i < URL.length; i++) {
var option = URL[i].split('=')[0];
var value = URL[i].split('=')[1];
if (value == '')
continue; // Skip options with empty values in URL config
switch(option) {
case 'hfov':
case 'pitch':
case 'yaw':
case 'haov':
case 'vaov':
case 'minHfov':
case 'maxHfov':
case 'minPitch':
case 'maxPitch':
case 'minYaw':
case 'maxYaw':
case 'vOffset':
case 'autoRotate':
configFromURL[option] = Number(value);
break;
case 'autoLoad':
case 'ignoreGPanoXMP':
case 'compass':
case 'showFullscreenCtrl':
case 'showZoomCtrl':
case 'keyboardZoom':
case 'mouseZoom':
case 'doubleClickZoom':
case 'disableKeyboardCtrl':
case 'draggable':
case 'showControls':
case 'dragConfirm':
configFromURL[option] = JSON.parse(value);
break;
case 'author':
case 'title':
case 'firstScene':
case 'fallback':
case 'preview':
case 'panorama':
case 'config':
configFromURL[option] = decodeURIComponent(value);
break;
default:
//anError('An invalid configuration parameter was specified: ' + option);
// return;
}
}
var request;
// Check for JSON configuration file
if (configFromURL.config) {
// Get JSON configuration file
request = new XMLHttpRequest();
request.onload = function() {
if (request.status != 200) {
// Display error if JSON can't be loaded
var a = document.createElement('a');
a.href = configFromURL.config;
a.textContent = a.href;
anError('The file ' + a.outerHTML + ' could not be accessed.', true);
return;
}
var responseMap = JSON.parse(request.responseText);
// Set JSON file location
if (responseMap.basePath === undefined)
responseMap.basePath = configFromURL.config.substring(0, configFromURL.config.lastIndexOf('/')+1);
// Merge options
for (var key in responseMap) {
if (configFromURL.hasOwnProperty(key)) {
continue;
}
configFromURL[key] = responseMap[key];
}
// Set title
if ('title' in configFromURL)
document.title = configFromURL.title;
// Create viewer
configFromURL.escapeHTML = true;
viewer = pannellum.viewer('container', configFromURL);
};
request.open('GET', configFromURL.config);
request.send();
return;
}
// Set title
if ('title' in configFromURL)
document.title = configFromURL.title;
// Create viewer
configFromURL.escapeHTML = true;
configFromURL.targetBlank = true;
viewer = pannellum.viewer('container', configFromURL);
}
// Display error if opened from local file
if (window.location.protocol == 'file:') {
anError('Due to browser security restrictions, Pannellum can\'t be run ' +
'from the local filesystem; some sort of web server must be used.');
} else {
// Initialize viewer
parseURLParameters();
}