jxmapviewer2 icon indicating copy to clipboard operation
jxmapviewer2 copied to clipboard

Feature suggestion: tiles loading/downloading finished notification

Open fredkp opened this issue 5 years ago • 6 comments

It would be very useful to have a notification when tiles cache loading/downloading is finished (with error status).

fredkp avatar Jan 17 '20 07:01 fredkp

Did you have a look at:

factory.addTileListener(new TileListener() {

       @Override
      public void tileLoaded(Tile tile) {
                   //...do something here
      }
});

kkieffer avatar Jan 17 '20 14:01 kkieffer

Yes, i already use it to save System.currentTimeMillis() value and i have a thread to evaluate the time elapsed since last tile loaded and when the timeout is reached i make an event. This method works (with previous release, with some glitch on slow connexion) but with the current release, i have (most of the time) missing tiles. I just did a quick test with no further investigation. The cleaner way (for my case) would be an event to know when all tiles are downloaded.

fredkp avatar Jan 17 '20 15:01 fredkp

What about getPendingTiles() in AbstractTileFactory?

kkieffer avatar Jan 17 '20 15:01 kkieffer

I used this method too but you can have a getPendingTiles() == 0 but the tile is not yet loaded because getPendingTiles return tileQueue . size() and in the TileRunner class, at the beginning of the run method you have " final Tile tile = tileQueue . remove();" before loading it.

fredkp avatar Jan 18 '20 08:01 fredkp

Valid request, I will see what can be done here.

msteiger avatar Jan 18 '20 11:01 msteiger

I came across this ticket as I had the same challenge, and I used a combination of the TileListener and overwriting the startLoading function in the DefaultTileFactory. Something like this:

AtomicInteger numLoadingTiles = new AtomicInteger(0);

DefaultTileFactory tileFactory = new DefaultTileFactory(nodeSettings.getTileFactoryInfo()) {
  @Override
  protected synchronized void startLoading(Tile tile) {
    numLoadingTiles.incrementAndGet();
    super.startLoading(tile);
  }
};

tileFactory.addTileListener(tile -> numLoadingTiles.decrementAndGet());

This seems to work fine for us -- the counter gets incremented when loading starts, and decremented once the loading has finished.

qqilihq avatar Nov 10 '22 16:11 qqilihq