ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Map Class / GetBookmarks Method
Example

In This Topic
    GetBookmarks Method (Map)
    In This Topic
    Returns the map's collection of bookmarks. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Return Value

    The collection of bookmarks for the map.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Create Map Frame and Set Camera
    {
      //Create a map frame and set its camera by zooming to the extent of an existing bookmark.
      //Construct on the worker thread
    
      //Build 2D envelope geometry
      Coordinate2D mf_ll = new Coordinate2D(6.0, 8.5);
      Coordinate2D mf_ur = new Coordinate2D(8.0, 10.5);
      Envelope mf_env = EnvelopeBuilderEx.CreateEnvelope(mf_ll, mf_ur);
    
      //Reference map, create MF and add to layout
      MapProjectItem mapPrjItem = Project.Current.GetItems<MapProjectItem>()
                           .FirstOrDefault(item => item.Name.Equals("Map"));
      Map mfMap = mapPrjItem.GetMap();
      Bookmark bookmark = mfMap.GetBookmarks().FirstOrDefault(
                            b => b.Name == "Great Lakes");
    
      MapFrame mfElm = ElementFactory.Instance.CreateMapFrameElement(
                           layout, mf_env, mfMap, "New Map Frame");
    
      //Zoom to bookmark
      mfElm.SetCamera(bookmark);
    }
    Get Map Bookmarks
    {
      // Note: Needs QueuedTask to run
      {
        //Return the collection of bookmarks for the map.
        var result = mapView.Map.GetBookmarks();
        // Use the bookmarks (if any)
      }
    }
    Zoom To Bookmark by name
    {
      // Note: Needs QueuedTask to run
      {
        //Get the first bookmark with the given name.
        var bookmark = mapView.Map.GetBookmarks().FirstOrDefault(b => b.Name == bookmarkName);
        if (bookmark == null)
        {
          // Manage the error - bookmark not found
        }
    
        //Zoom the view to the bookmark.
        mapView.ZoomTo(bookmark);
      }
    }
    Zoom Async To Bookmark by name
    {
      // Note: Needs QueuedTask to run
      //Get the first bookmark with the given name.
      var bookmark = mapView.Map.GetBookmarks().FirstOrDefault(b => b.Name == bookmarkName);
      if (bookmark == null)
      {
        // Manage the error - bookmark not found
      }
    
      //Zoom the view to the bookmark.
      mapView.ZoomToAsync(bookmark, TimeSpan.FromSeconds(2));
    }
    Get the collection of bookmarks for the project
    {
      //Get the collection of bookmarks for the project.
      var result = Project.Current.GetBookmarks();
      // Use the bookmarks (if any)
    }
    Remove bookmark with a given name
    {
      // Note: Needs QueuedTask to run
      {
        //Find the first bookmark with the name
        var bookmark = mapView.Map.GetBookmarks().FirstOrDefault(b => b.Name == bookmarkName);
        if (bookmark == null)
        {
          //Bookmark not found
        }
    
        //Remove the bookmark
        mapView.Map.RemoveBookmark(bookmark);
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also