如何将瓷砖添加到谷歌地图并动画它们,即用新的瓷砖连续替换它们

时间:2016-04-20 15:40:41

标签: android google-maps

我正在从缓存向Google地图添加多个TileOverlay。当尝试通过更改其可见性使用处理程序为它们设置动画时,在第一次播放期间地图上的叠加层会闪烁。

我可以通过其他任何方式实现这一目标吗?

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;
    } 
}

以下是将这些图块添加到Google地图的代码

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

添加它们之后,我通过切换磁贴的可见性来使用处理程序播放动画

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 个答案:

答案 0 :(得分:0)

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 :(得分:0)

Gmaps总是有一些" filckering"添加新的TileOverlay时。 您有两种选择:

  • 添加" new"覆盖旧的,只有当第一个已加载时才删除/隐藏旧的(我不记得是否有回调)
  • 首次添加所有TileProviders,将第一个设置为可见(true),将其他设置为可见false(如果您已在第一时间添加所有提供程序,则无法从代码中获取)

答案 2 :(得分:0)

我知道这是一个非常老的问题,但是如果有人在寻找该问题的答案,我想我可以发表我的答案。

将TileOverlay添加到地图时,其闪烁有两个原因。

  1. 图块未缓存,必须加载
  2. 图块正在淡入(默认行为)

从代码的外观来看,您正在缓存磁贴,因此,要阻止它们闪烁,您需要做的就是关闭淡入行为:

var filedb = SpreadsheetApp.create("FileDBValueYourTime")     
var folder = DriveApp.createFolder("ValueYourTime")
  var idfolder = folder.getId()
  var idfile = filedb.getId()
  var movefile = DriveApp.getFileById(idfile)
  folder.addFile(movefile)
  //save ID file and folder
  var scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.setProperty('FILEID', idfile)
   scriptProperties.setProperty('FOLDERID', idfolder)