Handle of variables and conditional syntax

  • Hello,
    I'm in the way to get a svg logo show over a 360 photo pano display. with some conditions.

    In pano.xml I added a layer and the logo prints okay in the center.
    I also added an event with onresize to have the logo resize according to user screen width. I also works okay.

    Now I want to manage alpha value of the created layer.

    1) How to set variable values like a1=0.7 and set it inside <layer> like alpha=a1 ?

    2) What's the best conditional before <layer> like if(global.stagewidth) < 200, a1=0.4, a1=0.8) (if stagewidth less than 200 then a1=0.4 else a1=0.8)

    3) I found that there's a large area around the logo that the pointer is a hand (instead of the krpano icon to drag), link to follow but I don't need that. I want the whole screen be draggable to browse the panorama

    Thank you!

    Edited once, last by fotouy (June 10, 2024 at 2:15 AM).

    • hank you very much for your answer!
      I started with #3 but writing a single line layer[logo].enabled=false; didn't work so I added enabled="false" inside <layer> element and it worked.

      About combined #1 and #2 I couldn't get it work.
      At pano.xml in <krpano> I wrote
      layer[logo].alpha=*a1;
      if(global.stagewidth LT 200, a1=0.4, a1=0.8);
      <layer name="logo" url="../../img/logo.svg" width="800" height="prop" align="center" keep="true" enabled="false" />

      But the output was like alpha=1.
      Also tried:
      <layer name="logo" url="../../img/logo.svg" width="800" height="prop" align="center" keep="true" enabled="false" onloaded.addevent="calc(alpha.global.stagewidth LT 400 ? 0.7 : 0.3);"/>

      An finally I tried:
      <layer name="logo" url="../../img/logo.svg" width="800" height="prop" align="center" keep="true" enabled="false" />
      <events name="alpha0" keep="true" onloaded="calc(layer[logo].alpha, global.stagewidth LT 400 ? 0.7 : 0.3);" />
      But also didn't work.
      Thanks
      P.S: Edit: replacing onloaded by onresize in the last attempt, solved the issue

    Edited once, last by fotouy (June 10, 2024 at 4:16 PM).

  • hm maybe you should check out some of the examples to get a general feeling how code and xml works together.

    the code below should work (hopefully *squint*)

    Code
    <layer name="logo" url="../../img/logo.svg" width="800" height="prop" align="center" keep="true" enabled="false" />
    <events name="onresize" keep="true" onloaded="onresize();" onresize="onresize();" />
    <action name="onresize" scope="local">
        calc(layer[logo].alpha, stagewidth LT 400 ? 0.7 : 0.3);
    </action>

Participate now!

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