Local Tile Layer

This sample illustrates the most basic use of ArcGISLocalTiledLayer where your tile package (*.tpk) data is stored locally on the device and can function when device does not have network connectivity. The sample depends on the following basemap tile package.


  • MapView
  • ArcGISLocalTiledLayer

Sample Design

The Local Tile Layer sample creates a path to a *.tpk file on disk. The path is constructed as a String to be used in the ArcGISLocalTiledLayer constructor and then add the layer to the MapView. You can change the data to your own data by editing the string.xml resource file and change the following string resource variables:

<string name="local_tpk">NAME-OF-YOUR-TPK.tpk</string>
<string name="offline_dir">PATH-TO-YOUR-TPK</string>

The offline_dir variable should be the path after the primary external storage directory returned from Environment.getExternalStorageDirectory();.

Sample Code

/* 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 java.io.File;

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

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

 * This sample illustrates the use of ArcGISLocatlTiledLayer where the data is
 * a tile package (*.tpk) stored locally on the device, therefore this layer 
 * can function even when the device does not have any network connectivity. 
 * A sample Tile Package data set has been created and is available via ArcGIS Online:
 * http://www.arcgis.com/home/item.html?id=9a7e015149854c35b5eb94494f4aeb89 
 * In order to use the data, download it from the url above 
 * copy the data to your device's internal sdcard location at
 * /[external-storage-dir]/ArcGIS/samples/LocalTileLayer/SanFrancisco.tpk
 * You can also use your own data if it is in an ArcGIS Compact Cache format or
 * a tile package format.  You can edit the location and name of the date in the 
 * string resource file, strings.xml.  

public class LocalTiledLayer extends Activity {

  private static File demoDataFile;
  private static String offlineDataSDCardDirName;
  private static String filename;

  MapView mMapView;
  ArcGISLocalTiledLayer localTiledLayer;

  /** Called when the activity is first created. */
  public void onCreate(Bundle savedInstanceState) {

    // create the path to local tpk
    demoDataFile = Environment.getExternalStorageDirectory();
    offlineDataSDCardDirName = this.getResources().getString(R.string.offline_dir);
    filename = this.getResources().getString(R.string.local_tpk);

    // create the url
    String basemap = demoDataFile + File.separator + offlineDataSDCardDirName + File.separator + filename;

    // create the mapview
    mMapView = (MapView) findViewById(R.id.map);
    // create the local tpk
    localTiledLayer = new ArcGISLocalTiledLayer(basemap);
    // add the layer
    // enable panning over date line
    // set Esri logo

Feedback on this topic?