krpano Javascript Interface

  • Hello to all.

    I just want to get second set of mind for a few questions I have:

    1. when using embedpano() with the onready callback I found that the onready is fired too soon -> I create a JS file with the function that has to be called when the krpano is loaded and ready, but when I try to log out the krpano instance object it doesn't exist -> but available after 500ms setTimeout - I think the onready callback function is triggered to quick, even before the krpano is really ready.

    2. No way to add and "id" property to the layer that gets created when constructing a layer with xml - did anybody find a way to do something like this ? So that the created layer/div is easy to access from external JS.

    Hope this gets answered.

    Regards,

    Nejc

  • Hi,

    1. when using embedpano() with the onready callback I found that the onready is fired too soon -> I create a JS file with the function that has to be called when the krpano is loaded and ready, but when I try to log out the krpano instance object it doesn't exist -> but available after 500ms setTimeout - I think the onready callback function is triggered to quick, even before the krpano is really ready.

    The onready event will be called from the viewer itself once it is ready for working. It can't be to early or 'too quick'.

    But note - a ready viewer doesn't mean it had already loaded the xml file or anything further, for this there are other events (e.g. onxmlcomplete).


    2. No way to add and "id" property to the layer that gets created when constructing a layer with xml - did anybody find a way to do something like this ? So that the created layer/div is easy to access from external JS.

    You could use a JS action to assign an id to a layer - e.g.:

    Code
    <action name="assign_dom_id" type="Javascript">
      caller.sprite.id = args[1];
    </action>
    
    
    <layer ... onloaded="assign_dom_id('layer1');" />

    See also here:
    https://krpano.com/docu/xml/#action.js
    https://krpano.com/docu/xml/#layer.sprite

    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!