EXAMPLE code for using loadjs() and covert the results on krpano variables.

  • Hi,

    I have a beatiful Javascript file that convert data arrays to a json format and place it on the console into the browser.

    I´m newby including dynamic content into krpano. I recently found loadjs() and I think is the way to go.

    How can I parse or transform that json array data to variables on krpano, or how can I set attributes directly to layers, hotspots, etc from that data.

    I couldn´t found any examples of code for loadjs().

    Could someone please helpme with some basic examples within krpano tour.xml

    Thanks *rolleyes*

  • More info on loadjs:

    kme
    March 12, 2023 at 10:05 PM
  • More info on loadjs:

    kme
    March 12, 2023 at 10:05 PM

    Thanks a lot, that post is not enogth clear for me I´m trying to use window. but I can´t read my js array with jscall or jsget, do you have any suggestion? Just type please some code to verify.

  • In the next krpano version (1.22) there will be an example that loads two JSON files (a GeoJSON one and generic database-like one) and parses them (using Javascript) to automatically generate polygonal-hotspots and image-hotspots.

    Please wait and see then this example.

    Thanks but I can´t wait, I´m in the project right now. I expect a little code to verify. Just to get a variable in krpano with jsget or jscall from the js Array function.

  • In the next krpano version (1.22) there will be an example that loads two JSON files (a GeoJSON one and generic database-like one) and parses them (using Javascript) to automatically generate polygonal-hotspots and image-hotspots.

    Please wait and see then this example.

    Please help

    I have this script in javascript

    Code
    keys.forEach((key) => {
    
    krpano.set('datos_lotifica[lote' + elnumerolote + '].' + key + ', ' + el[key]);
    
    let elset = 'datos_lotifica[lote' + elnumerolote + '].' + key + ', ' + el[key]
    
    console.log(elset);
    })

    I´m loading it with loadjs and in the console I can see the results,

    datos_lotifica[lote7].lote, 7
    datos_lotifica[lote7].area, 6645
    datos_lotifica[lote7].dimensiones, 45x50

    Its seems that every thing its ok as you can see.

    But in the .xml I didn´t receive the information for that array.

    How can I retrieve them.

  • Thanks a lot

    It works with call


    Code
    let elset = 'datoslotifica[lote' + elnumerolote + '].' + key + ', ' + el[key];
    krpano.call('set('+elset+');');

    Edited once, last by alexgtz (October 7, 2024 at 1:46 AM).

Participate now!

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