reddag / jsc3d

Automatically exported from code.google.com/p/jsc3d
0 stars 0 forks source link

Canvas or viewer loading complete? #111

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi.
I want export image of canvas on new tab when replace scene complete. I write 
this:

viewer.replaceSceneFromUrl(url);
viewer.onloadingcomplete = function () {
   window.open(canvas.toDataURL());
};

It's open blank page. So I solve this:

viewer.replaceSceneFromUrl(url);
viewer.onloadingcomplete = function () {
  setTimeout(function(){
     window.open(canvas.toDataURL());
  },3000)
};

It's ok. But setTimeout is not a good choice. How to identify the view or 
canvas is loading complete, please?

Original issue reported on code.google.com by fabien...@gmail.com on 4 Sep 2014 at 8:33

GoogleCodeExporter commented 9 years ago
Yes, it is. Before viewer.onloadingcomplete is invoked, the viewer sets a flag 
to call for a redraw but won't perform it immediately. There's an asynchronous 
routine, periodically scheduled by an internal timer, to get the actual job 
done.  So there will be only background when your code is executed.

Try this solution instead:

  var canExport = false;
  ...
  viewer.onloadingcomplete = function() {
    // now we can export the screenshot
    canExport = true;
  };
  viewer.afterupdate = function() {
    // do export it and reset the flag
    if (canExport) {
      window.open(canvas.toDataURL());
      canExport = false;
    }
  };
  ...

It makes use of another event handler viewer.afterupdate which is ensured to be 
called after a redraw is complete for the actual exporting. This handler is 
documented here: 
http://jsc3d.googlecode.com/svn/trunk/jsc3d/docs/symbols/JSC3D.Viewer.html#after
update.

Original comment by Humu2...@gmail.com on 4 Sep 2014 at 3:16

GoogleCodeExporter commented 9 years ago
Thank you. It's work well

Original comment by fabien...@gmail.com on 5 Sep 2014 at 2:02