From 4f477031b3c6f80a247fd93571eea47de65b66af Mon Sep 17 00:00:00 2001 From: pchen66 Date: Wed, 22 Apr 2020 23:11:01 -0700 Subject: [PATCH] Refactor event sequence to avoid confusion --- src/panorama/PanoMomentPanorama.js | 2 +- src/panorama/Panorama.js | 14 +++++++++++++- src/viewer/Viewer.js | 22 +++++++--------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/panorama/PanoMomentPanorama.js b/src/panorama/PanoMomentPanorama.js index bab6fff6..13480140 100644 --- a/src/panorama/PanoMomentPanorama.js +++ b/src/panorama/PanoMomentPanorama.js @@ -44,7 +44,7 @@ function PanoMomentPanorama ( identifier, options = {} ) { // Event Listeners this.addEventListener( 'panolens-camera', data => this.onPanolensCamera( data ) ); this.addEventListener( 'panolens-controls', data => this.onPanolensControls( data ) ); - this.addEventListener( 'enter-start', () => this.enter() ); + this.addEventListener( 'enter-fade-start', () => this.enter() ); this.addEventListener( 'leave-complete', () => this.leave() ); this.addEventListener( PANOMOMENT.LOAD, () => this.disableControl() ); this.addEventListener( PANOMOMENT.READY, () => this.enableControl() ); diff --git a/src/panorama/Panorama.js b/src/panorama/Panorama.js index 6163434b..9b187c34 100644 --- a/src/panorama/Panorama.js +++ b/src/panorama/Panorama.js @@ -254,6 +254,13 @@ Panorama.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), { */ this.dispatchEvent( { type: 'loaded' } ); + /** + * Panorama is ready to go + * @event Panorama#ready + * @type {object} + */ + this.dispatchEvent( { type: 'ready' } ); + }, /** @@ -629,7 +636,12 @@ Panorama.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), { if ( this.loaded ) { - this.fadeIn( duration ); + /** + * Panorama is ready to go + * @event Panorama#ready + * @type {object} + */ + this.dispatchEvent( { type: 'ready' } ); } else { diff --git a/src/viewer/Viewer.js b/src/viewer/Viewer.js index f3e5c44c..c2a2637e 100644 --- a/src/viewer/Viewer.js +++ b/src/viewer/Viewer.js @@ -349,7 +349,7 @@ Viewer.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype } else { - ep.onEnter(); + ep.fadeIn(); } @@ -359,7 +359,7 @@ Viewer.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype const onLeaveComplete = () => { - ep.onEnter(); + ep.fadeIn(); lp.removeEventListener( 'leave-complete', onLeaveComplete ); }; @@ -368,25 +368,17 @@ Viewer.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype } - if( ep.loaded ) { + const onReady = () => { onSwitch(); + ep.removeEventListener( 'ready', onReady ); - } else { - - const onLoaded = () => { - - onSwitch(); - ep.removeEventListener( 'loaded', onLoaded ); - - }; - - ep.addEventListener( 'loaded', onLoaded ); - ep.load(); + }; - } + ep.addEventListener( 'ready', onReady ); this.panorama = ep; + this.panorama.onEnter(); }