In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What is the design and implementation of the right-click menu in ArcEngine development? in order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
In developing custom GIS applications with ArcGIS Engine, there are generally two ways to create right-click menus.
One is to make use of the right-click menu controls that come with the development tools, such as the ContextMenuStrip control in Visual Studio
The second is to use the IToolbarMenu interface encapsulated by ArcGIS Engine. Comparatively speaking, the former is easier to implement, but the latter makes the program more object-oriented and easier to expand. In large-scale systems, this method is a better choice.
This paper describes in detail how to use IToolbarMenu interface to achieve right-click menu function.
The main interface of the designer is shown in the following figure:
First define the following pointer in the FrmMain class:
Private ITOCControl2 pTocControl; private IMapControl3 pMapControl; private IToolbarMenu pToolMenuMap; private IToolbarMenu pToolMenuLayer
Initialize these pointers in the load event of the FrmMain form:
/ / get references to MapControl and PageLayoutControl pTocControl = (ITOCControl2) axTOCControl1.Object; pMapControl = (IMapControl3) axMapControl1.Object; / / create menu pToolMenuMap = new ToolbarMenuClass (); pToolMenuLayer = new ToolbarMenuClass ()
In this way, a new menu is established, but there are no actual menu items, and specific commands or tools must be added to the menu as menu items in order to achieve the corresponding functions.
Before you can add a menu item, you have to implement the corresponding command or tool. Next, customize a command to zoom to the layer and add a class ZoomToLayer.cs to the project, which inherits from ESRI.ArcGIS.ADF.BaseClasses.BaseCommand. BaseCommand is an abstract class that provides an effective way for developers to create custom command items. Override the OnCreate and OnClick methods of the base class to zoom the layer to a complete display in the map control. The complete code is as follows.
Using System; using System.Collections.Generic; using System.Text; using ESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; namespace ArcEngine3_3 {class ZoomToLayer: BaseCommand {/ / definition pointer private IMapControl3 pMapControl; public ZoomToLayer () {base.m_caption = "Zoom in to this layer" } / / override the virtual method OnClick () public override void OnClick () {ILayer pLayer = (ILayer) pMapControl.CustomProperty; pMapControl.Extent = pLayer.AreaOfInterest;} / / override the abstract method OnCreate (object hook) public override void OnCreate (object hook) of the BaseCommand base class {pMapControl = (IMapControl3) hook;}
In addition to custom implementation commands or tools, ArcGIS Engine has many common commands and tools that can be called directly, such as ControlsAddDataCommandClass, ControlsClearSelectionCommandClass, etc., or you can directly call AE built-in menus, such as ControlsFeatureSelectionMenu.
Once you have established a custom command or tool, you can add the corresponding menu item to the menu. Add a menu item to the load event of the FrmMain form.
PToolMenuLayer.AddItem (new ZoomToLayer (),-1,0, true, esriCommandStyles.esriCommandStyleTextOnly)
Set the hook of the menu
PToolMenuLayer.SetHook (pMapControl)
Now that you have a menu, you need to right-click in the TocControl, so get the mouse click information in its OnMouseDown/OnMouseUp event, and then pop up the corresponding menu.
/ / get mouse click information axTOCControl1.HitTest (e.x, e.y, ref pTocItem, ref pBasicMap, ref pLayer, ref oLegendGroup, ref oIndex); if (e.button = = 2) {if (pTocItem = = esriTOCControlItem.esriTOCControlItemMap) {pTocControl.SelectItem (pBasicMap, null);} else {pTocControl.SelectItem (pLayer, null);} / / set CustomProperty to layer (for custom Layer commands) pMapControl.CustomProperty = pLayer / / right-click menu if (pTocItem = = esriTOCControlItem.esriTOCControlItemMap) {pToolMenuMap.PopupMenu (e.x, e.y, pTocControl.hWnd);} else {pToolMenuLayer.PopupMenu (e.x, e.y, pTocControl.hWnd);}}
In the same way, you can add their own right-click menus for maps, layers, symbols, MapControl, etc., in TocControl. The final results are as follows.
The answer to the question about the design and implementation of the right-click menu in ArcEngine development is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.