How to add a local tiled layer


Follow these steps to add a local tiled layer to your map.

  1. Add the ArcGIS Runtime dependent jar files to the build path of your Java project. You will locate these files in the <ArcGIS Runtime SDK installation directory>/sdk/jars folder laid down at installation.
  2. Import the Swing map control called JMap found in the package.
  3. Add the map control (JMap) to the ContentPane of the JFrame. Set the frame's window listener to ensure that the map is disposed of correctly when the window is closed.
    private JFrame theFrame;
    private JMap map;
    theFrame = new JFrame();
    theFrame.setBounds(100, 100, 450, 300);
    theFrame.getContentPane().setLayout(new BorderLayout(0, 0));
    map = new JMap();
  4. Import the local tiled layer class found in the com.esri.client.local package.
    import com.esri.client.local.ArcGISLocalTiledLayer;
  5. Create an ArcGISLocalTiledLayer and provide the path to an ArcGIS tile package (*.tpk). In the following code, the path shown is to the location of a tile package included with the SDK installation, where you need to replace '<ArcGIS Runtime SDK installation directory>' with your actual installation directory. For any other tile package, just set this path to match the location of your own tile package.
    ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(
     "<ArcGIS Runtime SDK installation directory>\sdk\samples\data\tpks\Topographic.tpk"); 

    If you have an exploded cache then provide the path to the folder that contains the cache configuration file (conf.xml).

  6. Compile and run your application.
  7. Navigate around the map by zooming, panning and using the mouse wheel.