分享

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

 feisguan 2018-09-13



加载天地图没有问题,只是我测试谷歌时候,只能看到屏幕上这些地图,其他滑动出去,就没有,不知道为什么。有知道的大神可以评论一下。

1、天地图的代码

这个网上搜集代码,封装好的天地图使用类:

  1. package com.arcgis.until;
  2. import com.esri.arcgisruntime.arcgisservices.LevelOfDetail;
  3. import com.esri.arcgisruntime.arcgisservices.TileInfo;
  4. import com.esri.arcgisruntime.geometry.Envelope;
  5. import com.esri.arcgisruntime.geometry.Point;
  6. import com.esri.arcgisruntime.geometry.SpatialReference;
  7. import com.esri.arcgisruntime.layers.WebTiledLayer;
  8. import java.util.ArrayList;
  9. import java.util.Arrays;
  10. import java.util.List;
  11. /**
  12. * 天地图
  13. */
  14. public class TianDiTuMethodsClass {
  15. private static final List<String> SubDomain = Arrays.asList(new String[]{"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"});
  16. private static final String URL_VECTOR_2000 = "http://{subDomain}.tianditu.com/DataServer?T=vec_c&x={col}&y={row}&l={level}";
  17. private static final String URL_VECTOR_ANNOTATION_CHINESE_2000 = "http://{subDomain}.tianditu.com/DataServer?T=cva_c&x={col}&y={row}&l={level}";
  18. private static final String URL_VECTOR_ANNOTATION_ENGLISH_2000 = "http://{subDomain}.tianditu.com/DataServer?T=eva_c&x={col}&y={row}&l={level}";
  19. private static final String URL_IMAGE_2000 = "http://{subDomain}.tianditu.com/DataServer?T=img_c&x={col}&y={row}&l={level}";
  20. private static final String URL_IMAGE_ANNOTATION_CHINESE_2000 = "http://{subDomain}.tianditu.com/DataServer?T=cia_c&x={col}&y={row}&l={level}";
  21. private static final String URL_IMAGE_ANNOTATION_ENGLISH_2000 = "http://{subDomain}.tianditu.com/DataServer?T=eia_c&x={col}&y={row}&l={level}";
  22. private static final String URL_TERRAIN_2000 = "http://{subDomain}.tianditu.com/DataServer?T=ter_c&x={col}&y={row}&l={level}";
  23. private static final String URL_TERRAIN_ANNOTATION_CHINESE_2000 = "http://{subDomain}.tianditu.com/DataServer?T=cta_c&x={col}&y={row}&l={level}";
  24. private static final String URL_VECTOR_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=vec_w&x={col}&y={row}&l={level}";
  25. private static final String URL_VECTOR_ANNOTATION_CHINESE_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=cva_w&x={col}&y={row}&l={level}";
  26. private static final String URL_VECTOR_ANNOTATION_ENGLISH_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=eva_w&x={col}&y={row}&l={level}";
  27. private static final String URL_IMAGE_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=img_w&x={col}&y={row}&l={level}";
  28. private static final String URL_IMAGE_ANNOTATION_CHINESE_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=cia_w&x={col}&y={row}&l={level}";
  29. private static final String URL_IMAGE_ANNOTATION_ENGLISH_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=eia_w&x={col}&y={row}&l={level}";
  30. private static final String URL_TERRAIN_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=ter_w&x={col}&y={row}&l={level}";
  31. private static final String URL_TERRAIN_ANNOTATION_CHINESE_MERCATOR = "http://{subDomain}.tianditu.com/DataServer?T=cta_w&x={col}&y={row}&l={level}";
  32. private static final int DPI = 96;
  33. private static final int minZoomLevel = 1;
  34. private static final int maxZoomLevel = 18;
  35. private static final int tileWidth = 256;
  36. private static final int tileHeight = 256;
  37. private static final String LAYER_NAME_VECTOR = "vec";
  38. private static final String LAYER_NAME_VECTOR_ANNOTATION_CHINESE = "cva";
  39. private static final String LAYER_NAME_VECTOR_ANNOTATION_ENGLISH = "eva";
  40. private static final String LAYER_NAME_IMAGE = "img";
  41. private static final String LAYER_NAME_IMAGE_ANNOTATION_CHINESE = "cia";
  42. private static final String LAYER_NAME_IMAGE_ANNOTATION_ENGLISH = "eia";
  43. private static final String LAYER_NAME_TERRAIN = "ter";
  44. private static final String LAYER_NAME_TERRAIN_ANNOTATION_CHINESE = "cta";
  45. private static final SpatialReference SRID_2000 = SpatialReference.create(4490);
  46. private static final SpatialReference SRID_MERCATOR = SpatialReference.create(102100);
  47. private static final double X_MIN_2000 = -180;
  48. private static final double Y_MIN_2000 = -90;
  49. private static final double X_MAX_2000 = 180;
  50. private static final double Y_MAX_2000 = 90;
  51. private static final double X_MIN_MERCATOR = -20037508.3427892;
  52. private static final double Y_MIN_MERCATOR = -20037508.3427892;
  53. private static final double X_MAX_MERCATOR = 20037508.3427892;
  54. private static final double Y_MAX_MERCATOR = 20037508.3427892;
  55. private static final Point ORIGIN_2000 = new Point(-180, 90, SRID_2000);
  56. private static final Point ORIGIN_MERCATOR = new Point(-20037508.3427892, 20037508.3427892, SRID_MERCATOR);
  57. private static final Envelope ENVELOPE_2000 = new Envelope(X_MIN_2000, Y_MIN_2000, X_MAX_2000, Y_MAX_2000, SRID_2000);
  58. private static final Envelope ENVELOPE_MERCATOR = new Envelope(X_MIN_MERCATOR, Y_MIN_MERCATOR, X_MAX_MERCATOR, Y_MAX_MERCATOR, SRID_MERCATOR);
  59. private static final double[] SCALES = {
  60. 2.958293554545656E8, 1.479146777272828E8,
  61. 7.39573388636414E7, 3.69786694318207E7,
  62. 1.848933471591035E7, 9244667.357955175,
  63. 4622333.678977588, 2311166.839488794,
  64. 1155583.419744397, 577791.7098721985,
  65. 288895.85493609926, 144447.92746804963,
  66. 72223.96373402482, 36111.98186701241,
  67. 18055.990933506204, 9027.995466753102,
  68. 4513.997733376551, 2256.998866688275,
  69. 1128.4994333441375
  70. };
  71. private static final double[] RESOLUTIONS_MERCATOR = {
  72. 78271.51696402048, 39135.75848201024,
  73. 19567.87924100512, 9783.93962050256,
  74. 4891.96981025128, 2445.98490512564,
  75. 1222.99245256282, 611.49622628141,
  76. 305.748113140705, 152.8740565703525,
  77. 76.43702828517625, 38.21851414258813,
  78. 19.109257071294063, 9.554628535647032,
  79. 4.777314267823516, 2.388657133911758,
  80. 1.194328566955879, 0.5971642834779395,
  81. 0.298582141738970};
  82. private static final double[] RESOLUTIONS_2000 = {
  83. 0.7031249999891485, 0.35156249999999994,
  84. 0.17578124999999997, 0.08789062500000014,
  85. 0.04394531250000007, 0.021972656250000007,
  86. 0.01098632812500002, 0.00549316406250001,
  87. 0.0027465820312500017, 0.0013732910156250009,
  88. 0.000686645507812499, 0.0003433227539062495,
  89. 0.00017166137695312503, 0.00008583068847656251,
  90. 0.000042915344238281406, 0.000021457672119140645,
  91. 0.000010728836059570307, 0.000005364418029785169};
  92. public static WebTiledLayer CreateTianDiTuTiledLayer(String layerType) {
  93. return CreateTianDiTuTiledLayer(getTianDiTuLayerType(layerType));
  94. }
  95. public static WebTiledLayer CreateTianDiTuTiledLayer(LayerType layerType) {
  96. WebTiledLayer webTiledLayer = null;
  97. String mainUrl = "";
  98. String mainName = "";
  99. TileInfo mainTileInfo = null;
  100. Envelope mainEnvelope = null;
  101. boolean mainIs2000 = false;
  102. try {
  103. switch (layerType) {
  104. case TIANDITU_VECTOR_2000:
  105. mainUrl = URL_VECTOR_2000;
  106. mainName = LAYER_NAME_VECTOR;
  107. mainIs2000 = true;
  108. break;
  109. case TIANDITU_VECTOR_MERCATOR:
  110. mainUrl = URL_VECTOR_MERCATOR;
  111. mainName = LAYER_NAME_VECTOR;
  112. break;
  113. case TIANDITU_IMAGE_2000:
  114. mainUrl = URL_IMAGE_2000;
  115. mainName = LAYER_NAME_IMAGE;
  116. mainIs2000 = true;
  117. break;
  118. case TIANDITU_IMAGE_ANNOTATION_CHINESE_2000:
  119. mainUrl = URL_IMAGE_ANNOTATION_CHINESE_2000;
  120. mainName = LAYER_NAME_IMAGE_ANNOTATION_CHINESE;
  121. mainIs2000 = true;
  122. break;
  123. case TIANDITU_IMAGE_ANNOTATION_ENGLISH_2000:
  124. mainUrl = URL_IMAGE_ANNOTATION_ENGLISH_2000;
  125. mainName = LAYER_NAME_IMAGE_ANNOTATION_ENGLISH;
  126. mainIs2000 = true;
  127. break;
  128. case TIANDITU_IMAGE_ANNOTATION_CHINESE_MERCATOR:
  129. mainUrl = URL_IMAGE_ANNOTATION_CHINESE_MERCATOR;
  130. mainName = LAYER_NAME_IMAGE_ANNOTATION_CHINESE;
  131. break;
  132. case TIANDITU_IMAGE_ANNOTATION_ENGLISH_MERCATOR:
  133. mainUrl = URL_IMAGE_ANNOTATION_ENGLISH_MERCATOR;
  134. mainName = LAYER_NAME_IMAGE_ANNOTATION_ENGLISH;
  135. break;
  136. case TIANDITU_IMAGE_MERCATOR:
  137. mainUrl = URL_IMAGE_MERCATOR;
  138. mainName = LAYER_NAME_IMAGE;
  139. break;
  140. case TIANDITU_VECTOR_ANNOTATION_CHINESE_2000:
  141. mainUrl = URL_VECTOR_ANNOTATION_CHINESE_2000;
  142. mainName = LAYER_NAME_VECTOR_ANNOTATION_CHINESE;
  143. mainIs2000 = true;
  144. break;
  145. case TIANDITU_VECTOR_ANNOTATION_ENGLISH_2000:
  146. mainUrl = URL_VECTOR_ANNOTATION_ENGLISH_2000;
  147. mainName = LAYER_NAME_VECTOR_ANNOTATION_ENGLISH;
  148. mainIs2000 = true;
  149. break;
  150. case TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR:
  151. mainUrl = URL_VECTOR_ANNOTATION_CHINESE_MERCATOR;
  152. mainName = LAYER_NAME_VECTOR_ANNOTATION_CHINESE;
  153. break;
  154. case TIANDITU_VECTOR_ANNOTATION_ENGLISH_MERCATOR:
  155. mainUrl = URL_VECTOR_ANNOTATION_ENGLISH_MERCATOR;
  156. mainName = LAYER_NAME_VECTOR_ANNOTATION_ENGLISH;
  157. break;
  158. case TIANDITU_TERRAIN_2000:
  159. mainUrl = URL_TERRAIN_2000;
  160. mainName = LAYER_NAME_TERRAIN;
  161. mainIs2000 = true;
  162. break;
  163. case TIANDITU_TERRAIN_ANNOTATION_CHINESE_2000:
  164. mainUrl = URL_TERRAIN_ANNOTATION_CHINESE_2000;
  165. mainName = LAYER_NAME_TERRAIN_ANNOTATION_CHINESE;
  166. mainIs2000 = true;
  167. break;
  168. case TIANDITU_TERRAIN_MERCATOR:
  169. mainUrl = URL_TERRAIN_MERCATOR;
  170. mainName = LAYER_NAME_TERRAIN;
  171. break;
  172. case TIANDITU_TERRAIN_ANNOTATION_CHINESE_MERCATOR:
  173. mainUrl = URL_TERRAIN_ANNOTATION_CHINESE_MERCATOR;
  174. mainName = LAYER_NAME_TERRAIN_ANNOTATION_CHINESE;
  175. break;
  176. }
  177. List<LevelOfDetail> mainLevelOfDetail = new ArrayList<LevelOfDetail>();
  178. Point mainOrigin = null;
  179. if (mainIs2000 == true) {
  180. for (int i = minZoomLevel; i <= maxZoomLevel; i++) {
  181. LevelOfDetail item = new LevelOfDetail(i, RESOLUTIONS_2000[i - 1], SCALES[i - 1]);
  182. mainLevelOfDetail.add(item);
  183. }
  184. mainEnvelope = ENVELOPE_2000;
  185. mainOrigin = ORIGIN_2000;
  186. } else {
  187. for (int i = minZoomLevel; i <= maxZoomLevel; i++) {
  188. LevelOfDetail item = new LevelOfDetail(i, RESOLUTIONS_MERCATOR[i - 1], SCALES[i - 1]);
  189. mainLevelOfDetail.add(item);
  190. }
  191. mainEnvelope = ENVELOPE_MERCATOR;
  192. mainOrigin = ORIGIN_MERCATOR;
  193. }
  194. mainTileInfo = new TileInfo(
  195. DPI,
  196. TileInfo.ImageFormat.PNG24,
  197. mainLevelOfDetail,
  198. mainOrigin,
  199. mainOrigin.getSpatialReference(),
  200. tileHeight,
  201. tileWidth
  202. );
  203. webTiledLayer = new WebTiledLayer(
  204. mainUrl,
  205. SubDomain,
  206. mainTileInfo,
  207. mainEnvelope);
  208. webTiledLayer.setName(mainName);
  209. webTiledLayer.loadAsync();
  210. } catch (Exception e) {
  211. e.getCause();
  212. }
  213. return webTiledLayer;
  214. }
  215. protected static LayerType getTianDiTuLayerType(String layerType) {
  216. LayerType result = LayerType.TIANDITU_VECTOR_2000;
  217. switch (layerType) {
  218. /**
  219. * 天地图矢量墨卡托投影地图服务
  220. */
  221. case "TIANDITU_VECTOR_MERCATOR":
  222. result = LayerType.TIANDITU_VECTOR_MERCATOR;
  223. break;
  224. /**
  225. * 天地图矢量墨卡托中文标注
  226. */
  227. case "TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR":
  228. result = LayerType.TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR;
  229. break;
  230. /**
  231. * 天地图矢量墨卡托英文标注
  232. */
  233. case "TIANDITU_VECTOR_ANNOTATION_ENGLISH_MERCATOR":
  234. result = LayerType.TIANDITU_VECTOR_ANNOTATION_ENGLISH_MERCATOR;
  235. break;
  236. /**
  237. * 天地图影像墨卡托投影地图服务
  238. */
  239. case "TIANDITU_IMAGE_MERCATOR":
  240. result = LayerType.TIANDITU_IMAGE_MERCATOR;
  241. break;
  242. /**
  243. * 天地图影像墨卡托投影中文标注
  244. */
  245. case "TIANDITU_IMAGE_ANNOTATION_CHINESE_MERCATOR":
  246. result = LayerType.TIANDITU_IMAGE_ANNOTATION_CHINESE_MERCATOR;
  247. break;
  248. /**
  249. * 天地图影像墨卡托投影英文标注
  250. */
  251. case "TIANDITU_IMAGE_ANNOTATION_ENGLISH_MERCATOR":
  252. result = LayerType.TIANDITU_IMAGE_ANNOTATION_ENGLISH_MERCATOR;
  253. break;
  254. /**
  255. * 天地图地形墨卡托投影地图服务
  256. */
  257. case "TIANDITU_TERRAIN_MERCATOR":
  258. result = LayerType.TIANDITU_TERRAIN_MERCATOR;
  259. break;
  260. /**
  261. * 天地图地形墨卡托投影中文标注
  262. */
  263. case "TIANDITU_TERRAIN_ANNOTATION_CHINESE_MERCATOR":
  264. result = LayerType.TIANDITU_TERRAIN_ANNOTATION_CHINESE_MERCATOR;
  265. break;
  266. /**
  267. * 天地图矢量国家2000坐标系地图服务
  268. */
  269. case "TIANDITU_VECTOR_2000":
  270. result = LayerType.TIANDITU_VECTOR_2000;
  271. break;
  272. /**
  273. * 天地图矢量国家2000坐标系中文标注
  274. */
  275. case "TIANDITU_VECTOR_ANNOTATION_CHINESE_2000":
  276. result = LayerType.TIANDITU_VECTOR_ANNOTATION_CHINESE_2000;
  277. break;
  278. /**
  279. * 天地图矢量国家2000坐标系英文标注
  280. */
  281. case "TIANDITU_VECTOR_ANNOTATION_ENGLISH_2000":
  282. result = LayerType.TIANDITU_VECTOR_ANNOTATION_ENGLISH_2000;
  283. break;
  284. /**
  285. * 天地图影像国家2000坐标系地图服务
  286. */
  287. case "TIANDITU_IMAGE_2000":
  288. result = LayerType.TIANDITU_IMAGE_2000;
  289. break;
  290. /**
  291. * 天地图影像国家2000坐标系中文标注
  292. */
  293. case "TIANDITU_IMAGE_ANNOTATION_CHINESE_2000":
  294. result = LayerType.TIANDITU_IMAGE_ANNOTATION_CHINESE_2000;
  295. break;
  296. /**
  297. * 天地图影像国家2000坐标系英文标注
  298. */
  299. case "TIANDITU_IMAGE_ANNOTATION_ENGLISH_2000":
  300. result = LayerType.TIANDITU_IMAGE_ANNOTATION_ENGLISH_2000;
  301. break;
  302. /**
  303. * 天地图地形国家2000坐标系地图服务
  304. */
  305. case "TIANDITU_TERRAIN_2000":
  306. result = LayerType.TIANDITU_TERRAIN_2000;
  307. break;
  308. /**
  309. * 天地图地形国家2000坐标系中文标注
  310. */
  311. case "TIANDITU_TERRAIN_ANNOTATION_CHINESE_2000":
  312. result = LayerType.TIANDITU_TERRAIN_ANNOTATION_CHINESE_2000;
  313. break;
  314. }
  315. return result;
  316. }
  317. public enum LayerType {
  318. /**
  319. * 天地图矢量墨卡托投影地图服务
  320. */
  321. TIANDITU_VECTOR_MERCATOR,
  322. /**
  323. * 天地图矢量墨卡托中文标注
  324. */
  325. TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR,
  326. /**
  327. * 天地图矢量墨卡托英文标注
  328. */
  329. TIANDITU_VECTOR_ANNOTATION_ENGLISH_MERCATOR,
  330. /**
  331. * 天地图影像墨卡托投影地图服务
  332. */
  333. TIANDITU_IMAGE_MERCATOR,
  334. /**
  335. * 天地图影像墨卡托投影中文标注
  336. */
  337. TIANDITU_IMAGE_ANNOTATION_CHINESE_MERCATOR,
  338. /**
  339. * 天地图影像墨卡托投影英文标注
  340. */
  341. TIANDITU_IMAGE_ANNOTATION_ENGLISH_MERCATOR,
  342. /**
  343. * 天地图地形墨卡托投影地图服务
  344. */
  345. TIANDITU_TERRAIN_MERCATOR,
  346. /**
  347. * 天地图地形墨卡托投影中文标注
  348. */
  349. TIANDITU_TERRAIN_ANNOTATION_CHINESE_MERCATOR,
  350. /**
  351. * 天地图矢量国家2000坐标系地图服务
  352. */
  353. TIANDITU_VECTOR_2000,
  354. /**
  355. * 天地图矢量国家2000坐标系中文标注
  356. */
  357. TIANDITU_VECTOR_ANNOTATION_CHINESE_2000,
  358. /**
  359. * 天地图矢量国家2000坐标系英文标注
  360. */
  361. TIANDITU_VECTOR_ANNOTATION_ENGLISH_2000,
  362. /**
  363. * 天地图影像国家2000坐标系地图服务
  364. */
  365. TIANDITU_IMAGE_2000,
  366. /**
  367. * 天地图影像国家2000坐标系中文标注
  368. */
  369. TIANDITU_IMAGE_ANNOTATION_CHINESE_2000,
  370. /**
  371. * 天地图影像国家2000坐标系英文标注
  372. */
  373. TIANDITU_IMAGE_ANNOTATION_ENGLISH_2000,
  374. /**
  375. * 天地图地形国家2000坐标系地图服务
  376. */
  377. TIANDITU_TERRAIN_2000,
  378. /**
  379. * 天地图地形国家2000坐标系中文标注
  380. */
  381. TIANDITU_TERRAIN_ANNOTATION_CHINESE_2000
  382. }
  383. }

调用方式:

  1. package com.arcgis.activity;
  2. import android.os.Bundle;
  3. import android.os.Environment;
  4. import android.support.v7.app.AppCompatActivity;
  5. import com.arcgis.R;
  6. import com.arcgis.until.TianDiTuMethodsClass;
  7. import com.esri.arcgisruntime.geometry.Point;
  8. import com.esri.arcgisruntime.geometry.SpatialReference;
  9. import com.esri.arcgisruntime.layers.ArcGISTiledLayer;
  10. import com.esri.arcgisruntime.layers.WebTiledLayer;
  11. import com.esri.arcgisruntime.loadable.LoadStatus;
  12. import com.esri.arcgisruntime.mapping.ArcGISMap;
  13. import com.esri.arcgisruntime.mapping.Basemap;
  14. import com.esri.arcgisruntime.mapping.Viewpoint;
  15. import com.esri.arcgisruntime.mapping.view.MapView;
  16. import java.util.Arrays;
  17. import java.util.List;
  18. public class ArcgisTiandituMapActivity extends AppCompatActivity {
  19. private MapView mMapView;
  20. //影像地图 _W是墨卡托投影 _c是国家2000的坐标系
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_map);
  25. mMapView = (MapView) findViewById(R.id.map_view);
  26. // webtile layer
  27. final WebTiledLayer webTiledLayer =
  28. TianDiTuMethodsClass.CreateTianDiTuTiledLayer(TianDiTuMethodsClass.LayerType.TIANDITU_VECTOR_MERCATOR);
  29. webTiledLayer.loadAsync();
  30. ArcGISMap map = new ArcGISMap(new Basemap(webTiledLayer));
  31. Point center = new Point(113.365548756,23.12648183, SpatialReference.create(4490));// CGCS2000
  32. mMapView.setViewpointCenterAsync(center,12);
  33. mMapView.setMap(map);
  34. }
  35. protected void onResume() {
  36. super.onResume();
  37. mMapView.resume();
  38. }
  39. @Override
  40. protected void onPause() {
  41. super.onPause();
  42. mMapView.pause();
  43. }
  44. }

3、谷歌地图的代码

自已根据天地图封装方式,封装了谷歌地图使用类

注意:测试谷歌时候,只能看到屏幕上这些地图,其他滑动出去,就没有,不知道为什么。有知道的大神可以评论一下。

  1. package com.arcgis.until;
  2. import com.esri.arcgisruntime.arcgisservices.LevelOfDetail;
  3. import com.esri.arcgisruntime.arcgisservices.TileInfo;
  4. import com.esri.arcgisruntime.data.TileKey;
  5. import com.esri.arcgisruntime.geometry.Envelope;
  6. import com.esri.arcgisruntime.geometry.Point;
  7. import com.esri.arcgisruntime.geometry.SpatialReference;
  8. import com.esri.arcgisruntime.layers.WebTiledLayer;
  9. import java.util.ArrayList;
  10. import java.util.Arrays;
  11. import java.util.List;
  12. import java.util.Random;
  13. public class GoogleMapLayer{
  14. private static final int DPI = 96;
  15. private static final int minZoomLevel = 1;
  16. private static final int maxZoomLevel = 19;
  17. private static final int tileWidth = 256;
  18. private static final int tileHeight = 256;
  19. // 枚举
  20. public enum MapType {
  21. VECTOR, //矢量标注地图
  22. IMAGE, //影像地图
  23. ROAD //道路标注图层
  24. }
  25. private MapType mMapType;
  26. private static final List<String> SubDomain = Arrays.asList(new String[]{"mt0", "mt1", "mt2", "mt3", "mt4"});
  27. //102100是esri内部使用id 与epsg:3857 是对应的
  28. private static final SpatialReference SRID_MERCATOR = SpatialReference.create(102113);
  29. private static final Point ORIGIN_MERCATOR = new Point(-20037508.3427892, 20037508.3427892, SRID_MERCATOR);
  30. private static final Envelope ENVELOPE_MERCATOR = new Envelope(-22041257.773878,
  31. -32673939.6727517, 22041257.773878, 20851350.0432886, SRID_MERCATOR);
  32. private static double[] SCALES = new double[] { 591657527.591555,
  33. 295828763.79577702, 147914381.89788899, 73957190.948944002,
  34. 36978595.474472001, 18489297.737236001, 9244648.8686180003,
  35. 4622324.4343090001, 2311162.217155, 1155581.108577, 577790.554289,
  36. 288895.277144, 144447.638572, 72223.819286, 36111.909643,
  37. 18055.954822, 9027.9774109999998, 4513.9887049999998, 2256.994353,
  38. 1128.4971760000001 };
  39. private static double[] iRes = new double[] { 156543.03392800014,
  40. 78271.516963999937, 39135.758482000092, 19567.879240999919,
  41. 9783.9396204999593, 4891.9698102499797, 2445.9849051249898,
  42. 1222.9924525624949, 611.49622628138, 305.748113140558,
  43. 152.874056570411, 76.4370282850732, 38.2185141425366,
  44. 19.1092570712683, 9.55462853563415, 4.7773142679493699,
  45. 2.3886571339746849, 1.1943285668550503, 0.59716428355981721,
  46. 0.29858214164761665 };
  47. private String getMapUrl(TileKey tileKey) {
  48. String iResult = null;
  49. Random iRandom = null;
  50. int level = tileKey.getLevel();
  51. int col = tileKey.getColumn();
  52. int row = tileKey.getRow();
  53. iResult = "http://mt";
  54. iRandom = new Random();
  55. iResult = iResult + iRandom.nextInt(4);
  56. switch (this.mMapType) {
  57. case VECTOR:
  58. iResult = iResult + ".google.cn/vt/lyrs=m@212000000&hl=zh-CN&gl=CN&src=app&x=" + col + "&y=" + row + "&z=" + level + "&s==Galil";
  59. break;
  60. case IMAGE:
  61. iResult = iResult + ".google.cn/vt/lyrs=s@126&hl=zh-CN&gl=CN&src=app&x=" + col + "&y=" + row + "&z=" + level + "&s==Galil";
  62. break;
  63. case ROAD:
  64. 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";
  65. break;
  66. default:
  67. return null;
  68. }
  69. return iResult;
  70. }
  71. public static WebTiledLayer CreateGoogleLayer(MapType layerType) {
  72. WebTiledLayer webTiledLayer = null;
  73. String mainUrl = "";
  74. String mainName = "Google";
  75. TileInfo mainTileInfo = null;
  76. Envelope mainEnvelope = null;
  77. try {
  78. switch (layerType) {
  79. case VECTOR:
  80. mainUrl = "http://{subDomain}.google.cn/vt/lyrs=m@225000000&hl=zh-CN&gl=CN&src=app&s=G&x={col}&y={row}&z={level}";
  81. break;
  82. case ROAD:
  83. mainUrl = "";
  84. break;
  85. case IMAGE:
  86. mainUrl = "";
  87. break;
  88. }
  89. List<LevelOfDetail> mainLevelOfDetail = new ArrayList<LevelOfDetail>();
  90. Point mainOrigin = null;
  91. for (int i = minZoomLevel; i <= maxZoomLevel; i++) {
  92. LevelOfDetail item = new LevelOfDetail(i, iRes[i - 1], SCALES[i - 1]);
  93. mainLevelOfDetail.add(item);
  94. }
  95. mainEnvelope = ENVELOPE_MERCATOR;
  96. mainOrigin = ORIGIN_MERCATOR;
  97. mainTileInfo = new TileInfo(
  98. DPI,
  99. TileInfo.ImageFormat.PNG24,
  100. mainLevelOfDetail,
  101. mainOrigin,
  102. mainOrigin.getSpatialReference(),
  103. tileHeight,
  104. tileWidth
  105. );
  106. webTiledLayer = new WebTiledLayer(
  107. mainUrl,
  108. SubDomain,
  109. mainTileInfo,
  110. mainEnvelope);
  111. webTiledLayer.setName(mainName);
  112. webTiledLayer.loadAsync();
  113. } catch (Exception e) {
  114. e.getCause();
  115. }
  116. return webTiledLayer;
  117. }
  118. }

调用方式

  1. package com.arcgis.activity;
  2. import android.os.Bundle;
  3. import android.support.v7.app.AppCompatActivity;
  4. import com.arcgis.R;
  5. import com.arcgis.until.GoogleMapLayer;
  6. import com.arcgis.until.TianDiTuMethodsClass;
  7. import com.esri.arcgisruntime.geometry.Point;
  8. import com.esri.arcgisruntime.geometry.SpatialReference;
  9. import com.esri.arcgisruntime.layers.WebTiledLayer;
  10. import com.esri.arcgisruntime.mapping.ArcGISMap;
  11. import com.esri.arcgisruntime.mapping.Basemap;
  12. import com.esri.arcgisruntime.mapping.view.MapView;
  13. public class ArcgisGoogleMapActivity extends AppCompatActivity {
  14. private MapView mMapView;
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_map);
  19. mMapView = (MapView) findViewById(R.id.map_view);
  20. // webtile layer
  21. final WebTiledLayer webTiledLayer =
  22. GoogleMapLayer.CreateGoogleLayer(GoogleMapLayer.MapType.VECTOR);
  23. webTiledLayer.loadAsync();
  24. ArcGISMap map = new ArcGISMap(new Basemap(webTiledLayer));
  25. mMapView.setMap(map);
  26. }
  27. protected void onResume() {
  28. super.onResume();
  29. mMapView.resume();
  30. }
  31. @Override
  32. protected void onPause() {
  33. super.onPause();
  34. mMapView.pause();
  35. }
  36. }

新手一定要注意权限

  1. <uses-permission android:name="android.permission.INTERNET" />
  2. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  3. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约