You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

robertl

Beginner

  • "robertl" started this thread

Posts: 32

Location: Croatia

  • Send private message

1

Wednesday, July 5th 2017, 3:59pm

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

Hi!
If I define the layer first like this:

Source code

1
2
3
4
5
6
7
8
9
10
	<!-- 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:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
	<action name="create-radar">
		set(layer[radar].align,"topleft");
		set(layer[radar].mask,"mapmask");
		set(layer[radar].edge,"center");
		set(layer[radar].parent,"map");
		set(layer[radar].keep,"false");
		set(layer[radar].scale,"2");
		set(layer[radar].fillcolor,"0xFF0000");
		set(layer[radar].linewidth,"1.0");
		set(layer[radar].zorder, "2");
		set(layer[radar].editmode, "true");
	</action>


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

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	<action name="create-radar">
		addlayer(radar);
		set(layer[radar].align,"topleft");
		set(layer[radar].mask,"mapmask");
		set(layer[radar].edge,"center");
		set(layer[radar].parent,"map");
		set(layer[radar].keep,"false");
		set(layer[radar].url.flash,"%SWFPATH%/plugins/radar.swf");
		set(layer[radar].url.html5,"%SWFPATH%/plugins/radar.js");
		set(layer[radar].scale,"2");
		set(layer[radar].fillcolor,"0xFF0000");
		set(layer[radar].linewidth,"1.0");
		set(layer[radar].zorder, "2");
		set(layer[radar].editmode, "true");
	</action>


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.

This post has been edited 1 times, last edit by "robertl" (Jul 5th 2017, 4:13pm)


Alexey Tkachenko

Professional

Posts: 763

Location: Sevastopol, Crimea, Russian Federation

Occupation: Interpreting, Building virtual tours

  • Send private message

2

Wednesday, July 5th 2017, 4:15pm

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:

Source code

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

Alexey

robertl

Beginner

  • "robertl" started this thread

Posts: 32

Location: Croatia

  • Send private message

3

Wednesday, July 5th 2017, 4:36pm

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:

Source code

1
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:

Source code

1
2
  <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:

Source code

1
2
3
4
5
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:

Source code

1
2
3
4
5
6
7
8
9
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');
);

4

Sunday, July 9th 2017, 5:40pm

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.


but this one could:
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');
);
  • 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:

Source code

1
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:

Source code

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


Best regards,
Klaus

robertl

Beginner

  • "robertl" started this thread

Posts: 32

Location: Croatia

  • Send private message

5

Sunday, July 9th 2017, 6:17pm

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?

Quoted


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

Source code

1
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:

Source code

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


Yeah, that would work.
Thanks!