浏览代码

Prevent empty values in URL config from stopping panorama rendering

Should the user use URL configuration for their panorama and then
specify an option/key but leave the value empty, previously this
would stop the panorama from being displayed due to the generated
JSON config from src/standalone/standalone.js being invalid.

This commit omits creating an on-the-fly JSON string and instead
uses a JavaScript object (which the generated JSON string was
converted to anyway).

The background of wanting to enable URL options with possibly empty
values relates to using Pannellum with static site generators.
Depending on the static site generator, specifying default values
for undefined template variables can result in lots of template
notation whereas outputting a value for a variable that isn't
defined usuallly simply outputs an empty string. It would hence be
desirable to treat the empty-string value of an option/key in URL
config as if that option/key were not user-supplied at all and
hence the Pannellum default value for that option/key be used.
pull/166/head
Janne Cederberg 8 年前
父节点
当前提交
24bef7b329
共有 1 个文件被更改,包括 7 次插入13 次删除
  1. +7
    -13
      src/standalone/standalone.js

+ 7
- 13
src/standalone/standalone.js 查看文件

@@ -14,35 +14,29 @@ function parseURLParameters() {
return;
}
URL = URL[0].split('&');
var json = '{';
var configFromURL = {};
for (var i = 0; i < URL.length; i++) {
var option = URL[i].split('=')[0];
var value = URL[i].split('=')[1];
json += '"' + option + '":';
if ( value == '' ) continue; // skip options with empty values in URL config
switch(option) {
case 'hfov': case 'pitch': case 'yaw': case 'haov': case 'vaov':
case 'hfov': case 'pitch': case 'yaw': case 'haov': case 'vaov': case 'vOffset':
case 'minHfov': case 'maxHfov': case 'minPitch': case 'maxPitch': case 'minYaw': case 'maxYaw':
case 'vOffset': case 'autoRotate':
json += value;
configFromURL[option] = value;
break;
case 'autoLoad': case 'ignoreGPanoXMP':
json += JSON.parse(value);
case 'autoLoad': case 'autoRotate': case 'ignoreGPanoXMP':
configFromURL[option] = JSON.parse(value);
break;
case 'tour':
console.log('The `tour` parameter is deprecated and will be removed. Use the `config` parameter instead.')
case 'author': case 'title': case 'firstScene': case 'fallback':
case 'preview': case 'panorama': case 'config':
json += '"' + decodeURIComponent(value) + '"';
configFromURL[option] = decodeURIComponent(value);
break;
default:
anError('An invalid configuration parameter was specified: ' + option);
}
if (i < URL.length - 1) {
json += ',';
}
}
json += '}';
var configFromURL = JSON.parse(json);

var request;



正在加载...
取消
保存