Pop-up menu for GIS Secondary Development

Source: Internet
Author: User

You have talked about the custom tool several times before. Check the function before you start to bring up the menu.

We can see that the custom tools mentioned in the previous articles are displayed in these articles, and the effects of the pop-up menu to be implemented are also displayed. Right-click the main map view and a menu will pop up. The functions in this menu are the same as those in the toolbar, in the TOC navigation tool, the menu content displayed when you right-click a map is different from that displayed when you right-click a layer. When you select a map, you can add a layer and a full graph. When you select a layer, you can delete and refresh the selected layer.

This section mainly describes the implementation code of the pop-up menu. Other codes will be added later.

First, let's look at the implementation code of the pop-up menu in the main view, just like the method added in the previous few lectures, but this time the container is toolbarmenu. Let's look at the implementation of the Code:

Code

// Right-click the axmapmain menu
Private itoolbarmenu mapmenu = new toolbarmenuclass ();
/// <Summary>
/// Right-click the axmapmain menu
/// </Summary>
Private void addmapmainpopumenu ()
{
// Add progid
String progid = "csharpdotnetcommands. mappan ";
Mapmenu. additem (progid,-1,-1, false, esricommandstyles. esricommandstyleiconandtext );
Progid = "csharpdotnetcommands. mapzoomin ";
Mapmenu. additem (progid,-1,-1, true, esricommandstyles. esricommandstyleiconandtext );
Progid = "csharpdotnetcommands. mapzoomout ";
Mapmenu. additem (progid,-1,-1, true, esricommandstyles. esricommandstyleiconandtext );
Progid = "csharpdotnetcommands. mapfullextent ";
Mapmenu. additem (progid,-1,-1, true, esricommandstyles. esricommandstyleiconandtext );
Progid = "csharpdotnetcommands. mapgoback ";
Mapmenu. additem (progid,-1,-1, true, esricommandstyles. esricommandstyleiconandtext );
Progid = "csharpdotnetcommands. mapgoforward ";
Mapmenu. additem (progid,-1,-1, true, esricommandstyles. esricommandstyleiconandtext );
Mapmenu. sethook (axmapmain); // right-click the axmapmain menu
} // <Summary>
/// Right-click the axmapmain menu
/// </Summary>
Private void axmapmain_onmouseup (Object sender, imapcontrolevents2_onmouseupevent E)
{
If (E. Button = 2)
{
Mapmenu. popupmenu (E. X, E. Y, axmapmain. hwnd );
}
}

In this way, the mapmenu menu will pop up when you right-click the main view.

The following shows the implementation code of the pop-up menu in TOC:

Code

// Right-click the axtoccontrol menu
Private itoolbarmenu axtocmenu1 = new toolbarmenuclass ();
Private itoolbarmenu axtocmenu2 = new toolbarmenuclass ();

/// <Summary>
/// Define the right-click menu for map in axtoccontrol
/// </Summary>
Private void addtocpopumenu1 ()
{
String progid = "csharpdotnetcommands. mapfullextent ";
Axtocmenu1.additem (progid,-1,-1, false, esricommandstyles. esricommandstyleiconandtext );
Progid = "csharpdotnetcommands. mapaddlayer ";
Axtocmenu1.additem (progid,-1,-1, true, esricommandstyles. esricommandstyleiconandtext );
}

/// <Summary>
/// Define the right-click menu for layer in axtoccontrol
/// </Summary>
Private void addtocpopumenu2 ()
{
String progid = "csharpdotnetcommands. mapflash ";
Axtocmenu2.additem (progid,-1,-1, false, esricommandstyles. esricommandstyleiconandtext );
Progid = "csharpdotnetcommands. mapdellayer ";
Axtocmenu2.additem (progid,-1,-1, true, esricommandstyles. esricommandstyleiconandtext );
}
 
/// <Summary>
/// Display the pop-up menu
/// </Summary>
Private void axtoccontrolpoliconmousedown (Object sender, itoccontrolevents_onmousedownevent E)
{
Esritoccontrolitem item = esritoccontrolitem. esritoccontrolitemmap;
Ibasicmap pbasicmap = NULL;
Ilayer player = NULL;
Object unk = NULL;
Object Data = NULL;
Axtoccontrol1.hittest (E. X, E. Y, ref item, ref pbasicmap, ref player, ref unk, ref data );
If (item = esritoccontrolitem. esritoccontrolitemmap) // when map is selected
{
Axtoccontrol1.selectitem (pbasicmap, null );
If (E. Button = 2) // adddata
{
Axtocmenu1.popupmenu (E. X, E. Y, axtoccontrol1.hwnd );
}
}
Else if (item = esritoccontrolitem. esritoccontrolitemlayer)
{
Axtoccontrol1.selectitem (player, null );
If (E. Button = 2) // Delete
{
Axtocmenu2.popupmenu (E. X, E. Y, axtoccontrol1.hwnd );
}
}
}

You can add the above Code to achieve the first effect. As for adding a layer, the code for deleting the layer will be pasted in the next article.

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.