在项目中可以经常需要动态加载一些图层,像投影地图服务、投影地图服务器。其实网上有大量这样的服务,比如天地图官网,

随便点开一个服务,里面有相关的信息。那如何加载这样图层服务呢。

一、首先感谢这篇博文ArcGIS读取天地图出现错位的情况,这篇文章的下载链接也有许多有用的资料。加载天地图用到一个关键的自定义类TianDiTuLayer

package com.huang.tianditu.layer;import java.util.Map;
import java.util.concurrent.RejectedExecutionException;import android.util.Log;import com.esri.android.map.TiledServiceLayer;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.SpatialReference;public class TianDiTuLayer extends TiledServiceLayer {private TianDiTuLayerInfo layerInfo;public TianDiTuLayer(int layerType) {super(true);this.layerInfo = LayerInfoFactory.getLayerInfo(layerType);this.init();}private void init() {try {getServiceExecutor().submit(new Runnable() {public void run() {TianDiTuLayer.this.initLayer();}});} catch (RejectedExecutionException rejectedexecutionexception) {Log.e("ArcGIS", "initialization of the layer failed.", rejectedexecutionexception);}}public byte[] getTile(int level, int col, int row) throws Exception {String url = layerInfo.getUrl() + "?service=wmts&request=gettile&version=1.0.0&layer=" + layerInfo.getLayerName() + "&format=tiles&tilematrixset=" + layerInfo.getTileMatrixSet() + "&tilecol="+ col + "&tilerow=" + row + "&tilematrix=" + (level + 1);Map<String, String> map = null;return com.esri.core.internal.io.handler.a.a(url, map);}protected void initLayer() {if (getID() == 0L) {nativeHandle = create();changeStatus(com.esri.android.map.event.OnStatusChangedListener.STATUS.fromInt(-1000));} else {this.setDefaultSpatialReference(SpatialReference.create(layerInfo.getSrid()));Log.e("huang", layerInfo.toString()+"");this.setFullExtent(new Envelope(layerInfo.getxMin(), layerInfo.getyMin(), layerInfo.getxMax(), layerInfo.getyMax()));this.setTileInfo(new TileInfo(layerInfo.getOrigin(), layerInfo.getScales(), layerInfo.getResolutions(), layerInfo.getScales().length, layerInfo.getDpi(), layerInfo.getTileWidth(),layerInfo.getTileHeight()));super.initLayer();}}}

另外还有三个类,TianDiTuLayerInfo、LayerInfoFactory、TianDiTuLayerTypes这里就不贴代码了。资料下载。

二、我们修改一下代码
1.常量类TDTConstant:

package com.huang.tianditu;import com.esri.android.map.TiledServiceLayer.TileInfo;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;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, 90);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 = { 2.958293554545656E8, 1.479146777272828E8, 7.39573388636414E7, 3.69786694318207E7, 1.848933471591035E7, 9244667.357955175, 4622333.678977588,2311166.839488794, 1155583.419744397, 577791.7098721985, 288895.85493609926, 144447.92746804963, 72223.96373402482, 36111.98186701241, 18055.990933506204, 9027.995466753102,4513.997733376551, 2256.998866688275 };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 = { 0.7031249999891485, 0.35156249999999994, 0.17578124999999997, 0.08789062500000014, 0.04394531250000007, 0.021972656250000007,0.01098632812500002, 0.00549316406250001, 0.0027465820312500017, 0.0013732910156250009, 0.000686645507812499, 0.0003433227539062495, 0.00017166137695312503, 0.00008583068847656251,0.000042915344238281406, 0.000021457672119140645, 0.000010728836059570307, 0.000005364418029785169 };public 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 TileInfo TileInfo_2000 = new TileInfo(TDTConstant.ORIGIN_2000,TDTConstant.SCALES, TDTConstant.RESOLUTIONS_2000,TDTConstant.SCALES.length, TDTConstant.dpi,TDTConstant.tileWidth, TDTConstant.tileHeight);public static final TileInfo TileInfo_MERCATOR = new TileInfo(TDTConstant.ORIGIN_MERCATOR,TDTConstant.SCALES, TDTConstant.RESOLUTIONS_MERCATOR,TDTConstant.SCALES.length, TDTConstant.dpi,TDTConstant.tileWidth, TDTConstant.tileHeight);}

2.TianDiTuLayer,代码如下 :

package com.huang.tianditu;import java.util.Map;
import java.util.concurrent.RejectedExecutionException;import android.util.Log;import com.esri.android.map.TiledServiceLayer;
import com.esri.core.geometry.SpatialReference;public class TianDiTuLayer extends TiledServiceLayer {private TianDiTuInfo tianDiTuInfo;public TianDiTuLayer(TianDiTuInfo tianDiTuInfo) {super(true);this.tianDiTuInfo = tianDiTuInfo;this.init();}private void init() {try {getServiceExecutor().submit(new Runnable() {public void run() {TianDiTuLayer.this.initLayer();}});} catch (RejectedExecutionException rejectedexecutionexception) {Log.e("ArcGIS", "initialization of the layer failed.", rejectedexecutionexception);}}public byte[] getTile(int level, int col, int row) throws Exception {String url = tianDiTuInfo.getUrl() + "?service=wmts&request=gettile&version=1.0.0&layer=" + tianDiTuInfo.getLayerName() + "&format=tiles&tilematrixset=" + tianDiTuInfo.getTileMatrixSet() + "&tilecol="+ col + "&tilerow=" + row + "&tilematrix=" + (level + 1);Map<String, String> map = null;return com.esri.core.internal.io.handler.a.a(url, map);}protected void initLayer() {if (getID() == 0L) {nativeHandle = create();changeStatus(com.esri.android.map.event.OnStatusChangedListener.STATUS.fromInt(-1000));} else {this.setDefaultSpatialReference(SpatialReference.create(tianDiTuInfo.getSrid()));this.setFullExtent(tianDiTuInfo.getEnvelope());this.setTileInfo(tianDiTuInfo.getTileInfo());super.initLayer();}}}

3.TianDiTuInfo实体类:

package com.huang.tianditu;import com.esri.android.map.TiledServiceLayer.TileInfo;
import com.esri.core.geometry.Envelope;public class TianDiTuInfo {private String url;private String layerName;private int minZoomLevel = 0;private int maxZoomLevel = 17;private int srid;private String tileMatrixSet;private Envelope envelope;private TileInfo tileInfo;public String getUrl() {return url;}public void setUrl(String url) {this.url = url;}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 TileInfo getTileInfo() {return tileInfo;}public void setTileInfo(TileInfo tileInfo) {this.tileInfo = tileInfo;}}

4.Activity代码:

package com.huang.tianditu;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;import com.esri.android.map.MapView;public class TianDiTuLayerActivity extends Activity {private MapView mMapView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);mMapView = (MapView) findViewById(R.id.mapView);TianDiTuInfo tianDiTuInfo = new TianDiTuInfo();tianDiTuInfo.setUrl("http://t0.tianditu.com/vec_c/wmts");tianDiTuInfo.setLayerName(TDTConstant.LAYER_NAME_VECTOR);tianDiTuInfo.setTileMatrixSet(TDTConstant.TILE_MATRIX_SET_2000);tianDiTuInfo.setSrid(TDTConstant.SRID_2000);tianDiTuInfo.setEnvelope(TDTConstant.Envelope_2000);tianDiTuInfo.setTileInfo(TDTConstant.TileInfo_2000);mMapView.addLayer(new TianDiTuLayer(tianDiTuInfo));}}

调用的地图服务相关信息
效果图:

Android Arcgis入门(12)、加载天地图相关推荐

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

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

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

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

  3. arcgis for android(五)加载天地图

    1.上一篇文章arcgis for android 入门与提高(四)去掉属性标记和水印arcgis for android 入门与提高(四)去掉属性标记和水印_郝大大的博客-CSDN博客,接下来介绍国 ...

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

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

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

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

  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 android 天地图,Arcgis runtime for Android 100.5 加载天地图

    说明一下,什么时候加载高德地图,什么时候加载天地图 使用原生定位或者使用arcgis提供的LocationDisplay的定位时,需要加载天地图,因为原生定位返回的坐标是wgs84的坐标,而高德地图是 ...

最新文章

  1. openCV 图像相加,位运算,协方差,绝对值,比较
  2. CVE-2015-3636(pingpong root) android内核 UAF漏洞分析
  3. 计算机工具软件未来的发展,2017年我国PC及工具软件的发展概况
  4. vue 组件基本使用
  5. 路由器DHCP和DHCP中继的配置
  6. batchplot插件用法_Batchplot怎么安装及使用?Batchplot的安装方法及使用方法介绍
  7. 图片照片展示html5模板
  8. 跨境电商全球趋势与独立站布局的关键点
  9. c语言 0x12ed,C语言基本数据类型及运算题库有答案.doc
  10. kotlin 类构造函数_Kotlin类– Kotlin构造函数
  11. 计算机硬盘 u盘和光盘属于,磁盘U盘光盘的区别
  12. excel自动调整列宽_Java 设置Excel自适应行高、列宽
  13. 计算机发展历程 思维导图
  14. jshop测试分析总览
  15. 为什么SEM竞价推广效果越来越差?
  16. html表格自动分列,CSS3 Columns分列式布局方法简介
  17. Python数学建模—线性规划
  18. day40 ORM sqlalchemy
  19. 宁静、万茜等姐姐们“乘风破浪”,各品牌借势掀起新一波火热营销
  20. 漫谈数据库领域职业定位与发展

热门文章

  1. 实时性之硬实时与软实时
  2. [paper] CE2P
  3. 用计算机语言编写累加程序,用汇编语言实现如下程序:进行自然数相加(1+2+3... 汇编语言 编写程序实现自然数1到100的累加。要求用......
  4. Elasticsearch搜索引擎第十篇-Query DSL详解
  5. xxl-job基本使用
  6. 工程伦理 第九章习题 答案
  7. VCS和Verdi联合仿真
  8. 四六级英语听力发射无线广播系统在广东海洋大学阳江校区的应用
  9. 校园网可以登录其他网站和应用,却无法登录校内网站的问题的解决方法
  10. Android 7.0 删除原生输入法(AOSP)更换系统默认输入法