TDTUrl.java 2.6 KB
package utils;

import java.util.Random;

/**
 * Created by jiangbotao on 2018/3/23.
 */

public class TDTUrl {

    private TianDiTuTiledMapServiceType _tiandituMapServiceType;
    private int _level;
    private int _col;
    private int _row;

    public TDTUrl(int level, int col, int row, TianDiTuTiledMapServiceType tiandituMapServiceType) {
        this._level = level;
        this._col = col;
        this._row = row;
        this._tiandituMapServiceType = tiandituMapServiceType;
    }

    public String generatUrl() {

        StringBuilder url = new StringBuilder("http://t");
        Random random = new Random();
        int subdomain = (random.nextInt(6) + 1);
        url.append(subdomain);
        switch (this._tiandituMapServiceType) {
            case TianDiTuTiledMapServiceType.VEC_C:
                url.append(".tianditu.com/DataServer?T=vec_c&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
                break;
            case TianDiTuTiledMapServiceType.CVA_C:
                url.append(".tianditu.com/DataServer?T=cva_c&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
                break;
            case TianDiTuTiledMapServiceType.CIA_C:
                url.append(".tianditu.com/DataServer?T=cia_c&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
                break;
            case TianDiTuTiledMapServiceType.IMG_C:
                url.append(".tianditu.com/DataServer?T=img_c&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
                break;
            case TianDiTuTiledMapServiceType.VEC_W:
                url.append(".tianditu.com/DataServer?T=vec_w&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
                break;
            case TianDiTuTiledMapServiceType.CVA_W:
                url.append(".tianditu.com/DataServer?T=cva_w&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
                break;
            case TianDiTuTiledMapServiceType.CIA_W:
                url.append(".tianditu.com/DataServer?T=cia_w&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
                break;
            case TianDiTuTiledMapServiceType.IMG_W:
                url.append(".tianditu.com/DataServer?T=img_w&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
                break;
            default:
                return null;
        }
        return url.toString();
    }
}