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.

hennzen

Beginner

  • "hennzen" started this thread

Posts: 7

Location: Berlin, Germany

  • Send private message

1

Wednesday, December 4th 2013, 8:45pm

How to create an event, firing only ONCE after view changed

I want to save the current view, i.e. atH, atV and fov, of a panorama into a session/cookie, after the user has interacted with the panorama. How can I achieve this?

Currently, I am using either the event "onviewchange" oder "onviewchanged", but tracing either one to the console shows me that it is fired constantly, as long as the panorama moves, which is impractical. I would like the panorama to stop, wait a second and only then save the aforementioned values. See this testing code sample.

Source code

1
2
3
4
5
6
7
8
9
<krpano>
  ...
  <events onviewchanged= "save_view();"/>
  <action name="save_view">
	trace(view.hlookat); // for testing the event only
	// Save atH, atV, fov
  </action>
  ...
</krpano>


Maybe there is a way of combing onviewchanged with idle, but I cannot figure out, how this could work.

Any hint appreciated!

Cheers,
Hennzen

Edit: My dear... this post ended up in the wrong section, should've gone to krpano Panorama Viewer, not the HTML5 Viewer. My bad. Can any moderator move this?

Posts: 1,081

Location: Russia, Kaliningrad

  • Send private message

2

Wednesday, December 4th 2013, 10:33pm

Hi!
try this:

Source code

1
2
3
4
5
6
7
<events onviewchanged= "save_view();"/>
<action name="save_view">
	stopdelayedcall(saveView);
	delayedcall(saveView,1,
		trace('You must see this message just once, after 1 sec you stop moving pano');
	);
</action>



Regards
Andrey *thumbup*
VRAP - desktop VR content player based on krpano.
Common tasks in one place in one click! Discussion thread
DOWNLOAD for MAC
DOWNLOAD for WIN

hennzen

Beginner

  • "hennzen" started this thread

Posts: 7

Location: Berlin, Germany

  • Send private message

3

Thursday, December 5th 2013, 12:33am

Neat! Tried it. save_view() fires up once upon load of pano (that's perfectly okay). Moved pano, but it never fires again.

First I thought the id in delayedcall(id, delay, actions) must not be a string, or at least not one with the same name as the method itself. But after some debugging I found that it actually works, as soon as you insert a trace() at the beginning of that method:

Source code

1
2
3
4
5
<action name="save_view">
  trace("boo!");  // comment this line out and it stops working
  stopdelayedcall(save_view);
  delayedcall(save_view, 2, trace('You must see this message just once, after 1 sec you stop moving pano');	);
</action>


This way it works. But I wouldn't want to put this to production ;-) Unfortunately enough, I am also experiencing some minor performance issues when panning the panorama.

I am thinking about switching to mouseup as the triggering event. This way I would not catch the mousewheel event though, but that one also feels like machine gun fire for the purpose of saving some values.

More ideas on this still welcome!

cheers,
Hennzen

hennzen

Beginner

  • "hennzen" started this thread

Posts: 7

Location: Berlin, Germany

  • Send private message

4

Thursday, December 5th 2013, 12:49am

This actually works quite well, as the row of events fired on onmousewheel is no performance issue at all, compared to onviewchanged.

Source code

1
2
3
4
5
6
7
<events onmouseup= "save_view();"/>
<events onmousewheel= "save_view();"/>
<action name="save_view">
  trace("why am i needed to make this work?");
  stopdelayedcall(save_view);
  delayedcall(save_view, 1, trace('You must see this message just once, after 1 sec you stop moving pano');	);
</action>


That trace still bugs me!

hennzen

Beginner

  • "hennzen" started this thread

Posts: 7

Location: Berlin, Germany

  • Send private message

5

Thursday, December 5th 2013, 1:15am

Argh! Know your development envirnoment! The code was fine, even without the trace("blafoo") method. It was Firebug that kicked my *** by silently grouping trace messages with the same content! So while I was watching the console, -apparently- nothing happened, BUT on the right, a tiny little counter increased, bravely counting the trace('You must see this message just once, after 1 sec you stop moving pano'); outputs. Only inserting the second trace() stopped this...

Find the solution how to break this default habit of Firebug here: http://stackoverflow.com/a/18765407/3047172

By default, Firebug groups the console messages if they are the same.
In version 1.12.1, there is a new option called console.groupLogMessages that you can use to disable this behaviour.

Steps:
1. Enter about:config in the address bar
2. Search for console.groupLogMessages
3. Double click it to set it to false

Posts: 1,081

Location: Russia, Kaliningrad

  • Send private message

6

Thursday, December 5th 2013, 9:04am

Hi!
my code works so:
you moving pano - and 1 sec after you stop changing view, you will see message. If you start moving again in 1 sec, you see nothing.
And so on, you must see this message each time you changed view. But only after you stop changing view with 1 sec delay (adjustable value). :)

so, If you need JUST ONCE! without repeat this message, then simple set onchanged event to null after fire message.

Or maybe I missed something.

Andrey *thumbup*
VRAP - desktop VR content player based on krpano.
Common tasks in one place in one click! Discussion thread
DOWNLOAD for MAC
DOWNLOAD for WIN

hennzen

Beginner

  • "hennzen" started this thread

Posts: 7

Location: Berlin, Germany

  • Send private message

7

Thursday, December 5th 2013, 9:42am

Works perfectly, thanks a lot! First I was just too stupid to read Firebugs console ouput correctly.

Cheers,
Hennzen