//
//Copyright(C) 2013
//Author:LL
//文件名:
//文件功能描述:加载天地图切片图层类
//
//创建标识:
////////////////////////////////////////////////////////////////////////////////
package com.gis.tiandimap;
import android.util.Log;
import com.esri.android.map.TiledServiceLayer;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.b.a.g;
import com.esri.core.io.UserCredentials;
import com.gis.tiandimap.config.TDTUrl;
import com.gis.tiandimap.config.TianDiTuTiledMapServiceType;
public class TianDiTuTiledMapServiceLayer extends TiledServiceLayer {
private TianDiTuTiledMapServiceType _mapType;
private TileInfo tiandituTileInfo;
public TianDiTuTiledMapServiceLayer() {
this(null, null,true);
}
public TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType mapType){
this(mapType, null,true);
}
public TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType mapType,UserCredentials usercredentials){
this(mapType, usercredentials, true);
}
public TianDiTuTiledMapServiceLayer(TianDiTuTiledMapServiceType mapType, UserCredentials usercredentials, boolean flag){
super("");
this._mapType=mapType;
setCredentials(usercredentials);
if(flag)
try
{
getServiceExecutor().submit(new Runnable() {
public final void run()
{
a.initLayer();
}
final TianDiTuTiledMapServiceLayer a;
{
a = TianDiTuTiledMapServiceLayer.this;
//super();
}
});
return;
}
catch(RejectedExecutionException _ex) { }
}
public TianDiTuTiledMapServiceType getMapType(){
return this._mapType;
}
protected void initLayer(){
this.buildTileInfo();
this.setFullExtent(new Envelope(-180,-90,180,90));
this.setDefaultSpatialReference(SpatialReference.create(4490)); //CGCS2000
//this.setDefaultSpatialReference(SpatialReference.create(4326));
this.setInitialExtent(new Envelope(90.52,33.76,113.59,42.88));
super.initLayer();
}
public void refresh()
{
try
{
getServiceExecutor().submit(new Runnable() {
public final void run()
{
if(a.isInitialized())
try
{
a.b();
a.clearTiles();
return;
}
catch(Exception exception)
{
Log.e("ArcGIS", "Re-initialization of the layer failed.", exception);
}
}
final TianDiTuTiledMapServiceLayer a;
{
a = TianDiTuTiledMapServiceLayer.this;
//super();
}
});
return;
}
catch(RejectedExecutionException _ex)
{
return;
}
}
final void b()
throws Exception
{
}
@Override
protected byte[] getTile(int level, int col, int row) throws Exception {
/**
*
* */
return com.esri.core.internal.b.a.a.a(this.getTianDiMapUrl(level, col, row), null,d());
}
private com.esri.core.internal.b.a.i d() {
// TODO Auto-generated method stub
return null;
}
@Override
public TileInfo getTileInfo(){
return this.tiandituTileInfo;
}
/**
*
* */
private String getTianDiMapUrl(int level, int col, int row){
String url=new TDTUrl(level,col,row,this._mapType).generatUrl();
return url;
}
private void buildTileInfo()
{
Point originalPoint=new Point(-180,90);
double[] scale={
400000000,
295497598.5708346,
147748799.285417,
73874399.6427087,
36937199.8213544,
18468599.9106772,
9234299.95533859,
4617149.97766929,
2308574.98883465,
1154287.49441732,
577143.747208662,
288571.873604331,
144285.936802165,
72142.9684010827,
36071.4842005414,
18035.7421002707,
9017.87105013534,
4508.93552506767,
2254.467762533835,
1127.2338812669175,
563.616940
};
double[] res={
1.40625,
0.703125,
0.3515625,
0.17578125,
0.087890625,
0.0439453125,
0.02197265625,
0.010986328125,
0.0054931640625,
0.00274658203125,
0.001373291015625,
0.0006866455078125,
0.00034332275390625,
0.000171661376953125,
8.58306884765629E-05,
4.29153442382814E-05,
2.14576721191407E-05,
1.07288360595703E-05,
5.36441802978515E-06,
2.68220901489258E-06,
1.34110450744629E-06
};
int levels=21;
int dpi=96;
int tileWidth=256;
int tileHeight=256;
this.tiandituTileInfo=new com.esri.android.map.TiledServiceLayer.TileInfo(originalPoint, scale, res, levels, dpi, tileWidth,tileHeight);
this.setTileInfo(this.tiandituTileInfo);
}
}
////////////////////////////////////////////////////////////////////////////////
//
//Copyright(C) 2013
//Author:LL
//文件名:
//文件功能描述:生成天地图切片的url地址
//
//创建标识:
////////////////////////////////////////////////////////////////////////////////
package com.gis.tiandimap.config;
import java.util.Random;
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://tile");
Random random=new Random();
int subdomain = (random.nextInt(6) + 1);
url.append(subdomain);
switch(this._tiandituMapServiceType){
case TDT_VECTOR_SERVICE:
if(this._level<=10){
url.append(".tianditu.com/DataServer?T=A0512_EMap&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
}else if(this._level<=12){
url.append(".tianditu.com/DataServer?T=B0627_EMap1112&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
}else if(this._level<=18){
url.append(".tianditu.com/DataServer?T=siwei0608&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
}
break;
case TDT_LATTIC_SERVICE:
break;
case TDT_VECTOR_LABEL_SERVICE:
if(this._level<=10){
url.append(".tianditu.com/DataServer?T=AB0512_Anno&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);
}else{
//可用空白图片代替
return null;
}
break;
case TDT_LATTIC_LABEL_SERVICE:
break;
default:
return null;
}
return url.toString();
}
}
////////////////////////////////////////////////////////////////////////////////
//
//Copyright(C) 2013
//Author:LL
//文件名:
//文件功能描述:枚举类,天地图的矢量和影像
//
//创建标识:
////////////////////////////////////////////////////////////////////////////////
package com.gis.tiandimap.config;
public enum TianDiTuTiledMapServiceType {
/**
* 天地图矢量
* */
TDT_VECTOR_SERVICE,
/**
* 天地图影像
* */
TDT_LATTIC_SERVICE,
/**
* 天地图矢量标注
* */
TDT_VECTOR_LABEL_SERVICE,
/**
* 天地图影像标注
* */
TDT_LATTIC_LABEL_SERVICE
}
该博客介绍了如何在Android应用中使用ArcGIS API来调用天地图服务,包括天地图的矢量、影像及标注服务。通过示例代码展示了如何生成不同级别的地图切片URL。
3396

被折叠的 条评论
为什么被折叠?



