Sie sind nicht angemeldet.

1

Dienstag, 4. Juli 2017, 01:24

Can't get layer[name].imagewidth working

Hi!
I'm creating an image layer with:

Quellcode

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?

Beiträge: 770

Wohnort: Russian Federation

Beruf: Interpreting, Building virtual tours

  • Nachricht senden

2

Dienstag, 4. Juli 2017, 08:36

Hi)

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

Quellcode

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

Alexey

3

Dienstag, 4. Juli 2017, 11:54

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.

Beiträge: 770

Wohnort: Russian Federation

Beruf: Interpreting, Building virtual tours

  • Nachricht senden

4

Dienstag, 4. Juli 2017, 14:29

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

5

Dienstag, 4. Juli 2017, 14:39

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.