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.

    Code
    <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?

  • Hi!
    try this:

    Code
    <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*

  • 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:

    Code
    <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 *wink* 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

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

    Code
    <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!

  • 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

  • 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*

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!