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.

1

Thursday, January 23rd 2020, 4:47pm

embedpano vars object and overriding design_bgcolor or design_bgalpha

Hi there,

I am trying to override skin or layer settings using javascript, but I am not having much luck.

Can anyone help me with the order of execution when using embedpano and an onready callback function:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
embedpano({
	swf: "../assets/tour.swf"
	,xml: "tour.xml"
	,target: "pano"
	,html5: "auto"
	,mobilescale: 1.0
	,bgcolor: "#00ff00"
	,vars:  {
		ui_color: "0xFFFFFF"
		ui_alpha: "0.5"
	}
	,onready : krpano_onready_callback
});

function krpano_onready_callback(krpano_interface) {
	krpano = krpano_interface;
	console.log("krpano ready");
	if (krpano) {
		krpano.set("skin_settings.design_bgcolor", "0xFFFFFF");
		krpano.call("trace('skin_settings.design_bgcolor=', get(skin_settings.design_bgcolor));");
	}
	console.log("krpano_onready_callback ended");
}

After I call embedpano() I get the following output in the console:

Source code

1
2
3
4
5
krpano ready
krpano_onready_callback ended
INFO: preinit action fired
INFO: onstart action fired
INFO: skin_settings.design_bgcolor=0x2D3E50

I would expect "skin_settings.design_bgcolor" to have been changed to "0x00FF00" when I called krpano.set() but it remains as the default from set in vtourskin.xml


I have also tried setting a layer's bgcolor with JS (in my callback function) but I cannot get this to work either:

Source code

1
2
krpano.set("layer[skin_floorplan_container].bgcolor", "0xFFFFFF");
krpano.call("trace('layer[skin_floorplan_container].bgcolor=', get(layer[skin_floorplan_container].bgcolor));");

Console output:

Source code

1
INFO: layer[skin_floorplan_container].bgcolor=0x000000


Do I need to call some a method to get these changes to be registered with krpano and displayed in the browser?

Hopefully one of you kind people can point me in the right direction!

Cheers
Olly

San7

Intermediate

Posts: 284

Occupation: coding in krpano

  • Send private message

2

Thursday, January 23rd 2020, 5:11pm

Try like this

krpano.call("set(layer[skin_floorplan_container].bgcolor, 0xFFFFFF);");

3

Thursday, January 23rd 2020, 5:23pm

Thank you San7 - that worked perfectly!

Do you know why you cannot use krpano.set() for this?

4

Thursday, January 23rd 2020, 6:32pm

Do you know why you cannot use krpano.set() for this?


actually that should work...

krpano.set("layer[skin_floorplan_container].bgcolor", 0xFFFFFF);

or

var sfc = krpano.layer.getItem("skin_floorplan_container");
if(sfc) sfc.bgcolor = 0xFFFFFF;

5

Thursday, January 23rd 2020, 6:52pm

Thanks for trying to help indexofrefraction.


Your first idea does not work here and the second throws an error:
Uncaught TypeError: Cannot read property 'getItem' of undefined

Is the layer property of krpano object documented anywhere?

Is this a bug or user error?

FWIW I am using v1.20.2...

6

Thursday, January 23rd 2020, 7:55pm

https://krpano.com/docu/plugininterface/#array.getItem

problem is maybe more that there you dont get the "real" krpano object ...
try to do this first :

...
krpano = krpano_interface;
console.log(krpano);
console.log(krpano.set);
console.log(krpano.layer);

if the later show null or undefined, it is not the "real" krpano object...
i always forget how to get it... will check...

ahh.. have a look here:
https://krpano.com/forum/wbb/index.php?p…t=krpano+object

7

Friday, January 24th 2020, 4:13pm

Thanks for the pointer to get the "real" krpano object...

However, krpano.layer.getItem("skin_floorplan_container") returns undefined.

Does the getItem() selector string require any context?

8

Friday, January 24th 2020, 6:51pm

Hi,

one important note - the onready will be called once the krpano viewer itself is loaded and ready to use. But that doesn't mean that any files, like the startup-xml file are also already loaded at this time.

Therefore these layers are not defined yet and when you set some values they get overwriten by the loaded xml.

Try something like this:

Source code

1
2
3
4
krpano.set("events.onxmlcomplete", function()
{
   krpano.set("layer[skin_floorplan_container].bgcolor", 0xFFFFFF); 
});


Best regards,
Klaus

9

Friday, January 24th 2020, 7:13pm

Thank you so much Klaus - that is exactly what I needed...

You are a legend!