Can't use set(layer[name].url.html5,"file.js")?

  • Hi!
    If I define the layer first like this:

    Code
    <!-- radar -->
    	<layer name="radar" keep="true"
    	       url.flash="%SWFPATH%/plugins/radar.swf"
    	       url.html5="%SWFPATH%/plugins/radar.js"
    	       align="center" zorder="1"
    	       scale.mobile="1.5"
    	       fillalpha="0.5" fillcolor="0x7F5F3F"
    	       linewidth="1.0" linecolor="0xE0E0A0" linealpha="0.5"
    	       editmode="true"
      />

    and set the parameters with set like this:

    It works as expected.
    But if I use addlayer(radar) to create it, it doesn't load:

    Am I missing something?

    I have my doubts on the set/get and dots.
    The debug("Radar.url:",get(layer[radar].url.html5)); is throwing a null.

    Edited once, last by robertl (July 5, 2017 at 4:13 PM).

  • hi) It won't work this way. You're trying to use static xml device check while adding the layer dynamically.

    Try 'if' condition instead. Like this:

    Code
    if(device.html5, set(layer[radar].url. '%SWFPATH%/plugins/radar.js'); , set(layer[radar].url. '%SWFPATH%/plugins/radar.swf'));

    Regards,

    Alexey

  • hi) It won't work this way. You're trying to use static xml device check while adding the layer dynamically.

    Try 'if' condition instead. Like this:

    Code
    if(device.html5, set(layer[radar].url. '%SWFPATH%/plugins/radar.js'); , set(layer[radar].url. '%SWFPATH%/plugins/radar.swf'));

    Thanks Alexey!
    That did the trick.

    And finally found the relevant part in the documentation!
    So all the additional concatenated attributes are basically shorthand if checks?

    How about this:

    Code
    <hotspot name="pano15" videourl="%FIRSTXML%/spots/pano_high.mp4" devices="desktop" />
      <hotspot name="pano15" videourl="%FIRSTXML%/spots/pano_low.mp4" devices="tablet.or.mobile.and.no-iphone" />

    That is from a live site and it's working.
    It's elegant, and seems replicating it dynamically would not be as much.

    I'm guessing this wouldn't work:

    Code
    addlayer(pano15);
    set(layer[pano15].videourl, get(%FIRSTXML%/spots/pano_high.mp4));
    set(layer[pano15].devices, 'desktop');
    set(layer[pano15].videourl, get(%FIRSTXML%/spots/pano_low.mp4));
    set(layer[pano15].devices, 'tablet.or.mobile.and.no-iphone');

    but this one could:

    Code
    addlayer(pano15);
    if(device.desktop,
        set(layer[pano15].videourl, get(%FIRSTXML%/spots/pano_high.mp4));
        set(layer[pano15].devices, 'desktop');
    );
    if(device.tablet.or.mobile.and.no-iphone,
        set(layer[pano15].videourl, get(%FIRSTXML%/spots/pano_low.mp4));
        set(layer[pano15].devices, 'tablet.or.mobile.and.no-iphone');
    );
  • Hi,

    So all the additional concatenated attributes are basically shorthand if checks?

    Yes, can be said. They decide if that attribute will get parsed or not.


    • the 'if' is okay
    • the 'get(...)' is wrong as the values you're setting are not variables
    • and setting the 'devices' attributes is unnecessary and wouldn't do anything. krpano checks the 'devices' attributes in the xml files only during parsing the xml data to the internal data structures.


    Here an alternative one-line solution using the calc() action and the ternary (if ? then : else) operator:

    Code
    calc(layer[pano15].videourl, device.desktop ? '%FIRSTXML%/spots/pano_high.mp4' : '%FIRSTXML%/spots/pano_low.mp4');

    or here with separating the folder-path from the file-names:

    Code
    calc(layer[pano15].videourl, '%FIRSTXML%/spots/' + (device.desktop ? pano_high.mp4' : 'pano_low.mp4'));

    Best regards,
    Klaus

  • Hi,

    • the 'if' is okay
    • the 'get(...)' is wrong as the values you're setting are not variables
    • and setting the 'devices' attributes is unnecessary and wouldn't do anything. krpano checks the 'devices' attributes in the xml files only during parsing the xml data to the internal data structures.


    Uh, yes, you're right about the get. I was a bit tired and didn't think it through :)
    Good to know about the 'devices ' attribute, so it's like a preprocessor command?

    Quote


    Here an alternative one-line solution using the calc() action and the ternary (if ? then : else) operator:

    Code
    calc(layer[pano15].videourl, device.desktop ? '%FIRSTXML%/spots/pano_high.mp4' : '%FIRSTXML%/spots/pano_low.mp4');

    or here with separating the folder-path from the file-names:

    Code
    calc(layer[pano15].videourl, '%FIRSTXML%/spots/' + (device.desktop ? pano_high.mp4' : 'pano_low.mp4'));

    Yeah, that would work.
    Thanks!

Participate now!

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