How to interact with map elements


Interacting with map elements

Elements are commonly accessed through the IGraphicsContainer interface implemented by the Map and PageLayout objects. Through this interface, you can add, delete, update, and retrieve the individual elements within a Map or PageLayout object. Use the GroupElement object to combine multiple elements into a single unit for manipulation by the user.
IElement is the generic interface implemented by all graphic elements and frames. Most methods that return graphics (various methods and properties of IGraphicsContainer and IGraphicsContainerSelect) return them as generic IElement objects. IElement gives the programmer access to the geometry of the object and employs methods for querying the object and drawing it. It is the programmer’s responsibility to determine what type of object is hosting the IElement interface by performing a cast. In C# or VB.NET, you can enumerate and parse the map elements using the following example:
[Java]
static void countPolygonElements(IPageLayout docPageLayout)throws Exception{
    //The page layout is a graphic container, so it can be enumerated.
    IGraphicsContainer docContainer = (IGraphicsContainer)docPageLayout;
    //Reset the container to start from the beginning.
    docContainer.reset();
    int iCounter = 0;
    Object docElement = docContainer.next();
    //Loop through the container until the end, denoted by a null value.
    while (docElement != null){
        //Test the element to see if it's a certain type. This can be ITextElement, IPolygonElement, etc.
        if (docElement instanceof IPolygonElement){
            //If a match is found, increment the counter.
            iCounter++;
        }
        //Step to the next element in the container.
        docElement = docContainer.next();
    }
    //Display the results of the count.
    System.out.println("The pagelayout contains " + iCounter + " PolygonElement(s)");
}






Additional Requirements
  • The code in this document requires references to the Carto library.

Development licensingDeployment licensing
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine