Arcgis Android API开发之离线地图

最近一直在倒腾Arcgis Android API等相关的东西,想把自己的做的图放到地图上去,也就是离线地图,穷人一般是没有钱的,一个月好几十的流量是开不起的,所以就左捉摸,右思考,看着API里面有离线地图,始终没有弄明白是怎么回事,直到今天下午,想起来了就有试了试,结果成功了,那个激动啊,好半天那……

Arcgis Android API离线地图主要是通过ArcGISLocalTiledLayer实现的,下面是ArcGISLocalTiledLayer的相关内容:

java.lang.Object
  com.esri.android.map.Layer
      com.esri.android.map.TiledLayer
          com.esri.android.map.ags.ArcGISLocalTiledLayer

The ArcGISLocatlTiledLayer class is a type of tiled layer where the data is stored locally on the device, therefore this layer can function even when the device does not have any network connectivity. The data for this layer must be in an ArcGIS Compact Cache format. The typical compact cache structure is as follows:  <CacheName>      Layers           _allLayers, conf.cdi, conf.xml The path used in the constructor of the ArcGISLocalTiledLayer must point to the Layers folder e.g.  ArcGISLocalTiledLayer local = new ArcGISLocalTiledLayer("file:///mnt/sdcard/<CacheName>/Layers");

上面的内容是从帮助文档里面粘贴过来的,英文水平不高,就不翻译了,各位的水平肯定比我高。下面就把做的例子展示一下吧:

在做之前,需要把数据拷贝到手机的SD卡里面,我的在手机里是这样组织的:

所用的数据呢,是用Arcgis Server切片的数据。数据弄好之后,因为你要读取Sd卡上的内容,所以,你得在AndroidManifest.xml文件中添加用户权限:

<uses-permission android:name="android.permission.INTERNET" /><!-- 允许访问Internet -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><!-- 允许写入Sd卡 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

用户权限配置好之后,布局文件中加入mapview空间,布局文件main.xml的代码如下:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"
     android:orientation="vertical"
>

<com.esri.android.map.MapView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/map" android:layout_width="fill_parent" 
     android:layout_height="fill_parent">
 
</com.esri.android.map.MapView>
</LinearLayout>

Activity的代码如下:

/* Copyright 2012 ESRI
 *
 * All rights reserved under the copyright laws of the United States
 * and applicable international laws, treaties, and conventions.
 *
 * You may freely redistribute and use this sample code, with or
 * without modification, provided you include the original copyright
 * notice and use restrictions.
 *
 * See the �Sample code usage restrictions� document for further information.
 *
 */

package com.esri.arcgis.android.samples.localtiledlayer;

import android.app.Activity;
import android.os.Bundle;

import com.esri.android.map.MapView;
import com.esri.android.map.ags.ArcGISLocalTiledLayer;

/**
* This sample illustrates the use of ArcGISLocatlTiledLayer where the data is stored locally on the device, therefore 
* this layer can function even when the device does not have any network connectivity. The data for this layer must be 
* in an ArcGIS Compact Cache format or packaged as a Tile package (*.tpk).
* 
* The typical compact cache structure is as  follows:
*	<CacheName><br>
*		Layers<br>
*			_allLayers<br>
*				conf.cdi,conf.xml<br>
* The path used in the constructor of the ArcGISLocalTiledLayer must point to the Layers folder e.g. <br>
*  ArcGISLocalTiledLayer local = new ArcGISLocalTiledLayer("file:///mnt/sdcard/<CacheName>/Layers");
*  
*  A sample data set has been created and is available via ArcGIS Online:
*  http://www.arcgis.com/home/item.html?id=d2d263a280164a039ef0a02e26ee0501
*  1) In order to use the data, download it from the url above
*  2) Copy the data to your sdcard
*  3) Set the path to the data by replacing <Path-to-local-data> with file:///mnt/sdcard/Parcels/v101/Parcel Map
*     on line68 below.
*  
*  A sample Tile Map Package has been created and is available via ArcGIS Online:
*  http://www.arcgis.com/home/item.html?id=4497b7bb42e543b691027840d1b9092a
*  1) In order to use the data, download it from the url above
*  2) Copy the data to your device
*  3) Set the path to the *.tpk file by replacing <Path-to-local-data> on line 68 below
*  
*  You can also use your own data if it is in an ArcGIS Compact Cache format, for more information on 
*  this data format see this link: 
*  http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2010/05/27/Introducing-the-compact-cache-storage-format.aspx
*  
**/

public class LocalTiledLayer extends Activity {

	MapView map = null;
	ArcGISLocalTiledLayer local;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		map = (MapView) findViewById(R.id.map);
		
		//the data is stored on the SDCARD
		//the data is created as a tiled cache
		//local = new ArcGISLocalTiledLayer("file:///mnt/sdcard/arcgis/Parcels/v101/Parcel Map");
		local = new ArcGISLocalTiledLayer("file:///mnt/sdcard/arcgis/neimeng/Layers");
		map.addLayer(local);
		
		
	}
}

完成后效果如下图:

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Samego技术资源分享

解决Docker中ubuntu镜像安装MySQL

24640
来自专栏向治洪

Google VR技术大揭秘

VR 虚拟现实(Virtual Reality)技术是一种可以创建和体验虚拟世界的计算机仿真系统,它利用计算机生成一种模拟环境,是一种多源信息融合的、交互式的三...

29560
来自专栏V站

图片API丨网站如何接入Bing每天一更背景?

Bing,即必应。常常有些站都是千篇一律的底色背景,毫无新意,导致的即是访客一个一个访你友链都不访那些死鬼站长!这就是Bing每天一更背景,也十分的骚,需要的上...

29870
来自专栏developerHaoz 的安卓之旅

手把手教你从零开始做一个好看的 APP

俗话说,万事开头难,在开始敲代码之前,先让我们来做一些必要的准备,这样才能事半功倍嘛!

19330
来自专栏黑白安全

高清无码!比鬼片还刺激!且听“诡娃”远控的这首惊魂曲

近日,360云安全系统发现一款名为“诡娃”的远控木马,正通过钓鱼软件、网页挂马等多渠道扩散。“诡娃”除了能进行操控中招电脑等行为外,还会通过控制指令让中招机器弹...

13220
来自专栏木子昭的博客

Django网页模板的继承include与复用extends

Django使用网页模板的方式分为两种, 一是建立代码块, 在新的页面导入代码块, 关键词为include 二是建立模板,新的页面在模板基础上扩充, 关键词为e...

21510
来自专栏刘望舒

Android四大架构的优缺点,你真的了解吗?

你准备好了吗?本次列车开往 “重构” 之巅,时速 900km/s。风太大听不见,但我就是可以很简单很直的,给你讲述事物本质和解决方案!⚡

13920
来自专栏Android干货

关于相机拍照获取图片onActivityResult返回data 为null的问题

此时发现 代码执行到 if(data==null)就结束了,问题为为什么拍摄相机的回调图片数据data为null

18420
来自专栏编程之路

羊皮书APP(Android版)开发系列(二十五)自动拍照保存照片-适用于Android 5.0 以下版本

功能描述:学校刷卡终端采用android系统,学生在进出学校时需要刷卡,刷卡同时系统自动拍照并保存照片,而拍照保存照片这个过程学生并不知晓,也就是后台自动拍照。

17330
来自专栏嵌入式程序猿

博世小功率变频器拆解

变频器在工业生产中应用非常的广泛,橡胶行业的轮胎产线就有很多,而且轮胎产线环境恶劣,灰尘大,今天帮朋友修理一台力士乐的变频器,因为长期使用加上环境恶劣,变频器里...

54520

扫码关注云+社区

领取腾讯云代金券