How to add a web map

Web maps are comprised of a basemap layer and one or more operational layers, as well as tasks, feature collections and pop-ups. Using the ArcGIS Runtime SDK for Java, it's easy to add a web map to your application, as shown in the following steps:

  1. Browse and locate the web map you want to add to your application. Alternatively, discover the web map by using Portal for ArcGIS API.. There is a portal sample in the ArcGIS Runtime for Java sample application which shows how a portal could be queried to find web maps.
  2. You can add a web map using its full URL or just the ID. On, open the details of the map to get its ID. The map's ID is the value at the end of the uniform resource locator (URL) of the details page. For example, for the Topographic map with the details URL, the ID is d5e02a0c1f2b4ec399823fdd3c2fdebd.
  3. Create a Java application to contain a JMap that will display the web map.
    JMap jMap = new JMap();
  4. Load the web map.
    The WebMap class in the package supports reading web map JSON. Create an instance of the class using either the full URL of the web map or just the item ID then add the web map to a JMap instance by calling initializeMap.
    WebMap webMap = null; 
    try { 
       webMap = new WebMap("4778fee6371d4e83a22786029f30c7e1");
       // if using Bing Maps basemaps in your web map, set your Bing key here
       // webMap.setBingKey("yourBingKeyHere");
    } catch (Exception e) {
       // handle the exception

    If you are using a Bing Maps basemap in your web map, you need to set a Bing key on the WebMap instance using the setBingKey() method, as above. See the Bing Maps overview for how to obtain a Bing key.

  5. Alternatively, construct the WebMap by using a PortalItem retrieved by using the Portal for ArcGIS API..
    PortalItem portalItem = null;
    //retrieve PortalItem from portal
    WebMap webMap = new WebMap(portalItem); 
  6. Compile and run your application.
  7. You can allow your users to interact with the map once the map is ready. Set up an event listener on the JMap instance to listen for the 'mapReady' event. See the following code example:
    jMap.addMapEventListener(new MapEventListenerAdapter() { 
       public void mapReady(final MapEvent arg0) { 
         SwingUtilities.invokeLater(new Runnable() { 
            public void run() { 
            //... allow the user to interact with the map

    The mapReady event fires when the map's spatial reference is set, so some layers in the map may not be initialized yet (such as feature layers) when this event fires.