In this topic
Creating AOIs and bookmarks
The following code example shows how to create AOIs and bookmarks:
[C#] private void AddSpatialBookMark(IApplication application)
{
IMapDocument mapDoc=application.Document as IMapDocument;
IMap map=mapDoc.ActiveView.FocusMap;
IActiveView activeView=map as IActiveView;
// Create a new bookmark and set its location to the focus map's current extent.
IAOIBookmark areaOfInterest=new AOIBookmarkClass();
areaOfInterest.Location=activeView.Extent;
// Give the bookmark a name.
areaOfInterest.Name="Area of Interest Bookmark";
// Add the bookmark to the map's bookmark collection. This adds the bookmark
// to the Bookmarks menu, which is accessible from the View menu.
IMapBookmarks mapBookmarks=map as IMapBookmarks;
mapBookmarks.AddBookmark(areaOfInterest);
}
[VB.NET] Private Sub AddSpatialBookMark(ByVal application As IApplication)
Dim mapDoc As IMapDocument=TryCast(application.Document, IMapDocument)
Dim map As IMap=mapDoc.ActiveView.FocusMap
Dim activeView As IActiveView=TryCast(map, IActiveView)
' Create a new bookmark and set its location to the focus map's current extent.
Dim areaOfInterest As IAOIBookmark=New AOIBookmarkClass()
areaOfInterest.Location=activeView.Extent
' Give the bookmark a name.
areaOfInterest.Name="Area of Interest Bookmark"
' Add the bookmark to the map's bookmark collection. This adds
' the bookmark to the Bookmarks menu accessible from the View menu.
Dim mapBookmarks As IMapBookmarks=TryCast(map, IMapBookmarks)
mapBookmarks.AddBookmark(areaOfInterest)
End Sub
Finding an existing spatial bookmark
The following code example shows how to find an existing spatial bookmark and zoom to its stored extent:
[C#] private void ZoomToBookmark(IApplication application, IMxDocument mxDocument)
{
IDocument document=application.Document;
IMapDocument mapDoc=document as IMapDocument;
IActiveView activeView=mapDoc.ActiveView;
IMap map=activeView.FocusMap;
// Access the Map object through its IMapBookmarks interface.
IMapBookmarks mapBookmarks=map as IMapBookmarks;
// Get an enumeration of bookmarks.
IEnumSpatialBookmark enumSpatialBookmark=mapBookmarks.Bookmarks;
enumSpatialBookmark.Reset();
ISpatialBookmark spatialBookmark=enumSpatialBookmark.Next();
while (spatialBookmark != null)
{
if (spatialBookmark.Name == "Area of Interest Bookmark")
{
// Zoom to spatialBookmark.
spatialBookmark.ZoomTo(map);
activeView.Refresh();
return ;
}
spatialBookmark=enumSpatialBookmark.Next();
}
}
[VB.NET] Private Sub ZoomToBookmark(ByVal application As IApplication, ByVal mxDocument As IMxDocument)
Dim document As IDocument=application.Document
Dim mapDoc As IMapDocument=TryCast(document, IMapDocument)
Dim activeView As IActiveView=mapDoc.ActiveView
Dim map As IMap=activeView.FocusMap
' Access the Map object through its IMapBookmarks interface.
Dim mapBookmarks As IMapBookmarks=TryCast(map, IMapBookmarks)
' Get an enumeration of bookmarks.
Dim enumSpatialBookmark As IEnumSpatialBookmark=mapBookmarks.Bookmarks
enumSpatialBookmark.Reset()
Dim spatialBookmark As ISpatialBookmark=enumSpatialBookmark.Next()
While (spatialBookmark IsNot Nothing)
If (spatialBookmark.Name Is "Area of Interest Bookmark") Then
' Zoom to spatialBookmark.
spatialBookmark.ZoomTo(map)
activeView.Refresh()
Return
End If
spatialBookmark=enumSpatialBookmark.Next()
End While
End Sub
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing | Deployment licensing |
---|---|
ArcGIS Desktop Basic | ArcGIS Desktop Basic |
ArcGIS Desktop Standard | ArcGIS Desktop Standard |
ArcGIS Desktop Advanced | ArcGIS Desktop Advanced |