From 93dcbaef847bf1baa32c385db6f93ac96a5451c1 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 18 Feb 2015 19:06:45 -0500 Subject: [PATCH] Fix recently introduced bugs. --- examples/example-tour.json | 1 - src/js/libpannellum.js | 11 +++++++++++ src/js/pannellum.js | 29 ++++++++++++++++------------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/examples/example-tour.json b/examples/example-tour.json index 7638e3c..5c9fcee 100644 --- a/examples/example-tour.json +++ b/examples/example-tour.json @@ -43,7 +43,6 @@ "pond": { "title": "Jordan Pond", - "preview": "./examplepano-preview.jpg", "panorama": "./examplepano.jpg", "hotSpots": [ { diff --git a/src/js/libpannellum.js b/src/js/libpannellum.js index f9ba2e0..e7734e2 100644 --- a/src/js/libpannellum.js +++ b/src/js/libpannellum.js @@ -292,6 +292,17 @@ function Renderer(container, image, imageType, video) { callback(); }; + this.destroy = function() { + if (this.container !== undefined) { + if (this.canvas !== undefined) { + this.container.removeChild(this.canvas); + } + if (this.world !== undefined) { + this.container.removeChild(this.world); + } + } + }; + this.render = function(pitch, yaw, hfov, returnImage) { var focal, i; diff --git a/src/js/pannellum.js b/src/js/pannellum.js index f04f3a2..c05fa44 100644 --- a/src/js/pannellum.js +++ b/src/js/pannellum.js @@ -31,6 +31,7 @@ var config, tourConfig = {}, configFromURL, renderer, + oldRenderer, isUserInteracting = false, latestInteraction = Date.now(), onPointerDownPointerX = 0, @@ -800,6 +801,19 @@ function renderInit() { } function renderInitCallback() { + if (oldRenderer !== undefined) { + oldRenderer.destroy(); + + // Fade if specified + if (config.sceneFadeDuration && oldRenderer.fadeImg !== undefined) { + oldRenderer.fadeImg.style.opacity = 0; + // Remove image + setTimeout(function() { + oldRenderer.container.removeChild(oldRenderer.fadeImg); + }, config.sceneFadeDuration); + } + } + requestAnimationFrame(animate); // Show compass if applicable @@ -1224,6 +1238,7 @@ function load() { function loadScene(sceneId, targetPitch, targetYaw) { loaded = false; + oldRenderer = renderer; // Set up fade if specified var fadeImg; @@ -1236,6 +1251,7 @@ function loadScene(sceneId, targetPitch, targetYaw) { fadeImg.src = data; } document.getElementById('container').appendChild(fadeImg); + oldRenderer.fadeImg = fadeImg; } // Set new pointing @@ -1263,17 +1279,4 @@ function loadScene(sceneId, targetPitch, targetYaw) { config.yaw = targetYaw; } load(); - - // Fade if specified - if (config.sceneFadeDuration) { - // For some unclear reason, the fade doesn't work without the timeout - setTimeout(function() { - fadeImg.style.opacity = 0; - }, 10); - - // Remove image - setTimeout(function() { - document.getElementById('container').removeChild(fadeImg); - }, config.sceneFadeDuration); - } }