question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Secondary tile overlay does not always display tiles

See original GitHub issue

I’m using osmdoird 5.6.5 in my Android application. I’m using a custom baselayer, and I add a second layer above it in this way:

baselayer:

final MapTileProviderBasic tileProvider = new MapTileProviderBasic(getApplicationContext());
        final ITileSource tileSource = new XYTileSource(getResources().getString(R.string.rp_cachemap), 6, 17, 256, ".png", tileserver);
        tileProvider.setTileSource(tileSource);
        final TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, this.getBaseContext());
        tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);

overlay:

final MapTileProviderBasic anotherTileProvider = new MapTileProviderBasic(getApplicationContext());
        final ITileSource tileSource2 = new XYTileSource("tile_overlay_3",6, 17, 256, ".png", new String[]{"https://geoserver2.nodemapp.com/geoserver/"})
        {
            @Override
            public String getTileURLString(MapTile aTile) {
                String hello= getBaseUrl() + "gwc/service/gmaps?layers=nodemapp-public-mobile-with-cache&zoom=" + aTile.getZoomLevel() + "&x=" + aTile.getX() + "&y=" + aTile.getY() + "&format=image/png&viewparams=kind:hike;groupid:1&version=1";
                System.out.println(hello);
                return hello;
            }
        };
        anotherTileProvider.setTileSource(tileSource2);
        final TilesOverlay secondTilesOverlay = new TilesOverlay(anotherTileProvider, this.getBaseContext());
        secondTilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);

set tiles on map:

osmMap.setTileSource(tileSource);
osmMap.getOverlays().add(secondTilesOverlay);
osmMap.invalidate();

Eveything is working fine, but when scrolling the map, sometimes there are some tiles not showing properly in the second overlay. When scrolling a little bit further, they are loaded. Is this a known bug?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:13

github_iconTop GitHub Comments

4reactions
monsieurtanukicommented, May 19, 2018

@conej730

it does seem less than optimal to have to invalidate the map every time a new tile is downloaded?

According to Android docs about invalidate:

If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future.

In short: invalidate is not sync, and it’s safe to call several times as Android will refresh the display potentially only once. At some point.

Back to the current issue.

We have async tile downloads, and a MapView. How do new tiles refresh the MapView: only because whenever a tile is successfully downloaded, it calls (by default) a Handler of class SimpleInvalidationHandler, that explicitly calls MapView.invalidate. Another way to refresh the MapView is to move/pinch the map.

And the problem so far with the secondary tile provider is that you have to explicitly tell your provider how to behave when a tile is successfully downloaded. If not you just ask it to download tiles into the cache, regardless of the display. And you don’t have to do it explicitly for the primary tile provider because it’s done in MapView.setTileProvider.

Therefore you should add something like

anotherTileProvider.setTileRequestCompleteHandler(mMapView.getTileRequestCompleteHandler());

in your code.

In the meanwhile I’m fixing the “Sample with tiles overlay and secondary tile overlay” demo that doesn’t work for the same reasons - I will PR within an hour.

Tell me if it works.

0reactions
monsieurtanukicommented, May 22, 2018

@conej730 Excellent!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Tiles overlay not working in latest Google Maps SDK ...
The issue was with the tile url. The first issue in that was that the url was http, requests to which were failing....
Read more >
Overlay tiled images on a map - UWP applications
Overlay third-party or custom tiled images on a map by using tile sources. Use tile sources to overlay specialized information such as ...
Read more >
Overlay Tile Names - BoardGameGeek
Does a list of the overlay tile names along with images of the tiles exist anywhere? I am attempting to organize the game...
Read more >
MKTileOverlay not displayed on iOS… - Apple Developer
MKTileOverlay not displayed on iOS 14 device, but on iOS 14 Simulator. ... it to NO, but setting NO leads to only grey...
Read more >
Square tile galleries show square images - WordPress.org
All the images in a square lightbox or circular tile galleries display in the overlay as square images. There are replicated Tiled galleries...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found