Preface
Element is often used during AE development ). The emergence of this function has significantly increased the interaction between maps and users. On a map, you can use various element elements to display the expected results. For example, elements are frequently used in the highlighted display. You often need to add an element to the map to display the results. When there are more and more elements on the map and they are added through different functions, so many complex elements need to be managed in an orderly manner, let the element have its own ownership. How to manage it?
1. Use igroupelement. add the same class or element with similar functions to igroupelement. it is managed as a group. to delete an igroupelement, you only need to delete it. the advantage of this management is that when you need to operate multiple similar elements, you do not need to operate each element one by one. For example, you only need to delete the group in which a batch of houses are queried and highlighted by element.
This article discusses another management method here-using graphicslayer as the management group to manage Elements
in ArcGIS, graphicslayer is actually a container for managing elements. in ArcMap, All map elements are saved in graphicslayer. to manage all graphics elements, MAP has a compositegraphicslayer object. the compositegraphicslayer inherits from the icompositegraphicslayer interface and manages a series of graphicslayers. icompositegraphicslayer provides some basic operations on graphicslayer, such as creating, searching, and deleting. in addition, there are the count and layer attributes. compositegraphicslayer not only manages a series of graphicslayers, but also a graphicslayer. this means that compositegraphicslayer itself has a container for storing graphics (container ). it provides graphicslayer called "basic graphics layer ". this "basic graphics layer" is the default graphicslayer and cannot be deleted.
In general, the most frequently used element addition/deletion during development is igraphicscontaner. you can use the addelement method of this interface to display the elements that you need to express on the map. igraphicscontaner is used here. the elment added by the addelement method is also stored in a default graphicslayer. This graphicslayer is basegraphicslayer. The basegraphicslayer here is an instance of icompositegraphicslayer. therefore, since basegraphicslayer implements the icompositegraphicslayer interface, you can also manage the elements in the map in a layer-by using the interfaces Qi to icompositegraphicslayer, add the graphicslayer We Need To The basegraphicslayer for our business I. for example, you can create a graphicslayer for the elements that need to be used in a business. This graphicslayer is used to manage the elements used in the business. in this way, the elements used in different services are independent of each other and are not affected. to delete an element in a service, you only need to delete the graphicslayer that stores the elements without affecting the elements in other services.
1. How to add a subgraphicslayer:
Add a subgraphicslayer
/// </Summary>
/// <Param name = "subgraphicslayername"> Unique layer name </Param>
/// <Returns> </returns>
Public Igraphicslayer addsubgraphicslayer (IMAP map, String Subgraphicslayername)
{
Icompositegraphicslayer pcompositeglayer = Map. basicgraphicslayer As Icompositegraphicslayer;
Igraphicslayer pglayer = Null ;
Try
{
// Check whether the object already exists. If the object does not exist, jump to the catch content.
// If not found, graphicslayer with the specified name is not found in the collection.
Pglayer = Pcompositeglayer. findlayer (subgraphicslayername );
}
Catch
{
// If not, add a graphicslayer with the specified name.
Pglayer = Pcompositeglayer. addlayer (subgraphicslayername, Null );
}
ReturnPglayer;
}
Pass the aboveCodeThe result is an igraphicslayer object. developers can use igraphicscontainer G = graphicslayer as igraphicscontainer to obtain the igraphicscontainer object. If you want to add an element, use the igraphicscontainer. addelement () method. this method adds the element to the igraphicslayer object.
2. To clear elements, use the following code:
Remove all elements in graphicslayer
Try
{
Igraphicscontainer g = Graphicslayer As Igraphicscontainer;
// Delete all elements in this graphicslayer
G. deleteallelements ();
// Refresh
Activeview. partialrefresh (esriviewdrawphase. esriviewgraphics, Null , Null );
// removed from icompositegraphicslayer, that is, from IMAP. basegraphicslayer
icompositegraphicslayer pcompositeglayer = m_env.m_caxmapex.map.basicgraphicslayer as icompositegraphicslayer;
pcompositeglayer. deletelayer (graphicslayer as ilayer ). name);
}
Catch
{}
"G. the deleteallelements () "method only deletes all elements in the specified graphicslayer. If we create a graphicslayer for the elements of other services, deleting an element in the current business does not affect the elements of other businesses. This effectively controls the elements.
Summary:There are many ways to manage elements. You can see what you are saying. Here we only discuss one method. I personally think it is better to post it and share it with you,