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

Q&A about the latest versions
User avatar
Tony
Posts: 999
Joined: Mon Feb 15, 2010 6:54 am
Location: Adelaide, South Australia
Contact:

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?

cheers,

Tony
Tony Redhead | Panoramic Photographer | mobile: +61438501002 | website: http://tonyredhead.com - http://redsquare.com | roundme: http://round.me/@tonyredhead | instagram: https://www.instagram.com/tonyredhead/
User avatar
Tony
Posts: 999
Joined: Mon Feb 15, 2010 6:54 am
Location: Adelaide, South Australia
Contact:

Tue Aug 11, 2020 6:29 am

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
Last edited by Tony on Tue Aug 11, 2020 6:31 am, edited 1 time in total.
Tony Redhead | Panoramic Photographer | mobile: +61438501002 | website: http://tonyredhead.com - http://redsquare.com | roundme: http://round.me/@tonyredhead | instagram: https://www.instagram.com/tonyredhead/
Josh
Posts: 11
Joined: Wed Aug 05, 2020 1:54 pm

Tue Aug 11, 2020 6:30 am

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.
User avatar
Tony
Posts: 999
Joined: Mon Feb 15, 2010 6:54 am
Location: Adelaide, South Australia
Contact:

Tue Aug 11, 2020 6:32 am

Hi Josh,

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

cheers,

Tony
Tony Redhead | Panoramic Photographer | mobile: +61438501002 | website: http://tonyredhead.com - http://redsquare.com | roundme: http://round.me/@tonyredhead | instagram: https://www.instagram.com/tonyredhead/
Branigan
Posts: 228
Joined: Tue May 19, 2020 3:43 pm

Tue Aug 11, 2020 10:49 am

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.
Josh
Posts: 11
Joined: Wed Aug 05, 2020 1:54 pm

Tue Aug 11, 2020 12:21 pm

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
Post Reply