How to create a map control


The following steps will allow you to embed a map control into your Java application and display a layer that you can navigate with.

  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));
    // dispose map just before application window is closed.
    theFrame.addWindowListener(new WindowAdapter() {
     public void windowClosing(WindowEvent windowEvent) {
    map = new JMap();
  4. Import the tiled map service class found in the package.
  5. Create the ArcGISTiledMapServiceLayer and provide the URL to the map service endpoint. Add the layer to the map's list of layers.
    ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(
  6. When the layer has been added and the map is ready, set the initial map extent. Create a map listener and override the mapReady event. When the mapReady event is fired, call the setExtent method on the map.
    map.addMapEventListener(new MapEventListenerAdapter() { 
     public void mapReady(MapEvent arg0) { 
      SwingUtilities.invokeLater(new Runnable() { 
        public void run() { 
         map.setExtent(new Envelope(-14384172, 4578761, -11982215, 6180881)); 
  7. Compile and run your application.
  8. Navigate around the map by zooming, panning and using the mouse wheel.

Alternatively, follow the steps here which describe how to use the Eclipse New Project wizard called "ArcGIS Runtime Java Map Application" to add a new project to Eclipse. All of the above steps will be completed for you.