<include> via Javascript brokes the krpano player

  • Hello

    I have a problem when I add additional XML code via <include> in the basic XML passed to the player in Javascript. When the basic XML <krpano> code contains the <include>, subsequent calls to the player in Javascript, such as adding hotspots, are no longer processed. However, the panorama is displayed perfectly. If I remove the include, the instructions are processed without any problem.

    This happens even with the inclusion of the simplest possible external XML code, such as '<krpano></krpano>'.

    Has anyone experienced this problem before? As the Javascript console returns absolutely no errors, I don't see how to isolate what is going on. Moreover, if I make a 'krpano.get("hotspot.count")' call, the result is correct. In other words, the krpano declares the hotspots well but does not draw them ...

    Here are my calls in javascript. As you can see, I use a variable to establish the URL of the included XML, but the problem is strictly the same if I pass the complete URL in the base XML.

    The as() function, which calls all other functions to draw the hotspots or orientate the view, is placed in an external js file.

    Thank you for your help and your ideas.

    Sylvain


    Update : the console throwed an Unhandled Promise Rejection… See capture

    -- WITHOUT <include … /> - WORKS FINE

    <script>
    var settings = {};
    settings['pnopath'] = 'http://local.server/content/panoramas/the_panorama' ;
    settings["onstart"] = "loadxml('<krpano><view hlookat=\"0\" vlookat=\"0\" maxpixelzoom=\"1.0\" fovmax=\"150\" limitview=\"auto\" /><image><cube url=\"%$PNOPATH%/the_panorama.tiles/%s/l%l/%0v/l%l_%s_%0v_%0h.jpg\" multires=\"512,768,1536,3072,6144\" /></image></krpano>');"
    embedpano({id:"kr-2f9c6f5d1c9a",xml:"",target:"kr-2f9c6f5d1c9a-pano",html5:"auto",vars:settings,onready:krpano_onready_callback});
    function krpano_onready_callback(krpano_interface){
    as("kr-2f9c6f5d1c9a");
    }
    </script>


    -- WITH <include … /> - BROKEN

    <script>
    var settings = {};
    settings['thmpath'] = 'http://local.server/content/skin' ;
    settings['pnopath'] = 'http://local.server/content/panoramas/the_panorama' ;
    settings["onstart"] = "loadxml('<krpano><include url=\"%$THMPATH%/av_panorama.xml\" /><view hlookat=\"0\" vlookat=\"0\" maxpixelzoom=\"1.0\" fovmax=\"150\" limitview=\"auto\" /><image><cube url=\"%$PNOPATH%/the_panorama.tiles/%s/l%l/%0v/l%l_%s_%0v_%0h.jpg\" multires=\"512,768,1536,3072,6144\" /></image></krpano>');"
    embedpano({id:"kr-2f9c6f5d1c9a",xml:"",target:"kr-2f9c6f5d1c9a-pano",html5:"auto",vars:settings,onready:krpano_onready_callback});
    function krpano_onready_callback(krpano_interface){
    as("kr-2f9c6f5d1c9a");
    }
    </script>


    -- EXTERNAL JS FILE

    // closure
    var as;

    (function($) {

    as = applyskin ;

    function applyskin(pano_uuid) {
    krpano_go_to_view(pano_uuid,pano_uuid + '-pano');
    krpano_display_hotspots(pano_uuid,pano_uuid + '-pano');
    krpano_set_autorotation(pano_uuid,pano_uuid + '-pano') ;
    krpano_set_title(pano_uuid,pano_uuid + '-pano');
    }

    … functions …

    })(jQuery);

    -- EXTERNAL XML FILE (av_panorama.xml)

    <krpano></krpano>

  • Hi,

    is that error really from krpano itself?

    About your problem: to be able to use a variable as url placeholder it would need to be defined BEFORE actually using it.

    And for that these variables would need to be passed via 'initvars', not via 'vars' (the 'vars' will be set AFTER loading the xml - to be able to overwrite setting from xml) - please see here:
    https://krpano.com/docu/html/#vars
    https://krpano.com/docu/html/#initvars

    Best regards,
    Klaus

  • Thank you for your quick response, Klaus, and for pointing out the use of initvars.

    I just solved the problem. It was due to the fact that KRPANO seems to take longer to initialize with the inclusion of XML (at least this is my interpretation). As a consequence, and even if my external JavaScript functions were called through the onready callback, they had no effect. I implemented an additional timer that monitors the DOM and everything is now back to normal.

    Kind regards,

    Sylvain

  • Hi,

    the onready callback will be called when the krpano viewer itself is ready and running, it doesn't relate to the loading of any xml files.

    For that you could use the onxmlcomplete event:

    Code
    embedpano({xml:"...", ..., onready:krpanoonready});
    
    
    function krpanoonready(krpano)
    {
      krpano.set("events.onxmlcomplete", function()
      {  
        console.log("the startup xml files is loaded now");
      });
    }

    Best regards,
    Klaus

Participate now!

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