How to add a local feature layer

Steps

Follow these steps to add a local feature 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 com.esri.map package.
    import com.esri.map.JMap;
    
  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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    theFrame.getContentPane().setLayout(new BorderLayout(0, 0));
    
    map = new JMap();
    theFrame.getContentPane().add(map);
    
  4. Import the local feature layer class found in the com.esri.client.local package.
    import com.esri.client.local.ArcGISLocalFeatureLayer;
    
  5. Create an ArcGISLocalFeatureLayer. In the constructor provide the path to an ArcGIS map package (*.mpk) and the name of the feature layer contained in the package. You can find a map package in the SDK installation folder. Edit this path to provide the correct location or provide a path to your own map package.
    ArcGISLocalFeatureLayer featureLayer = new ArcGISLocalFeatureLayer( 
     "<ArcGIS Runtime SDK installation folder>\sdk\samples\data\mpks\USCitiesStates.mpk", "Cities");
    map.getLayers().add(featureLayer);
    
  6. Compile and run your application.
  7. Navigate around the map by zooming, panning and using the mouse wheel.
2/7/2013