6

I implemented heremaps in an angular app and use it to print a PDF using wkhtmltopdf, the problem is that I need to have a reliable event to listen to in order to inform wkhtmltopdf that my map is fully loaded and ready to be printed. Specifically some tiles are either not loaded or still in a blur state when printing the PDF.

I tried to listen to the mapviewchangeend event, but it isn't thrown at tile loading. I also tried listening to the render event of the rendering engine but an event is thrown each time a tile is loaded and I don't know exactly how many tiles I am supposed to wait

// add a listener on the map ready event
this.map.getEngine().addEventListener("render", (event: H.util.Event) => {
    if (this.map.getEngine() === event.target) {
        map.mapReadyAction();
    }
});

Is there a reliable way to know when my map tiles are fully loaded and ready to be printed ?

edit: using the post linked in the comments I found a way to reliably count the number of loaded tiles. Unfortunately I can't find a way to determine the total number of tiles my map needs to load (getTileNumber() in the code)

this.nbLoadedTiles = 0;
this.map
    .getBaseLayer()
    .getProvider()
    .addEventListener("update", () => {
        this.nbLoadedTiles++;
        console.log(`tile loaded : ${this.nbLoadedTiles}`);

        if (this.nbLoadedTiles === this.getTileNumber()) {
            console.log("All tiles loaded");
            map.mapReadyAction();
            this.nbLoadedTiles = 0;
        }
    });

Thanks !

Alfred
  • 649
  • 5
  • 11
  • There is already an answer provided for a similar question. See if that helps https://stackoverflow.com/questions/20978752/is-there-a-way-to-know-that-an-imgtileprovider-has-finished-loading-all-tiles –  Jul 30 '19 at 13:15
  • Hi thanks for your fast answer but in the linked post he defined a `magicNumber = 22`, representing the number of tiles to load on the map, which is specifically the number I'm looking to determine, in a non-magical way. I have around 50 maps per PDF, with different zoom levels and the number of tiles varies for each of them – Alfred Jul 31 '19 at 03:12
  • I tried it out just in case and my first map has 17 tiles and another one has 11 tiles. I'd like to find a way to figure out these numbers from the tiles provider, but there's no "fetch" event to listen to – Alfred Jul 31 '19 at 03:53
  • In JSLA version 3.x.x.x, we don't have any map-render-display.js file, we also don't have a class with the name ImgTileProvider. In 3.x.x.x the right way to check whether everything is loaded and rendered is to subscribe to render event of the render engine and check that event target is a render engine. –  Aug 05 '19 at 07:38
  • @here-developer-support could you explain that in more detail? – cweiske Jun 04 '21 at 11:11

1 Answers1

0

This is not an acceptable answer but it is the workaround I used while waiting for a proper solution:

I'm using the "tile loaded" event described in the original post to start a timer, if no additional tile was loaded within this time I consider the map loaded.

// add a listener on the map ready event
this.map
    .getBaseLayer()
    .getProvider()
    .addEventListener("update", () => {
        // a new tile was succesfully loaded: reset the timer
        clearTimeout(this.tileTimer);
        this.tileTimer = setTimeout(() => {
            map.mapReadyAction();
        }, DELAY_TILE_LOADED);
    });

I run this with a 3s delay to have an acceptable compromise between having the maximum chances to have a fully loaded map and acceptable delay. Note that my users are not customers so waiting for 3s is okay, but for an online app this may be a no go

Alfred
  • 649
  • 5
  • 11