ArcGIS Pro 3.8 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.
      var project = Project.Current;
      await QueuedTask.Run(() =>
      {
    
      //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.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 Feature Outlines from a Feature Layer
    {
      var greatLakes = map.GetLayersAsFlattenedList()
            .OfType<FeatureLayer>().First(l => l.Name == "Great Lakes");
      var michigan = map.GetBookmarks().First(b => b.Name == "Michigan");
    
      //get all features - multiple feature geometries are always returned as a
      //single multi-part
      var all_features_outline = greatLakes.GetFeatureOutline(mapView, FeatureOutlineType.All);
    
      //or get just the outline of selected features
      var qry = new QueryFilter()
      {
        SubFields = "*",
        WhereClause = "NAME in ('Huron','Michigan','Erie')"
      };
      greatLakes.Select(qry);
      var sel_features_outline = greatLakes.GetFeatureOutline(
          mapView, FeatureOutlineType.Selected);
      greatLakes.ClearSelection();
    
      //or just the visible features
      mapView?.ZoomTo(michigan);
      var visible_features_outline = greatLakes.GetFeatureOutline(
          mapView, FeatureOutlineType.Visible);
    }
    Zoom To Bookmark by name
    {
      await QueuedTask.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
    {
      await QueuedTask.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));
      });
    }
    Pan To Bookmark
    {
      await QueuedTask.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
        }
    
        //Pan the view to the bookmark.
        mapView.PanTo(bookmark);
      });
    }
    Pan To Bookmark Async
    {
      //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
      }
    
      //Pan the view to the bookmark.
      mapView.PanToAsync(bookmark, TimeSpan.FromSeconds(2));
    }
    Get Map Bookmarks
    {
      await QueuedTask.Run(() =>
      {
        //Return the collection of bookmarks for the map.
        var result = mapView.Map.GetBookmarks();
        // Use the bookmarks (if any)
      });
    }
    Move Bookmark to the Top
    {
      await QueuedTask.Run(() =>
      {
        var map = mapView.Map;
        //Find the first bookmark with the name
        var bookmark = map.GetBookmarks().FirstOrDefault(b => b.Name == bookmarkName);
        if (bookmark == null)
        {
          //Bookmark not found
        }
    
        //Move the bookmark to the top of the list
        map.MoveBookmark(bookmark, 0);
      });
    }
    Rename Bookmark
    {
      oldBookmark = mapView.Map.GetBookmarks().FirstOrDefault(b => b.Name == bookmarkName);
      oldBookmark.Rename(newBookmarkName);
    }
    Remove bookmark with a given name
    {
      await QueuedTask.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