Browse Source

Unify configuration files, deprecating separate `tour` option.

pull/86/head
Matthew Petroff 9 years ago
parent
commit
a00af3b8c3
3 changed files with 15 additions and 64 deletions
  1. +1
    -6
      doc/url-config-parameters.md
  2. +11
    -24
      src/js/pannellum.js
  3. +3
    -34
      src/pannellum.htm

+ 1
- 6
doc/url-config-parameters.md View File

@@ -3,7 +3,7 @@
URL parameters are used to configure Pannellum. If an `equirectangular` image
is being used without some of Pannellum's more advanced features, Pannellum can
be configured with just URL parameters; else, a JSON configuration file needs
to be used, using either the `config` parameter or `tour` parameter.
to be used with the `config`.


## `config`
@@ -11,11 +11,6 @@ to be used, using either the `config` parameter or `tour` parameter.
Specifies the URL of a JSON configuration file.


## `tour`

Specifies the URL of a JSON tour configuration file.


## Other parameters

A subset of the JSON configuration file options can be used as URL parameters.


+ 11
- 24
src/js/pannellum.js View File

@@ -25,7 +25,7 @@ window.pannellum = (function(window, document, undefined) {

'use strict';

function Viewer(container, initialConfig, tourConfig) {
function Viewer(container, initialConfig) {

// Declare variables
var config,
@@ -169,9 +169,9 @@ compass.className = 'pnlm-compass pnlm-controls pnlm-control';
container.appendChild(compass);

// Load and process configuration
if (tourConfig.default && tourConfig.default.firstScene) {
if (initialConfig.default && initialConfig.default.firstScene) {
// Activate first scene if specified
mergeConfig(tourConfig.default.firstScene);
mergeConfig(initialConfig.default.firstScene);
} else {
mergeConfig(null);
}
@@ -204,10 +204,6 @@ function init() {
c.basePath = config.basePath + config.multiRes.basePath;
} else if (config.basePath) {
c.basePath = config.basePath;
} else if (tourConfig.basePath && config.multiRes.basePath) { // avoid 'undefined' in path, check (optional) multiRes.basePath, too
c.basePath = tourConfig.basePath + config.multiRes.basePath;
} else if (tourConfig.basePath) {
c.basePath = tourConfig.basePath;
}
panoImage = c;
} else {
@@ -281,8 +277,6 @@ function init() {
p = config.cubeMap[i];
if (config.basePath && !absoluteURL(p)) {
p = config.basePath + p;
} else if (tourConfig.basePath && !absoluteURL(p)) {
p = tourConfig.basePath + p;
}
panoImage[i].src = p;
}
@@ -292,8 +286,6 @@ function init() {
p = '';
if (config.basePath) {
p = config.basePath;
} else if (tourConfig.basePath) {
p = tourConfig.basePath;
}
if (config.video === true) {
@@ -1116,9 +1108,9 @@ function mergeConfig(sceneId) {
}
// Merge default scene config
for (k in tourConfig.default) {
if (tourConfig.default.hasOwnProperty(k)) {
config[k] = tourConfig.default[k];
for (k in initialConfig.default) {
if (initialConfig.default.hasOwnProperty(k)) {
config[k] = initialConfig.default[k];
if (photoSphereExcludes.indexOf(k) >= 0) {
config.ignoreGPanoXMP = true;
}
@@ -1126,8 +1118,8 @@ function mergeConfig(sceneId) {
}
// Merge current scene config
if ((sceneId !== null) && (sceneId !== '') && (tourConfig.scenes) && (tourConfig.scenes[sceneId])) {
var scene = tourConfig.scenes[sceneId];
if ((sceneId !== null) && (sceneId !== '') && (initialConfig.scenes) && (initialConfig.scenes[sceneId])) {
var scene = initialConfig.scenes[sceneId];
for (k in scene) {
if (scene.hasOwnProperty(k)) {
config[k] = scene[k];
@@ -1158,8 +1150,6 @@ function processOptions() {
var p = config.preview;
if (config.basePath) {
p = config.basePath + p;
} else if (tourConfig.basePath) {
p = tourConfig.basePath + p;
}
preview = new Image();
@@ -1358,7 +1348,7 @@ function loadScene(sceneId, targetPitch, targetYaw) {
if (targetYaw === 'same') {
workingYaw = config.yaw;
} else if (targetYaw === 'sameAzimuth') {
workingYaw = config.yaw + config.northOffset - tourConfig.scenes[sceneId].northOffset;
workingYaw = config.yaw + config.northOffset - initialConfig.scenes[sceneId].northOffset;
} else {
workingYaw = targetYaw;
}
@@ -1383,11 +1373,8 @@ function loadScene(sceneId, targetPitch, targetYaw) {
}

return {
viewer: function(container, config, tourConfig) {
if (tourConfig === undefined) {
tourConfig = {};
}
return new Viewer(container, config, tourConfig);
viewer: function(container, config) {
return new Viewer(container, config);
}
};



+ 3
- 34
src/pannellum.htm View File

@@ -59,6 +59,9 @@ function parseURLParameters() {
var request;

// Check for JSON configuration file
if (configFromURL.tour) {
configFromURL.config = configFromURL.tour;
}
if (configFromURL.config) {
// Get JSON configuration file
request = new XMLHttpRequest();
@@ -92,40 +95,6 @@ function parseURLParameters() {
return;
}

var firstScene = null;
// Check for virtual tour JSON configuration file
if (configFromURL.tour) {
// 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.tour;
a.innerHTML = a.href;
anError('The file ' + a.outerHTML + ' could not be accessed.');
}

tourConfig = JSON.parse(request.responseText);

// Set JSON file location
tourConfig.basePath = configFromURL.tour.substring(0, configFromURL.tour.lastIndexOf('/')+1);

if (configFromURL.firstScene) {
if (tourConfig.default === undefined) {
tourConfig.default = {};
}
tourConfig.default.firstScene = configFromURL.firstScene;
}

// Create viewer
pannellum.viewer(document.getElementById('container'), configFromURL, tourConfig);
};
request.open('GET', configFromURL.tour);
request.send();
return;
}

// Create viewer
pannellum.viewer(document.getElementById('container'), configFromURL);
}


Loading…
Cancel
Save