天地图做为国家发布的地理信息公共服务平台,“天地图”网站装载了覆盖全球的地理信息数据,这些数据以矢量、影像、三维3种模式全方位、多角度展现,可漫游、能缩放,具有多类型全面的地理信息服务。

那怎么在Android程序中使用呢?

常量类:

public class TDTConstant {public static final String LAYER_NAME_VECTOR = "vec";public static final String LAYER_NAME_VECTOR_ANNOTATION_CHINESE = "cva";public static final String LAYER_NAME_VECTOR_ANNOTATION_ENGLISH = "eva";public static final String LAYER_NAME_IMAGE = "img";public static final String LAYER_NAME_IMAGE_ANNOTATION_CHINESE = "cia";public static final String LAYER_NAME_IMAGE_ANNOTATION_ENGLISH = "eia";public static final String LAYER_NAME_TERRAIN = "ter";public static final String LAYER_NAME_TERRAIN_ANNOTATION_CHINESE = "cta";public static final String TILE_MATRIX_SET_MERCATOR = "w";public static final String TILE_MATRIX_SET_2000 = "c";public static final Point ORIGIN_2000 = new Point(-180 + 0.000160, 90 - 0.000110);public static final Point ORIGIN_MERCATOR = new Point(-20037508.3427892, 20037508.3427892);public static final int SRID_2000 = 4490;public static final int SRID_MERCATOR = 102100;public static final double X_MIN_2000 = -180;public static final double Y_MIN_2000 = -90;public static final double X_MAX_2000 = 180;public static final double Y_MAX_2000 = 90;public static final double X_MIN_MERCATOR = -20037508.3427892;private static final double Y_MIN_MERCATOR = -20037508.3427892;public static final double X_MAX_MERCATOR = 20037508.3427892;public static final double Y_MAX_MERCATOR = 20037508.3427892;public static final int tileWidth = 256;public static final int tileHeight = 256;public static final int dpi = 96;public static final double[] SCALES = { 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};//,2254.467762533835, 1127.2338812669175, 563.616940// //错误   public static final double[] RESOLUTIONS_MERCATOR = { 78271.51696402048, 39135.75848201024, 19567.87924100512, 9783.93962050256, 4891.96981025128, 2445.98490512564, 1222.99245256282,
//            611.49622628141, 305.748113140705, 152.8740565703525, 76.43702828517625, 38.21851414258813, 19.109257071294063, 9.554628535647032, 4.777314267823516, 2.388657133911758, 1.194328566955879,
//            0.5971642834779395 };public static final double[] RESOLUTIONS_2000 = { 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-06public static final Envelope Envelope_2000 = new Envelope(TDTConstant.X_MIN_2000,TDTConstant.Y_MIN_2000, TDTConstant.X_MAX_2000,TDTConstant.Y_MAX_2000);public static final Envelope Envelope_MERCATOR = new Envelope(TDTConstant.X_MIN_MERCATOR,TDTConstant.Y_MIN_MERCATOR, TDTConstant.X_MAX_MERCATOR,TDTConstant.Y_MAX_MERCATOR);public static final TiledServiceLayer.TileInfo TileInfo_2000 = new TiledServiceLayer.TileInfo(TDTConstant.ORIGIN_2000,TDTConstant.SCALES, TDTConstant.RESOLUTIONS_2000,TDTConstant.SCALES.length, TDTConstant.dpi,TDTConstant.tileWidth, TDTConstant.tileHeight);//    public static final TiledServiceLayer.TileInfo TileInfo_MERCATOR = new TiledServiceLayer.TileInfo(TDTConstant.ORIGIN_MERCATOR,
//            TDTConstant.SCALES, TDTConstant.RESOLUTIONS_MERCATOR,
//            TDTConstant.SCALES.length, TDTConstant.dpi,
//            TDTConstant.tileWidth, TDTConstant.tileHeight);}

天地图实体类:

public class TDTInfo {private String layerName;private int minZoomLevel = 0;private int maxZoomLevel = 17;private int srid;private String tileMatrixSet;private Envelope envelope;private TiledServiceLayer.TileInfo tileInfo;private TDTType mapType;public TDTType getMapType() {return mapType;}public void setMapType(TDTType mapType) {this.mapType = mapType;}public TiledServiceLayer.TileInfo getTileInfo() {return tileInfo;}public void setTileInfo(TiledServiceLayer.TileInfo tileInfo) {this.tileInfo = tileInfo;}public String getLayerName() {return layerName;}public void setLayerName(String layerName) {this.layerName = layerName;}public int getMinZoomLevel() {return minZoomLevel;}public void setMinZoomLevel(int minZoomLevel) {this.minZoomLevel = minZoomLevel;}public int getMaxZoomLevel() {return maxZoomLevel;}public void setMaxZoomLevel(int maxZoomLevel) {this.maxZoomLevel = maxZoomLevel;}public int getSrid() {return srid;}public void setSrid(int srid) {this.srid = srid;}public String getTileMatrixSet() {return tileMatrixSet;}public void setTileMatrixSet(String tileMatrixSet) {this.tileMatrixSet = tileMatrixSet;}public Envelope getEnvelope() {return envelope;}public void setEnvelope(Envelope envelope) {this.envelope = envelope;}

常用类型枚举:

public enum  TDTType {/*** 天地图矢量* */VEC_C,/*** 天地图影像* */IMG_C,/*** 天地图矢量标注* */CVA_C,/*** 天地图影像标注* */CIA_C,
}

URL封装类:

public class TDTUrl {private TDTType _tiandituMapServiceType;private int _level;private int _col;private int _row;public TDTUrl(int level, int col, int row, TDTType tiandituMapServiceType) {this._level = level;this._col = col;this._row = row;this._tiandituMapServiceType = tiandituMapServiceType;}public String getUrl() {StringBuilder url1 = new StringBuilder("http://t");StringBuilder url2 = new StringBuilder("http://t0.tianditu.com/");Random random = new Random();int subdomain = (random.nextInt(6) + 1);url1.append(subdomain);switch (this._tiandituMapServiceType) {case VEC_C://矢量url1.append(".tianditu.com/DataServer?T=").append("vec_c").append("&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);url2.append("vec_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=c&TILEMATRIX="+this._level+"&TILEROW="+this._row+"&TILECOL="+this._col+"&FORMAT=tiles");break;case CVA_C://矢量注记url1.append(".tianditu.com/DataServer?T=").append("cva_c").append("&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);url2.append("cva_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=c&TILEMATRIX="+this._level+"&TILEROW="+this._row+"&TILECOL="+this._col+"&FORMAT=tiles");break;case CIA_C://影像注记url1.append(".tianditu.com/DataServer?T=").append("cia_c").append("&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);url2.append("cia_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=c&TILEMATRIX="+this._level+"&TILEROW="+this._row+"&TILECOL="+this._col+"&FORMAT=tiles");break;case IMG_C://影像url1.append(".tianditu.com/DataServer?T=").append("img_c").append("&X=").append(this._col).append("&Y=").append(this._row).append("&L=").append(this._level);url2.append("img_c/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=c&TILEMATRIX="+this._level+"&TILEROW="+this._row+"&TILECOL="+this._col+"&FORMAT=tiles");break;default:break;}if (this._level > 10) {//System.out.println(url2.toString());return url2.toString();} else {//System.out.println(url1.toString());return url1.toString();}}}

天地图图层类(加本地缓存功能):

public class TDTTiedMapLayer extends TiledServiceLayer {//本地缓存路径public static String cachepath = MyApplication.basePath+"TileTDT";private TDTInfo _TDTInfo;public TDTTiedMapLayer(TDTInfo _TDTInfo) {super(true);this._TDTInfo=_TDTInfo;this.init();}private void init(){try {getServiceExecutor().submit(new Runnable() {@Overridepublic void run() {TDTTiedMapLayer.this.initLayer();}});}catch (RejectedExecutionException e){Log.e("TDT Map Layer", "initialization of the layer failed.",e);}}protected void initLayer(){if (getID() == 0L) {nativeHandle = create();changeStatus(com.esri.android.map.event.OnStatusChangedListener.STATUS.fromInt(-1000));} else {//设置瓦片信息this.setTileInfo(new com.esri.android.map.TiledServiceLayer.TileInfo(ORIGIN_2000, SCALES, RESOLUTIONS_2000, RESOLUTIONS_2000.length, dpi, tileWidth,tileHeight));//设置全幅边界、默认坐标系、初始边界this.setFullExtent(new Envelope(95.80873303426465, 16.036465898612885, 123.5371052042365, 33.491348458866938));this.setDefaultSpatialReference(SpatialReference.create(SRID_2000)); // CGCS2000this.setInitialExtent(new Envelope(108.80873303426465, 20.036465898612885, 117.5371052042365, 26.491348458866938));//执行父类初始化super.initLayer();}}@Overrideprotected byte[] getTile(int level, int col, int row) throws Exception {if (level>_TDTInfo.getMaxZoomLevel()||level<_TDTInfo.getMinZoomLevel())return new byte[0];byte[] bytes= getOffLineCacheFile(_TDTInfo.getMapType().toString(), level, col, row);try {if (bytes==null) {String url = (new TDTUrl(level, col, row, _TDTInfo.getMapType())).getUrl();bytes = com.esri.core.internal.io.handler.a.a(url,new HashMap());addOfflineCacheFile(_TDTInfo.getMapType().toString(), level, col, row,bytes);}}catch(Exception e){e.printStackTrace();}return bytes;}private byte[] getOffLineCacheFile(String _TDTType,int _level,int _col,int _row)throws IOException{File file=new File(cachepath+"/"+_TDTType+"/"+_level+"/"+_col+"/"+_row+".dat");if (file.exists()) {FileInputStream in = new FileInputStream(file);ByteArrayOutputStream out = new ByteArrayOutputStream(1024);byte[] temp = new byte[1024];int size = 0;while ((size = in.read(temp)) != -1) {out.write(temp, 0, size);}in.close();byte[] bytes = out.toByteArray();return bytes;}else {return null;}}private void addOfflineCacheFile(String _TDTType,int _level,int _col,int _row,byte[] bytes){File file=new File(cachepath);if (!file.exists()){file.mkdir();}File typeFile=new File(cachepath+"/"+_TDTType);if (!typeFile.exists()){typeFile.mkdir();}File levelFile=new File(cachepath+"/"+_TDTType+"/"+_level);if (!levelFile.exists()){levelFile.mkdir();}File colFile=new File(cachepath+"/"+_TDTType+"/"+_level+"/"+_col);if (!colFile.exists()){colFile.mkdir();}File rowFile=new File(cachepath+"/"+_TDTType+"/"+_level+"/"+_col+"/"+_row+".dat");if (!rowFile.exists()){try {FileOutputStream outputStream=new FileOutputStream(rowFile);outputStream.write(bytes);outputStream.close();}catch (IOException e){e.printStackTrace();}}}
}

调用:

    private void initBaseMap(){TDTInfo tdtInfo=new TDTInfo();tdtInfo.setMapType(TDTType.VEC_C);TDTInfo tdtInfo1=new TDTInfo();tdtInfo1.setMapType(TDTType.CVA_C);Layer layer2d=new TDTTiedMapLayer(tdtInfo);Layer layer2dzj=new TDTTiedMapLayer(tdtInfo1);mapView.addLayer(layer2d);mapView.addLayer(layer2dzj);}

Arcgis For Android 加载天地图(拥有缓存功能)相关推荐

  1. (转)Arcgis for js加载天地图

    http://blog.csdn.net/gisshixisheng/article/details/44494715 综述:本节讲述的是用Arcgis for js加载天地图的切片资源. 天地图的切 ...

  2. Arcgis for android 加载谷歌、高德和天地图

    1.加载谷歌地图 工具类: package com.chy.google;import com.esri.arcgisruntime.arcgisservices.LevelOfDetail; imp ...

  3. Android加载用户头像的功能实现

    加载用户头像的过程是,首先从本地查看是否存储了用户的头像,如果有,则从本地读取后加载到ImageView中,如果没有,则去服务器下载头像保存到本地,并加载. public void initData( ...

  4. (转载)arcgis for js - 解决加载天地图和WMTS服务,WMTS服务不显示的问题,以及wmts服务密钥。...

    1 arcgis加载天地图和wmts服务 arcgis for js加载天地图的例子网上有很多,这里先不写了,后期有空再贴代码,这里主要分析下WMTS服务为什么不显示,怎么解决. 条件:这里的WMTS ...

  5. 基于ArcGIS API for JavaScript加载天地图

    文章目录 前言 效果图 详细代码 总结 参考链接 前言 该篇主要介绍如何用ArcGIS JS API加载天地图,具体应用场景以及需求分析等,在上篇基于ArcGIS API for JavaScript ...

  6. ArcGIS中加载天地图省级遥感影像服务

    天地图遥感影像的分辨率一般都是米级别的,而且更新的速度也是越来越快.质量也越来越好,那我们如何使用这方面的资源呢,本期我就给大家梳理一下,如何在ArcGIS软件中加载天地图省级遥感影像服务WMTS. ...

  7. (转)Openlayers 2.X加载天地图

    http://blog.csdn.net/gisshixisheng/article/details/44621923 概述: 在前面的章节,讲到了Arcgis for js加载天地图,在本节讲述如何 ...

  8. (转) Arcgis for js加载百度地图

    http://blog.csdn.net/gisshixisheng/article/details/44853709 概述: 在前面的文章里提到了Arcgis for js加载天地图,在本节,继续讲 ...

  9. arcgis for Android 100.1 在线加载天地图和谷歌地图

    距离上一篇arcgis for Android 已经很久.其实年初的时候就测试了arcgis for Android 100.1版本.搜集网上各篇文章,最后自已测试代码.修改代码.这一篇来讲一下加载在 ...

最新文章

  1. 如何用8GB树莓派替代MacBookPro?
  2. 【深度学习】keras框架使用预训练模型进行Finetune的应用
  3. python中文编辑器推荐-Python使用什么编辑比较好,Python编辑器推荐
  4. 字符流与字节流转换输出
  5. 通过console口连接交换机
  6. Some Essential JavaScript Questions And Answers(5)
  7. react apollo_Apollo GraphQL:如何使用React和Node Js构建全栈应用
  8. 45.MySQL Cluster
  9. 百度地图,你必须知道的自定义Marker图标方法
  10. (求救大佬)蓝桥杯C语言试题 算法训练 C++ CH08 01
  11. 《集成电路制造工艺与工程应用》目录
  12. 尼日利亚4g频段_4G全球频段划分及主要运营商对应表2015版
  13. 如何轻松查询分析多个快递单号物流到站派件延误件
  14. Week15 - 程序设计思维与实践 - 字符串算法
  15. Attention注意力机制–原理与应用
  16. React中createRef()和useRef()的使用方法
  17. AD——PCB布线实用技巧
  18. cometd: Bayeux Protocol
  19. android 中文开发文档
  20. 数据结构练习题---先序遍历二叉树

热门文章

  1. 润滑剂粘度调节剂的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  2. vb.net如何查询电脑麦克风收到声音_远程会议痛点多?看Poly Studio X30如何破局
  3. 秀日记:这个升学比例吓坏大家了
  4. Android blueZ HCI(二):hcitool hcidump常用方法
  5. 使用http访问页面时,将其跳转成https
  6. 风力发电机组机械功率Pm与转子转速Wm关系(Matlab实现)
  7. 【人工智能】基于百度AI+Python编程的简单应用:关于人像照片动漫化的分析实现(可进行批量化处理)——教你看到二次元中的自己
  8. 基于vue3的京东nutui组件库的表单校验规则:怎样进行表单验证?怎样只使用指定的某一个规则进行校验呢?
  9. 计算机毕设之 农产品二维码溯源系统
  10. Java小农养成记第十三天