距离上一篇arcgis for Android 已经很久。其实年初的时候就测试了arcgis for Android 100.1版本。搜集网上各篇文章,最后自已测试代码。修改代码。这一篇来讲一下加载在线的天地图和谷歌地图。
arcgis for Android 100.1 基本操作(缩小放大旋转定位)
1、效果图
加载天地图没有问题,只是我测试谷歌时候,只能看到屏幕上这些地图,其他滑动出去,就没有,不知道为什么。有知道的大神可以评论一下。
1、天地图的代码
这个网上搜集代码,封装好的天地图使用类:
package com.arcgis.until;
import com.esri.arcgisruntime.arcgisservices.LevelOfDetail;
import com.esri.arcgisruntime.arcgisservices.TileInfo;
import com.esri.arcgisruntime.geometry.Envelope;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReference;
import com.esri.arcgisruntime.layers.WebTiledLayer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 天地图
*/
public class TianDiTuMethodsClass {
private static final List<String> SubDomain = Arrays.asList(new String[]{"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"});
private static final String URL_VECTOR_2000 = "http://{subDomain}.tianditu.com/DataServer?T=vec_c&x={col}&y={row}&l={level}";
private static final String URL_VECTOR_ANNOTATION_CHINESE_2000 = "http://{subDomain}.tianditu.com/DataServer?T=cva_c&x={col}&y={row}&l={level}";
private static final String URL_VECTOR_ANNOTATION_ENGLISH_2000 = "http://{subDomain}.tianditu.com/DataServer?T=eva_c&x={col}&y={row}&l={level}";
private static final String URL_IMAGE_2000 = "http://{subDomain}.tianditu.com/DataServer?T=img_c&x={col}&y={row}&l={level}";
private static final String URL_IMAGE_ANNOTATION_CHINESE_2000 = "http://{subDomain}.tianditu.com/DataServer?T=cia_c&x={col}&y={row}&l={level}";
private static final String URL_IMAGE_ANNOTATION_ENGLISH_2000 = "http://{subDomain}.tianditu.com/DataServer?T=eia_c&x={col}&y={row}&l={level}";
private static final String URL_TERRAIN_2000 = "http://{subDomain}.tianditu.com/DataServer?T=ter_c&x={col}&y={row}&l={level}";
private static final String URL_TERRAIN_ANNOTATION_CHINESE_2000 = "http://{subDomain}.tianditu.com/DataServer?T=cta_c&x={col}&y={row}&l={level}";
private static final String URL_VECTOR_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=vec_w&x={col}&y={row}&l={level}";
private static final String URL_VECTOR_ANNOTATION_CHINESE_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=cva_w&x={col}&y={row}&l={level}";
private static final String URL_VECTOR_ANNOTATION_ENGLISH_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=eva_w&x={col}&y={row}&l={level}";
private static final String URL_IMAGE_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=img_w&x={col}&y={row}&l={level}";
private static final String URL_IMAGE_ANNOTATION_CHINESE_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=cia_w&x={col}&y={row}&l={level}";
private static final String URL_IMAGE_ANNOTATION_ENGLISH_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=eia_w&x={col}&y={row}&l={level}";
private static final String URL_TERRAIN_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=ter_w&x={col}&y={row}&l={level}";
private static final String URL_TERRAIN_ANNOTATION_CHINESE_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=cta_w&x={col}&y={row}&l={level}";
private static final int DPI = 96;
private static final int minZoomLevel = 1;
private static final int maxZoomLevel = 18;
private static final int tileWidth = 256;
private static final int tileHeight = 256;
private static final String LAYER_NAME_VECTOR = "vec";
private static final String LAYER_NAME_VECTOR_ANNOTATION_CHINESE = "cva";
private static final String LAYER_NAME_VECTOR_ANNOTATION_ENGLISH = "eva";
private static final String LAYER_NAME_IMAGE = "img";
private static final String LAYER_NAME_IMAGE_ANNOTATION_CHINESE = "cia";
private static final String LAYER_NAME_IMAGE_ANNOTATION_ENGLISH = "eia";
private static final String LAYER_NAME_TERRAIN = "ter";
private static final String LAYER_NAME_TERRAIN_ANNOTATION_CHINESE = "cta";
private static final SpatialReference SRID_2000 = SpatialReference.create(4490);
private static final SpatialReference SRID_MERCATOR = SpatialReference.create(102100);
private static final double X_MIN_2000 = -180;
private static final double Y_MIN_2000 = -90;
private static final double X_MAX_2000 = 180;
private static final double Y_MAX_2000 = 90;
private static final double X_MIN_MERCATOR = -20037508.3427892;
private static final double Y_MIN_MERCATOR = -20037508.3427892;
private static final double X_MAX_MERCATOR = 20037508.3427892;
private static final double Y_MAX_MERCATOR = 20037508.3427892;
private static final Point ORIGIN_2000 = new Point(-180, 90, SRID_2000);
private static final Point ORIGIN_MERCATOR = new Point(-20037508.3427892, 20037508.3427892, SRID_MERCATOR);
private static final Envelope ENVELOPE_2000 = new Envelope(X_MIN_2000, Y_MIN_2000, X_MAX_2000, Y_MAX_2000, SRID_2000);
private static final Envelope ENVELOPE_MERCATOR = new Envelope(X_MIN_MERCATOR, Y_MIN_MERCATOR, X_MAX_MERCATOR, Y_MAX_MERCATOR, SRID_MERCATOR);
private 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,
1128.4994333441375
};
private 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,
0.298582141738970};
private 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 WebTiledLayer CreateTianDiTuTiledLayer(String layerType) {
return CreateTianDiTuTiledLayer(getTianDiTuLayerType(layerType));
}
public static WebTiledLayer CreateTianDiTuTiledLayer(LayerType layerType) {
WebTiledLayer webTiledLayer = null;
String mainUrl = "";
String mainName = "";
TileInfo mainTileInfo = null;
Envelope mainEnvelope = null;
boolean mainIs2000 = false;
try {
switch (layerType) {
case TIANDITU_VECTOR_2000:
mainUrl = URL_VECTOR_2000;
mainName = LAYER_NAME_VECTOR;
mainIs2000 = true;
break;
case TIANDITU_VECTOR_MERCATOR:
mainUrl = URL_VECTOR_MERCATOR;
mainName = LAYER_NAME_VECTOR;
break;
case TIANDITU_IMAGE_2000:
mainUrl = URL_IMAGE_2000;
mainName = LAYER_NAME_IMAGE;
mainIs2000 = true;
break;
case TIANDITU_IMAGE_ANNOTATION_CHINESE_2000:
mainUrl = URL_IMAGE_ANNOTATION_CHINESE_2000;
mainName = LAYER_NAME_IMAGE_ANNOTATION_CHINESE;
mainIs2000 = true;
break;
case TIANDITU_IMAGE_ANNOTATION_ENGLISH_2000:
mainUrl = URL_IMAGE_ANNOTATION_ENGLISH_2000;
mainName = LAYER_NAME_IMAGE_ANNOTATION_ENGLISH;
mainIs2000 = true;
break;
case TIANDITU_IMAGE_ANNOTATION_CHINESE_MERCATOR:
mainUrl = URL_IMAGE_ANNOTATION_CHINESE_MERCATOR;
mainName = LAYER_NAME_IMAGE_ANNOTATION_CHINESE;
break;
case TIANDITU_IMAGE_ANNOTATION_ENGLISH_MERCATOR:
mainUrl = URL_IMAGE_ANNOTATION_ENGLISH_MERCATOR;
mainName = LAYER_NAME_IMAGE_ANNOTATION_ENGLISH;
break;
case TIANDITU_IMAGE_MERCATOR:
mainUrl = URL_IMAGE_MERCATOR;
mainName = LAYER_NAME_IMAGE;
break;
case TIANDITU_VECTOR_ANNOTATION_CHINESE_2000:
mainUrl = URL_VECTOR_ANNOTATION_CHINESE_2000;
mainName = LAYER_NAME_VECTOR_ANNOTATION_CHINESE;
mainIs2000 = true;
break;
case TIANDITU_VECTOR_ANNOTATION_ENGLISH_2000:
mainUrl = URL_VECTOR_ANNOTATION_ENGLISH_2000;
mainName = LAYER_NAME_VECTOR_ANNOTATION_ENGLISH;
mainIs2000 = true;
break;
case TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR:
mainUrl = URL_VECTOR_ANNOTATION_CHINESE_MERCATOR;
mainName = LAYER_NAME_VECTOR_ANNOTATION_CHINESE;
break;
case TIANDITU_VECTOR_ANNOTATION_ENGLISH_MERCATOR:
mainUrl = URL_VECTOR_ANNOTATION_ENGLISH_MERCATOR;
mainName = LAYER_NAME_VECTOR_ANNOTATION_ENGLISH;
break;
case TIANDITU_TERRAIN_2000:
mainUrl = URL_TERRAIN_2000;
mainName = LAYER_NAME_TERRAIN;
mainIs2000 = true;
break;
case TIANDITU_TERRAIN_ANNOTATION_CHINESE_2000:
mainUrl = URL_TERRAIN_ANNOTATION_CHINESE_2000;
mainName = LAYER_NAME_TERRAIN_ANNOTATION_CHINESE;
mainIs2000 = true;
break;
case TIANDITU_TERRAIN_MERCATOR:
mainUrl = URL_TERRAIN_MERCATOR;
mainName = LAYER_NAME_TERRAIN;
break;
case TIANDITU_TERRAIN_ANNOTATION_CHINESE_MERCATOR:
mainUrl = URL_TERRAIN_ANNOTATION_CHINESE_MERCATOR;
mainName = LAYER_NAME_TERRAIN_ANNOTATION_CHINESE;
break;
}
List<LevelOfDetail> mainLevelOfDetail = new ArrayList<LevelOfDetail>();
Point mainOrigin = null;
if (mainIs2000 == true) {
for (int i = minZoomLevel; i <= maxZoomLevel; i++) {
LevelOfDetail item = new LevelOfDetail(i, RESOLUTIONS_2000[i - 1], SCALES[i - 1]);
mainLevelOfDetail.add(item);
}
mainEnvelope = ENVELOPE_2000;
mainOrigin = ORIGIN_2000;
} else {
for (int i = minZoomLevel; i <= maxZoomLevel; i++) {
LevelOfDetail item = new LevelOfDetail(i, RESOLUTIONS_MERCATOR[i - 1], SCALES[i - 1]);
mainLevelOfDetail.add(item);
}
mainEnvelope = ENVELOPE_MERCATOR;
mainOrigin = ORIGIN_MERCATOR;
}
mainTileInfo = new TileInfo(
DPI,
TileInfo.ImageFormat.PNG24,
mainLevelOfDetail,
mainOrigin,
mainOrigin.getSpatialReference(),
tileHeight,
tileWidth
);
webTiledLayer = new WebTiledLayer(
mainUrl,
SubDomain,
mainTileInfo,
mainEnvelope);
webTiledLayer.setName(mainName);
webTiledLayer.loadAsync();
} catch (Exception e) {
e.getCause();
}
return webTiledLayer;
}
protected static LayerType getTianDiTuLayerType(String layerType) {
LayerType result = LayerType.TIANDITU_VECTOR_2000;
switch (layerType) {
/**
* 天地图矢量墨卡托投影地图服务
*/
case "TIANDITU_VECTOR_MERCATOR":
result = LayerType.TIANDITU_VECTOR_MERCATOR;
break;
/**
* 天地图矢量墨卡托中文标注
*/
case "TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR":
result = LayerType.TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR;
break;
/**
* 天地图矢量墨卡托英文标注
*/
case "TIANDITU_VECTOR_ANNOTATION_ENGLISH_MERCATOR":
result = LayerType.TIANDITU_VECTOR_ANNOTATION_ENGLISH_MERCATOR;
break;
/**
* 天地图影像墨卡托投影地图服务
*/
case "TIANDITU_IMAGE_MERCATOR":
result = LayerType.TIANDITU_IMAGE_MERCATOR;
break;
/**
* 天地图影像墨卡托投影中文标注
*/
case "TIANDITU_IMAGE_ANNOTATION_CHINESE_MERCATOR":
result = LayerType.TIANDITU_IMAGE_ANNOTATION_CHINESE_MERCATOR;
break;
/**
* 天地图影像墨卡托投影英文标注
*/
case "TIANDITU_IMAGE_ANNOTATION_ENGLISH_MERCATOR":
result = LayerType.TIANDITU_IMAGE_ANNOTATION_ENGLISH_MERCATOR;
break;
/**
* 天地图地形墨卡托投影地图服务
*/
case "TIANDITU_TERRAIN_MERCATOR":
result = LayerType.TIANDITU_TERRAIN_MERCATOR;
break;
/**
* 天地图地形墨卡托投影中文标注
*/
case "TIANDITU_TERRAIN_ANNOTATION_CHINESE_MERCATOR":
result = LayerType.TIANDITU_TERRAIN_ANNOTATION_CHINESE_MERCATOR;
break;
/**
* 天地图矢量国家2000坐标系地图服务
*/
case "TIANDITU_VECTOR_2000":
result = LayerType.TIANDITU_VECTOR_2000;
break;
/**
* 天地图矢量国家2000坐标系中文标注
*/
case "TIANDITU_VECTOR_ANNOTATION_CHINESE_2000":
result = LayerType.TIANDITU_VECTOR_ANNOTATION_CHINESE_2000;
break;
/**
* 天地图矢量国家2000坐标系英文标注
*/
case "TIANDITU_VECTOR_ANNOTATION_ENGLISH_2000":
result = LayerType.TIANDITU_VECTOR_ANNOTATION_ENGLISH_2000;
break;
/**
* 天地图影像国家2000坐标系地图服务
*/
case "TIANDITU_IMAGE_2000":
result = LayerType.TIANDITU_IMAGE_2000;
break;
/**
* 天地图影像国家2000坐标系中文标注
*/
case "TIANDITU_IMAGE_ANNOTATION_CHINESE_2000":
result = LayerType.TIANDITU_IMAGE_ANNOTATION_CHINESE_2000;
break;
/**
* 天地图影像国家2000坐标系英文标注
*/
case "TIANDITU_IMAGE_ANNOTATION_ENGLISH_2000":
result = LayerType.TIANDITU_IMAGE_ANNOTATION_ENGLISH_2000;
break;
/**
* 天地图地形国家2000坐标系地图服务
*/
case "TIANDITU_TERRAIN_2000":
result = LayerType.TIANDITU_TERRAIN_2000;
break;
/**
* 天地图地形国家2000坐标系中文标注
*/
case "TIANDITU_TERRAIN_ANNOTATION_CHINESE_2000":
result = LayerType.TIANDITU_TERRAIN_ANNOTATION_CHINESE_2000;
break;
}
return result;
}
public enum LayerType {
/**
* 天地图矢量墨卡托投影地图服务
*/
TIANDITU_VECTOR_MERCATOR,
/**
* 天地图矢量墨卡托中文标注
*/
TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR,
/**
* 天地图矢量墨卡托英文标注
*/
TIANDITU_VECTOR_ANNOTATION_ENGLISH_MERCATOR,
/**
* 天地图影像墨卡托投影地图服务
*/
TIANDITU_IMAGE_MERCATOR,
/**
* 天地图影像墨卡托投影中文标注
*/
TIANDITU_IMAGE_ANNOTATION_CHINESE_MERCATOR,
/**
* 天地图影像墨卡托投影英文标注
*/
TIANDITU_IMAGE_ANNOTATION_ENGLISH_MERCATOR,
/**
* 天地图地形墨卡托投影地图服务
*/
TIANDITU_TERRAIN_MERCATOR,
/**
* 天地图地形墨卡托投影中文标注
*/
TIANDITU_TERRAIN_ANNOTATION_CHINESE_MERCATOR,
/**
* 天地图矢量国家2000坐标系地图服务
*/
TIANDITU_VECTOR_2000,
/**
* 天地图矢量国家2000坐标系中文标注
*/
TIANDITU_VECTOR_ANNOTATION_CHINESE_2000,
/**
* 天地图矢量国家2000坐标系英文标注
*/
TIANDITU_VECTOR_ANNOTATION_ENGLISH_2000,
/**
* 天地图影像国家2000坐标系地图服务
*/
TIANDITU_IMAGE_2000,
/**
* 天地图影像国家2000坐标系中文标注
*/
TIANDITU_IMAGE_ANNOTATION_CHINESE_2000,
/**
* 天地图影像国家2000坐标系英文标注
*/
TIANDITU_IMAGE_ANNOTATION_ENGLISH_2000,
/**
* 天地图地形国家2000坐标系地图服务
*/
TIANDITU_TERRAIN_2000,
/**
* 天地图地形国家2000坐标系中文标注
*/
TIANDITU_TERRAIN_ANNOTATION_CHINESE_2000
}
}
调用方式:
package com.arcgis.activity;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import com.arcgis.R;
import com.arcgis.until.TianDiTuMethodsClass;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReference;
import com.esri.arcgisruntime.layers.ArcGISTiledLayer;
import com.esri.arcgisruntime.layers.WebTiledLayer;
import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.MapView;
import java.util.Arrays;
import java.util.List;
public class ArcgisTiandituMapActivity extends AppCompatActivity {
private MapView mMapView;
//影像地图 _W是墨卡托投影 _c是国家2000的坐标系
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.map_view);
// webtile layer
final WebTiledLayer webTiledLayer =
TianDiTuMethodsClass.CreateTianDiTuTiledLayer(TianDiTuMethodsClass.LayerType.TIANDITU_VECTOR_MERCATOR);
webTiledLayer.loadAsync();
ArcGISMap map = new ArcGISMap(new Basemap(webTiledLayer));
Point center = new Point(113.365548756,23.12648183, SpatialReference.create(4490));// CGCS2000
mMapView.setViewpointCenterAsync(center,12);
mMapView.setMap(map);
}
protected void onResume() {
super.onResume();
mMapView.resume();
}
@Override
protected void onPause() {
super.onPause();
mMapView.pause();
}
}
3、谷歌地图的代码
自已根据天地图封装方式,封装了谷歌地图使用类
注意:测试谷歌时候,只能看到屏幕上这些地图,其他滑动出去,就没有,不知道为什么。有知道的大神可以评论一下。
package com.arcgis.until;
import com.esri.arcgisruntime.arcgisservices.LevelOfDetail;
import com.esri.arcgisruntime.arcgisservices.TileInfo;
import com.esri.arcgisruntime.data.TileKey;
import com.esri.arcgisruntime.geometry.Envelope;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReference;
import com.esri.arcgisruntime.layers.WebTiledLayer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class GoogleMapLayer{
private static final int DPI = 96;
private static final int minZoomLevel = 1;
private static final int maxZoomLevel = 19;
private static final int tileWidth = 256;
private static final int tileHeight = 256;
// 枚举
public enum MapType {
VECTOR, //矢量标注地图
IMAGE, //影像地图
ROAD //道路标注图层
}
private MapType mMapType;
private static final List<String> SubDomain = Arrays.asList(new String[]{"mt0", "mt1", "mt2", "mt3", "mt4"});
//102100是esri内部使用id 与epsg:3857 是对应的
private static final SpatialReference SRID_MERCATOR = SpatialReference.create(102113);
private static final Point ORIGIN_MERCATOR = new Point(-20037508.3427892, 20037508.3427892, SRID_MERCATOR);
private static final Envelope ENVELOPE_MERCATOR = new Envelope(-22041257.773878,
-32673939.6727517, 22041257.773878, 20851350.0432886, SRID_MERCATOR);
private static double[] SCALES = new double[] { 591657527.591555,
295828763.79577702, 147914381.89788899, 73957190.948944002,
36978595.474472001, 18489297.737236001, 9244648.8686180003,
4622324.4343090001, 2311162.217155, 1155581.108577, 577790.554289,
288895.277144, 144447.638572, 72223.819286, 36111.909643,
18055.954822, 9027.9774109999998, 4513.9887049999998, 2256.994353,
1128.4971760000001 };
private static double[] iRes = new double[] { 156543.03392800014,
78271.516963999937, 39135.758482000092, 19567.879240999919,
9783.9396204999593, 4891.9698102499797, 2445.9849051249898,
1222.9924525624949, 611.49622628138, 305.748113140558,
152.874056570411, 76.4370282850732, 38.2185141425366,
19.1092570712683, 9.55462853563415, 4.7773142679493699,
2.3886571339746849, 1.1943285668550503, 0.59716428355981721,
0.29858214164761665 };
private String getMapUrl(TileKey tileKey) {
String iResult = null;
Random iRandom = null;
int level = tileKey.getLevel();
int col = tileKey.getColumn();
int row = tileKey.getRow();
iResult = "http://mt";
iRandom = new Random();
iResult = iResult + iRandom.nextInt(4);
switch (this.mMapType) {
case VECTOR:
iResult = iResult + ".google.cn/vt/lyrs=m@212000000&hl=zh-CN&gl=CN&src=app&x=" + col + "&y=" + row + "&z=" + level + "&s==Galil";
break;
case IMAGE:
iResult = iResult + ".google.cn/vt/lyrs=s@126&hl=zh-CN&gl=CN&src=app&x=" + col + "&y=" + row + "&z=" + level + "&s==Galil";
break;
case ROAD:
iResult = iResult + ".google.cn/vt/imgtp=png32&lyrs=h@212000000&hl=zh-CN&gl=CN&src=app&x=" + col + "&y=" + row + "&z=" + level + "&s==Galil";
break;
default:
return null;
}
return iResult;
}
public static WebTiledLayer CreateGoogleLayer(MapType layerType) {
WebTiledLayer webTiledLayer = null;
String mainUrl = "";
String mainName = "Google";
TileInfo mainTileInfo = null;
Envelope mainEnvelope = null;
try {
switch (layerType) {
case VECTOR:
mainUrl = "http://{subDomain}.google.cn/vt/lyrs=m@225000000&hl=zh-CN&gl=CN&src=app&s=G&x={col}&y={row}&z={level}";
break;
case ROAD:
mainUrl = "";
break;
case IMAGE:
mainUrl = "";
break;
}
List<LevelOfDetail> mainLevelOfDetail = new ArrayList<LevelOfDetail>();
Point mainOrigin = null;
for (int i = minZoomLevel; i <= maxZoomLevel; i++) {
LevelOfDetail item = new LevelOfDetail(i, iRes[i - 1], SCALES[i - 1]);
mainLevelOfDetail.add(item);
}
mainEnvelope = ENVELOPE_MERCATOR;
mainOrigin = ORIGIN_MERCATOR;
mainTileInfo = new TileInfo(
DPI,
TileInfo.ImageFormat.PNG24,
mainLevelOfDetail,
mainOrigin,
mainOrigin.getSpatialReference(),
tileHeight,
tileWidth
);
webTiledLayer = new WebTiledLayer(
mainUrl,
SubDomain,
mainTileInfo,
mainEnvelope);
webTiledLayer.setName(mainName);
webTiledLayer.loadAsync();
} catch (Exception e) {
e.getCause();
}
return webTiledLayer;
}
}
调用方式
package com.arcgis.activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.arcgis.R;
import com.arcgis.until.GoogleMapLayer;
import com.arcgis.until.TianDiTuMethodsClass;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReference;
import com.esri.arcgisruntime.layers.WebTiledLayer;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.MapView;
public class ArcgisGoogleMapActivity extends AppCompatActivity {
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.map_view);
// webtile layer
final WebTiledLayer webTiledLayer =
GoogleMapLayer.CreateGoogleLayer(GoogleMapLayer.MapType.VECTOR);
webTiledLayer.loadAsync();
ArcGISMap map = new ArcGISMap(new Basemap(webTiledLayer));
mMapView.setMap(map);
}
protected void onResume() {
super.onResume();
mMapView.resume();
}
@Override
protected void onPause() {
super.onPause();
mMapView.pause();
}
}
新手一定要注意权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />