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

Tuesday, July 4th 2017, 1:24am

Can't get layer[name].imagewidth working

Hi!
I'm creating an image layer with:

Source code

1
2
3
4
5
6
7
8
9
10
11
		addlayer(map);
		set(layer[map].align,"leftbottom");
		set(layer[map].x,"10");
		set(layer[map].y,"10");
		set(layer[map].keep,"false");
		set(layer[map].scalechildren,"true");
		set(layer[map].alpha,"0.5");
		set(layer[map].scale,"0.15");
		set(layer[map].startscale,"0.15");
		set(layer[map].destscale,"1");
                set(layer[map].url,get(mapurl));

The layer is created and works correctly, but I can't get the layer[name].imagewidth working, I always get 0.


Any ideas?

Alexey Tkachenko

Professional

Posts: 760

Location: Sevastopol, Crimea, Russian Federation

Occupation: Interpreting, Building virtual tours

  • Send private message

2

Tuesday, July 4th 2017, 8:36am

Hi)

Try to add this line and see what 'trace' returns:

Source code

1
set(layer[map].onloaded, showlog();trace(layer[map].imagewidth));
Regards,

Alexey

robertl

Beginner

  • "robertl" started this thread

Posts: 32

Location: Croatia

  • Send private message

3

Tuesday, July 4th 2017, 11:54am

set(layer[map].onloaded, showlog();trace(layer[map].imagewidth));


Thanks!
I completely missed the .onloaded method. I just put the code that deals with image dimensions to be run in an .onloaded and it's working fine!

I didn't expect to have to deal with such asynchronous behaviour with Krpano.

Alexey Tkachenko

Professional

Posts: 760

Location: Sevastopol, Crimea, Russian Federation

Occupation: Interpreting, Building virtual tours

  • Send private message

4

Tuesday, July 4th 2017, 2:29pm

Why asynchroneous? It's all very logical: imagewidth (original width of the image file) is not known until the source image is fully loaded.
Regards,

Alexey

robertl

Beginner

  • "robertl" started this thread

Posts: 32

Location: Croatia

  • Send private message

5

Tuesday, July 4th 2017, 2:39pm

Why asynchroneous? It's all very logical: imagewidth (original width of the image file) is not known until the source image is fully loaded.


In my original code, I called the .imagewidth a long after the image layer was created and set and it wasn't blocking. That's async behavior. Nothing wrong with it, but important to keep in mind.