ArcGis for android 加载tpk离线文件



ArcGis for android 加载tpk离线文件

1.安装 arcgis android sdk (必须安装过 android sdk及 adt 环境喲)

创建一个本地缓存arcgis android项目

如下代码

 

  1. package com.esri.arcgis.android.samples.localtiledlayer;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.os.Environment;
  5. import com.esri.android.map.MapView;
  6. import com.esri.android.map.ags.ArcGISLocalTiledLayer;
  7. /**
  8. * This sample illustrates the use of ArcGISLocatlTiledLayer where the data is stored locally on the device, therefore
  9. * this layer can function even when the device does not have any network connectivity. The data for this layer must be
  10. * in an ArcGIS Compact Cache format (Tile Packages or .tpk’s are not currently supported).
  11. * The typical compact cache structure is as  follows:
  12. *   <CacheName><br>
  13. *       Layers<br>
  14. *           _allLayers<br>
  15. *               conf.cdi,conf.xml<br>
  16. * The path used in the constructor of the ArcGISLocalTiledLayer must point to the Layers folder e.g. <br>
  17. *  ArcGISLocalTiledLayer local = new ArcGISLocalTiledLayer(“file:///mnt/sdcard/<CacheName>/Layers”);
  18. *
  19. *  A sample data set has been created and is available via ArcGIS Online:
  20. *  http://www.arcgis.com/home/item.html?id=d2d263a280164a039ef0a02e26ee0501
  21. *  1) In order to use the data, download it from the url above
  22. *  2) Copy the data to your sdcard
  23. *  3) Set the path to the data by replacing <CacheName> with file:///mnt/sdcard/Parcels/v101/Parcel Map
  24. *     on line60 below.
  25. *
  26. *  You can also use your own data if it is in an ArcGIS Compact Cache format, for more information on
  27. *  this data format see this link:
  28. *  http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2010/05/27/Introducing-the-compact-cache-storage-format.aspx
  29. *
  30. **/
  31. public class LocalTiledLayer extends Activity {
  32.     MapView map = null;
  33.     ArcGISLocalTiledLayer local;
  34.     /** Called when the activity is first created. */
  35.     @Override
  36.     public void onCreate(Bundle savedInstanceState) {
  37.         super.onCreate(savedInstanceState);
  38.         setContentView(R.layout.main);
  39.         map = (MapView) findViewById(R.id.map);
  40.         //the data is stored on the SDCARD
  41.         //the data is created as a tiled cache
  42. //      local = new ArcGISLocalTiledLayer(“file:///mnt/sdcard/ArcGIS/Basemap/Layers”);
  43. //      local = new ArcGISLocalTiledLayer(Environment.getExternalStorageDirectory()
  44. //                      + ”/YX1.tpk”); // 不行
  45.         local = new ArcGISLocalTiledLayer(“file:///storage/sdcard0/YX1.tpk”); // ok
  46.         map.addLayer(local);
  47.     }
  48. }

项目截图:


 

 

运行截图