mpetroff / pannellum

Pannellum is a lightweight, free, and open source panorama viewer for the web.

Home Page:https://pannellum.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pannelum load event with multires

aproni34f opened this issue · comments

Hi, I have an issue caching load event (with autoLoad:true) when using multires panaorama.

The load event fires before the code viewer.on('load'....

If I add little delay with setTimeout in pannellum.js to this line fireEvent('load'); then load event works with following code, but this is not something I want to do.

Is there a way I can rewrite this code so I can hear the load event after I init panorama? How could I attach listener before I actually set pano data to load?

  `var viewer = pannellum.viewer('panorama', {
	autoLoad:true,
    "type": "multires",
    "multiRes": {
        "basePath": "./multires",
        "path": "/%l/%s%x%y",
        "fallbackPath": "/fallback/%s",
        "extension": "png",
        "tileResolution": 256,
        "maxLevel": 4,
        "cubeResolution": 2048
    }
});

viewer.on('load',
    function () {
        console.log("load");
    }
);`

When constructing a viewer with a multires panorama and autoLoad: true, the panorama will be considered loaded before the pannellum.viewer returns. Thus, there is little reason to have an event listener for this. You could accomplish the same thing by just calling your event handler manually with something along the lines of:

var viewer = pannellum.viewer('panorama', {...});
function loadHandler () {
    console.log("load");
}
viewer.on('load', loadHandler);
loadHandler();

Alternatively, instead of setting autoLoad: true, just call viewer.loadScene(); after adding your event listener.

So with multires, Is there a way of actually knowing when the scene has loaded (maybe with some code mod) so I can fade in scene nicelly?

You can query the loading status with viewer.getRenderer().isLoading().

However, tile loading is linked to rendering for performance reasons, so a scene won't load if it isn't being rendered.