Page 2 of 2

Re: Can I read 'Player Width' into a variable? Edit: Yes! :^)

Posted: Tue Aug 11, 2020 5:01 am
by Tony
Hi Josh,

I tried your solution but ended up with a value of 0. Where are you placing the code?

cheers,

Tony

Re: Can I read 'Player Width' into a variable? Edit: Yes! :^)

Posted: Tue Aug 11, 2020 6:29 am
by Tony
Tony wrote: Tue Aug 11, 2020 5:01 am Hi Josh,

I tried your solution but ended up with a value of 0. Where are you placing the code?

Update: all good and working well. Then I saw your reply :-)

cheers,

Tony

Re: Can I read 'Player Width' into a variable? Edit: Yes! :^)

Posted: Tue Aug 11, 2020 6:30 am
by Josh
Hi Tony,

I have the code inside an action on a text box object, though realistically it could live anywhere. What's important here is that the Source for the action is something that happens when the pano loads - I used Config Loaded. The height and width won't be reported until after this action is executed (try it with a mouse click to see what I mean)

Anyhow, I suspect the reason you're getting 0 is because the player size hasn't actually changed. This code on its own won't do anything until the size of the window changes, that's the event that it's listening for so if you resize the window it should start working. To get around this you need to read the width and height into the variables first, and then have it listen for changes:

Code: Select all

javascript:
pano.setVariableValue('var_player_height', pano.getViewerSize().height);
pano.setVariableValue('var_player_width', pano.getViewerSize().width);
pano.on("sizechanged", function() {
pano.setVariableValue('var_player_height', pano.getViewerSize().height);
pano.setVariableValue('var_player_width', pano.getViewerSize().width);
});
Stick this code on an object (shouldn't matter what one) and have an event with source "config loaded", action "URL" and get that code in there. Should slap.

J

EDIT: Great, you got it working. Leaving this here to help anyone else who may come across the thread.

Re: Can I read 'Player Width' into a variable? Edit: Yes! :^)

Posted: Tue Aug 11, 2020 6:32 am
by Tony
Hi Josh,

Thanks for the explanation, it's very helpful. I'd forgotten to add 'javascript:' at the beginning.

cheers,

Tony

Re: Can I read 'Player Width' into a variable? Edit: Yes! :^)

Posted: Tue Aug 11, 2020 10:49 am
by Branigan
Josh wrote: Tue Aug 11, 2020 6:30 am
I have the code inside an action on a text box object, though realistically it could live anywhere. What's important here is that the Source for the action is something that happens when the pano loads - I used Config Loaded. The height and width won't be reported until after this action is executed (try it with a mouse click to see what I mean)

Anyhow, I suspect the reason you're getting 0 is because the player size hasn't actually changed. This code on its own won't do anything until the size of the window changes, that's the event that it's listening for so if you resize the window it should start working. To get around this you need to read the width and height into the variables first, and then have it listen for changes:
That's an interesting addition, but I literally put my two lines as the text in the text box and it does give the right values immediately. I'm not bothering with triggers because the act of starting the panorama is enough to get the initial values, and if you rotate your phone/tablet that seems to be enough to get it to update.

Re: Can I read 'Player Width' into a variable? Edit: Yes! :^)

Posted: Tue Aug 11, 2020 12:21 pm
by Josh
Yeah this would be because code that is placed in a text box is executed when the tour is loaded. It gives the same result so as long as it's working for you then that's all that matters but this could be useful for you to know if you want to trigger JS on an event later on. Glad you got it working how you wanted.

J

Re: Can I read 'Player Width' into a variable? Edit: Yes! :^)

Posted: Mon May 15, 2023 12:07 pm
by SharonaAd
Hi,

I have a similar problem. I want to display a image in proportion to the height and width of the player.
So I've got the height and width but how do I put a variable into the size elements of the image. That field doesn't seem to be able to accept variables as you can see in the attachment.
Is there maybe a Javascript way?

Thanks

Sharona