How to know when the map is correctly displayed in the browser ?

1416
4
05-26-2016 04:12 AM
RobinChappatte
New Contributor III

(Please excuse my english)

I have to fire a 'window.print()' when the map is entierely displayed in the browser.

I tried to use 'view.then()' but the map is still not displayed when the 'then' event occure...

My solution is to use 'setTimeout' in the 'then' event, and to wait 1 second, but that doesn't sounds correct to me to do this...

Is there a way to know / detect / check is the map is correctly displayed ?

Thank you in advance for your answers,

Robin Chappatte

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Robin,

  How about looping through the MapView.allLayerViews and check the updating property of each layer.

RobinChappatte
New Contributor III

Thank you !

I also have to check if the layers were created (otherwise it considered the map as ready when there where no layers in the list):

function isReady() {
     if (view.allLayerViews.length == 0) {
         return false;
     }

     for (var i = 0; i < view.allLayerViews.length; i++) {
         if (view.allLayerViews.items.updating) {
             return false;
         }
     }

     return true;
}

function waitReady() {
     if (isReady()) {
         window.print();
     } else {
         window.setTimeout(waitReady, 10);
     }
}
0 Kudos
RobinChappatte
New Contributor III

Sorry to set back this thread as unresolved but after many tests I detect bad case where the print is launched but tiles still missing...

By setting the timeout to a lower value, it fails more often...

So I don't give up and still looking for a way to detect it

0 Kudos
RobinChappatte
New Contributor III

After several tests, the only thing I can suppose is that the browser take time to display the tiles, and the attribute updating goes to false as soon as the layer received the data, regardless of whether they are displayed.

My solution consist in adding a setTimeout between the "isReady" and the printing launch:

function waitReady() {
     if (isReady()) {

         window.setTimeout(function() {

             window.print();

         }, 100); // 100ms of security for letting the browser display
     } else {
         window.setTimeout(waitReady, 10);
     }
}

0 Kudos