Arcgis Android API開發之離線地圖

jopen 11年前發布 | 64K 次閱讀 Android Android開發 移動開發

Arcgis Android API離線地圖主要是通過ArcGISLocalTiledLayer實現的,下面是ArcGISLocalTiledLayer的相關內容:</span>

java.lang.Object  
 extended by com.esri.android.map.Layer      
  extended by com.esri.android.map.TiledLayer          
   extended by 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 Android API開發之離線地圖

所用的數據呢,是用Arcgis Server切片的數據。數據弄好之后,因為你要讀取Sd卡上的內容,所以,你得在AndroidManifest.xml文件中添加用戶權限:

    <uses-permission android:name="android.permission.INTERNET" /><!-- 允許訪問Internet -->  
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><span style="font-family: Arial, Helvetica, sans-serif;"><!-- 允許寫入Sd卡 --></span>  
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  

用戶權限配置好之后,布局文件中加入mapview空間,布局文件main.xml的代碼如下:
    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns: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>  </pre><br />

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);  


    }  
}  </pre></b><a style="text-indent:0px;" title="派生到我的代碼片" href="/misc/goto?guid=4959549480341737714" target="_blank"></a></div>

</div> </div>
完成后效果如下圖:Arcgis Android API開發之離線地圖

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!