10
votes

I'm adding multiple TileOverlays to a Google map from cache. When trying to animate them using a handler by changing their visibility there is a flickering of the overlays on the map during the first play through.

Any other way with which I can achieve this?

enter image description here

public class LocalTileProvider implements TileProvider {
    private String url;
    DatabaseHelper db;
    String type;
    // private Paint opacityPaint = new Paint();
    String newurl= PathFinder.rainradar_HDBaseurl; 
    String uid;

    public LocalTileProvider(String uid,DatabaseHelper cache,String type){
        this.uid=uid;
        this.db=cache;
        this.type=type;
    }

    //taking the tile from SQLITEDATABASE 
    @Override
    public Tile getTile(int x, int y, int zoom){
        Tile tile = null;       
        if(db.ispresent(uid, zoom,x , y,type)){ 
            byte[] b=db.gettiles(uid, zoom,x , y,type);
            tile = new Tile(256, 256, b);
            return tile; 
        }
        return NO_TILE;
    } 
}

The following is code for adding those tiles to the Google map

LocalTileProvider provider1 = new LocalTileProvider(uidList.get(0), db, TAG);
TileOverlayOptions  top1 = new TileOverlayOptions().tileProvider(provider1).visible(true);
tileoverlay_1 = googleMap.addTileOverlay(top1);

After adding them I'm playing the animation with the handler by toggling the tile's visibility

public void start() {
    btn_play.setEnabled(true);
    tileoverlay_default.setVisible(false);
    runnable_animation = new Runnable() {
        @Override
        public void run() {
            //tileoverlay_default.setVisible(false);
            isDownloading = false;
            // stop_download=true;
            isRunning = true;
            btn_play.setBackgroundResource(R.drawable.player_pause_2x);
            setVisibility(global);

            if (global == 11) {
                global = 0;              
            } else {
                global = global + 1;
            } 
            mHandler_animation.postDelayed(this, 1000);
        }
    };
    mHandler_animation.post(runnable_animation);
}
3
Please do not ask the same question repeatedly. This is regarded as noise on Stack Overflow. If your question is closed as unanswerable or did not attract responses, then the first thing to do is to improve the question; some guidance for this is given here. Low-quality or unanswerable questions will typically be closed, but can be re-opened if improved or clarified (as appropriate).Matt
@user2197811 have you found a solution for this? This is a significant problem with Google Maps that I also can't find a solution to.aez

3 Answers

0
votes

I know this is a really old question, but in case someone is looking for the answer to this question I thought I might post my answer.

There are 2 reasons why the TileOverlay is flickering when you're adding it to the map.

  1. The tiles aren't cached and must be loaded
  2. The tiles are fading in (default behavior)

From the looks of your code, you are caching the tiles, so all you need to do to stop them from flickering is to turn off the fade in behavior:

LocalTileProvider provider1 = new LocalTileProvider(uidList.get(0), db, TAG);
TileOverlayOptions  top1 = new TileOverlayOptions().tileProvider(provider1).visible(true);
TileOverlay newTileOverlay = map.addTileOverlay(overlay);
tileoverlay_1 = googleMap.addTileOverlay(top1);
tileoverlay_1.setFadeIn(false); //Stop cached tiles from flickering in
-1
votes
public class LocalTileProvider implements TileProvider
    {
        private String url;
        DatabaseHelper db;
        String type;
       // private Paint opacityPaint = new Paint();
       String newurl= PathFinder.rainradar_HDBaseurl; 
        String uid;
         public LocalTileProvider(String uid,DatabaseHelper cache,String type)
        {
              this.uid=uid;
             this.db=cache;
             this.type=type;
        }

    //taking the tile from SQLITEDATABASE 
        @Override
        public Tile getTile(int x, int y, int zoom)
        {

             Tile tile = null;


            if(db.ispresent(uid, zoom,x , y,type))
            {

                byte[] b=db.gettiles(uid, zoom,x , y,type);
                 tile = new Tile(256, 256, b);
                    return tile;

            }
     return NO_TILE;
        }



    }
-1
votes

Gmaps has always some "filckering" when adding a new TileOverlay. You have two options:

  • Add the "new" overlay over the old one, and remove/hide the old one only when the first has loaded (for which I don't remember if there is a callback)
  • Add ALL the TileProviders at the first time, setting the first to visible(true) and the others to visible false (I can't get from your code if you already add all the providers at first time)