How to display web map bookmarks

When you author a web map on ArcGIS Online, you can bookmark and name map extents, and when you save your web map the bookmarks are saved as part of the web map. For more information on creating bookmarks in a web map, please refer to Bookmarking places. By following the steps below you can display these web map bookmarks in your Java application.

  1. First you need a web map which has saved bookmarks; these will be stored in the web map's JSON as 'bookmarks'. Refer to About authoring web maps and Bookmarking places if you have not authored ArcGIS web maps before and wish to do so for this exercise. You may also use an existing web map which has saved bookmarks.
  2. Using the URL or the item ID of your web map containing bookmarks, follow the instructions on How to add a web map to your Java application in order to display the web map.
  3. Now that you are displaying your web map, you need to display the bookmarks from the web map. To do so, the simplest way is to use the ArcGIS Runtime SDK for Java's toolkit component called JExtentBookmark. Make sure you have added the toolkit jar to your project and then add an import statement to your application in order to use this component:
    import com.esri.client.toolkit.bookmarks.JExtentBookmark;
  4. Create an instance of JExtentBookmark using your JMap instance, and add it to the content pane of your application. The code below assumes that you have created a JMap instance called 'map' and that you have declared a JExtentBookmark field in your application class called 'extentBookmarks'.
    extentBookmarks = new JExtentBookmark(map);
    // position the component as desired within your Swing layout of choice
  5. You now need to populate the bookmarks component with the bookmarks from the web map. Once the map (JMap) displaying your web map is fully initialized, you can obtain the bookmarks from the WebMap instance using getBookmarks(), and populate your extent bookmarks component, as below:
    jMap.addMapEventListener(new MapEventListenerAdapter() {
        public void mapReady(MapEvent event) {
  6. Compile and run your application. Refer to the WebMap Bookmarks sample in the Sample Application under the 'Datasources > WebMap' content heading for a working example.