The Graphicslayer---------element in the AO

Source: Internet
Author: User
Tags imap

Come the container of the Graphicslayer---------element in the from AO

The graphical elements (Graphic element) are stored in the Graphicslayer, and the main interfaces and classes involved in this paper are as follows:

Igraphicscontainer, Igraphicslayer, Icompositegraphicslayer, Graphicssublayer class, Compositegraphicslayer class.

Graphicssublayer class mainly implements the interface Igraphicscontainer, Igraphicslayer, ILayer.

The Compositegraphicslayer class implements interfaces Igraphicscontainer, Igraphicslayer, ILayer, Icompositegraphicslayer

The basicgraphicslayer of the IMAP interface is shown in the Help document of AE to get a igraphicslayer, But actually Imap.basicgraphicslayer is not only igraphicslayer so simple, it actually can be regarded as a Compositegraphicslayer object in essence, why say so? Because ArcGIS is developed based on COM standards, all of its properties or methods are returned by an interface, not a specific class. In order to ascertain what the nature of Imap.basicgraphicslayer is, I did a test, and the test process is as follows:

IMap Map1 = Axmapcontrol1.map;

Igraphicslayer gl = map1.basicgraphicslayer;

We can now be sure that GL is the Igraphicslayer interface type, and I looked at the help of AE, the Compositegraphicslayer class implements 22 common interfaces including the Igraphicslayer interface and 2 event interfaces. If Basicgraphicslayer is actually an instance of Compositegraphicslayer, then GL should implement all the interfaces in the Compositegraphicslayer, so I'm in the debug state, In the Immediate window of this 20 more than one interface to test the following, such as testing the first interface Ibarrierproperties statement as follows, in the Immediate window input GL is ibarrierproperties, enter, the result is true, That is to say, GL implements the Ibarrierproperties interface, I test 22 ordinary interfaces in turn, and find that the return is true, However, when testing two event interfaces Iselectionevents and Igraphicscontainerevents, it returns false, but because the event interface is special, we can ignore it. In conclusion, Basicgraphicslayer implements all common interfaces in the Compositegraphicslayer, Now we have good reason to think that Basicgraphicslayer is essentially an instance object of a Compositegraphicslayer class.

Now let's take a look at the Graphicssublayer class, which can be seen by the name sub as a sublayer, which is referred to as a "sublayer", which is relative to the composite graphics layer Compositegraphicslayer. We can think of Compositegraphicslayer as a graphicssublayer container, and we can even simply assume that Compositegraphicslayer is a huaben, And Graphicssublayer is a piece of paper in Huaben. When we draw the painting can be directly irregular painting on the Huaben, can also have a regular different types of painting on different paper.

A Map object manages a Compositegraphicslayer object, which means that a map corresponds to a huaben, but the number of paper in Huaben is indeed uncertain.

Since we can draw on the Huaben (Compositegraphicslayer), but also in the huaben of a paper (Graphicssublayer) on the painting, then we draw when should be painted on the Huaben, When should I draw the paper on the Huaben?

In general, if we want to add the graphic element (graphic element) to the map, we can draw directly on the huaben for simplicity, that is, using Compositegraphicslayer, The following function demonstrates how to draw a graphic Element on a map via Compositegraphicslayer:

private void Addgraphicelementbycompositegraphicslayer (igraphicelement element)

{

IMap Map1 = Axmapcontrol1.map;

Igraphicslayer gl = map1.basicgraphicslayer;

Igraphicscontainer GC = GL as Igraphicscontainer;

Gc. AddElement (element, 0);

AxMapControl1.ActiveView.PartialRefresh (esriviewdrawphase.esriviewgraphics, NULL, NULL);

}

Some people may ask, the above code simply does not appear "Compositegraphicslayer", how can say that the graphic element is painted on the compositegraphicslayer?

Igraphicscontainer GS = GL as Igraphicscontainer;

This code is the key, this code makes GL from the Compositegraphicslayer class Igraphicslayer interface Qi to the Compositegraphicslayer class Igraphicscontainer interface, The equivalent of the Compositegraphicslayer object is built into a special page of paper that can be used as a canvas.

So when should we draw the graphic on the Graphicssublayer? We should use Graphicssublayer when we want to manage different types of graphical elements regularly, or we can use Graphicssublayer to relate to a specific featurelaeyr in the TOC. The following function demonstrates how to add a graphic Element to a graphicssublayer:

private void Addgraphicelementbygraphicssublayer (string sublayername, igraphicelement Element)

{

Igraphicslayer sublayer = Findorcreategraphicssublayer (sublayername);//return is actually a Graphicssublayer instance object

Igraphicscontainer GC = Sublayer as igraphicscontainer;//here is the reason Qi is possible, is because Graphicssublayer simultaneously implements Igraphicslayer and Igraphicscontainer.

Gc. AddElement (element, 0);

AxMapControl1.ActiveView.PartialRefresh (esriviewdrawphase.esriviewgraphics, NULL, NULL);

}

Private Igraphicslayer Findorcreategraphicssublayer (string sublayername)

{

IMap Map1 = Axmapcontrol1.map;

Igraphicslayer gl = map1.basicgraphicslayer;

Icompositegraphicslayer CGL = gl as icompositegraphicslayer;

Igraphicslayer sublayer;

Sublayer = CGL. Findlayer (sublayername);//Find There is no Graphicssublayer named Sublayername in Compositegraphicslayer

if (sublayer = = null)

{

Sublayer = CGL. AddLayer (sublayername, null);//icompositegraphicslayer.addlayer method actually returns a Graphicssublayer instance object

}

return sublayer;

}


Here I would like to emphasize this code sublayer= CGL. AddLayer (sublayername, NULL);

Let's look at the function prototypes.

As I mentioned at the beginning of this article, the method of COM-based AO returns an interface rather than an object of a certain type. So what kind of addlaeyr is it going to return? Actually returned is the Graphicssublayer type, which I haveTest, the test method is the same as the previous testing process, no longer repeat. Note that the Addlayer method has a Ifeaturelaeyr type parameter that enables a feature class layer in the TOC so that the Featurelayer is associated with the Graphicssublayer If the passed-in Featurelayer parameter is NULL, the Graphicssublayer is not associated with any feature layer. The following content is in the help document of AE Imap.activegraphicslayer in the Remarks section, because the English content is relatively not difficult, do not translate, we look at: Threedifferent objects contain and persist Graphic elements:a map, Thepagelayout,and anfdographicslayer.  Both the map and the pagelayout store (persist) their graphics in the document; Fdographicslayers store their graphics in adatabase (an fdographics layer is a feature annotation layer). In arcmap,graphic elements is kept in graphics layers (Graphiclayers objects) .  tomanage all of the graphic layers, The MAP has the compositegraphicslayerobject.  the Compositegraphicslayer object have a collection ofgraphicslayers an D It implements Theicompositegraphicslayer interface which providesmethods for creating, finding, and deleting Graphicslay ers.  New graphicslayers is sometimes called ' Groups ' or ' Annotation Target Layers '. NotOnlydoes the Compositegraphicslayer object has a collection of graphics layers,but It is itself a graphics layer-like t He Fdographicslayer object, itinherits from the Graphicslayer object.  This means, Thecompositegraphicslayer obje CT have its own graphicsContainerWhere graphic elements can bestored.  The graphics layer it provides is called the ' Basic Graphicslayer '. This Basic graphics layer is the default graphics layer and Itcannot are deleted. The Compositegraphicslayer objects implements Theicompositelayer interface, among others, which have the Propertiescount an  Dlayer. The Count does not include the basic graphics Layer and the Layerproperty cannot is used to access the basic graphics Laye R. isbecause the Basic Graphics Layer is essentially the compositegraphicslayerobject whereas the Groups is Separat E Graphicslayer objects. Thebasicgraphicslayer returns a reference to the Basic Graphicslayer (the Compositegraphicslayer object) a nd from this can query interfacefor the other interfaces implemented by the object including those on Thegraphicslayer Object.
The Map ' s Activegraphicslayer property provides a reference to the Graphicslayer currently active (sometimes this is Calle  d the ' Active Annotation targetlayer). By default, the basic graphics layer is the active layer but anygroup or fdographicslayer is also settable as the active LA Yer.
The Compositegraphicslayer and none of its graphicslayers (Groups) is reallayers like Afeaturelayer, Agrouplayer, or ANFD  Ographicslayer. None Ofthese layers can is accessed with the Map ' Slayers property and is not Includedin thelayercount.

The Graphicslayer---------element in the AO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.