jxmapviewer2
jxmapviewer2 copied to clipboard
Feature suggestion: tiles loading/downloading finished notification
It would be very useful to have a notification when tiles cache loading/downloading is finished (with error status).
Did you have a look at:
factory.addTileListener(new TileListener() {
@Override
public void tileLoaded(Tile tile) {
//...do something here
}
});
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.
What about getPendingTiles() in AbstractTileFactory?
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.
Valid request, I will see what can be done here.
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.