Learning arcengine (8) eagleeye together

Source: Internet
Author: User

The official AE library does not provide this control and needs to be implemented by itself, but it is also relatively simple. The principle or implementation idea is to add an axmapcontrol control, set his view to the full map range of the map, and draw the range of the current map with a red box on the map control.

Create a new user control named mapeagle. Drag an axmapcontrol Control named axmapeagle to display the map.

Next, add a custom attribute to be associated with the main Map window so that the axmapeagle can obtain the range of the current map.

   1:  private AxMapControl pMap;
   2:          
   3:          /// <summary>
4: // associated map controls
   5:          /// </summary>
   6:          public AxMapControl MapControl
   7:          {
   8:              set
   9:              {
  10:                  if (value != pMap) pMap = value;
  11:                  //this.axMapEagle.Extent = pMap.FullExtent;
  12:                  pMap.OnMapReplaced += new IMapControlEvents2_Ax_OnMapReplacedEventHandler(pMap_OnMapReplaced);
  13:                  pMap.OnExtentUpdated += new IMapControlEvents2_Ax_OnExtentUpdatedEventHandler(pMap_OnExtentUpdated);
  14:              }
  15:   
  16:          }

The onmapreplaced event of the primary map control refreshes the view range of the axmapeagle when the primary Map window is reloaded. The implementation code is as follows:

   1:    void pMap_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
   2:          {
   3:   
   4:              for (int i = 0; i <= pMap.LayerCount; i++)
   5:              {
   6:                  axMapEagle.AddLayer(pMap.get_Layer(i));
   7:              }
   8:              this.axMapEagle.Extent = pMap.FullExtent;
   9:   
  10:              IGraphicsContainer pGraphicsContainer = this.axMapEagle.Map as IGraphicsContainer;
  11:              IActiveView pActiveView = pGraphicsContainer as IActiveView;
  12:              pGraphicsContainer.DeleteAllElements();
  13:   
  14:              IElement pEle = Envelope2Element(pMap.Extent);
  15:              pGraphicsContainer.AddElement(pEle, 0);
  16:              pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
  17:          }

In this event, first load the layers of the main map to the axmapeagle control, then try to set it as a full graph, and then delete all the elements in the window, next we will draw the view range of the main map on the axmapeagle view and use the element creation method. The envelope2element method converts the view range ienvelope into an element, set the map of axmapeagle as a graphical container, add the created element, and refresh the view.

The implementation process of the envelope2element method is as follows:

   1:   private IElement Envelope2Element(IEnvelope env)
   2:          {
   3:              IRectangleElement pRectangleEle = new RectangleElementClass();
   4:              IElement pEle = pRectangleEle as IElement;
   5:              pEle.Geometry = env;
   6:   
   7:              IRgbColor pColor = new RgbColorClass();
   8:              pColor.RGB = 255;
   9:              pColor.Transparency = 255;
  10:   
  11:              ILineSymbol pOutline = new SimpleLineSymbolClass();
  12:              pOutline.Width = 1.5;
  13:              pOutline.Color = pColor;
  14:   
  15:              pColor = new RgbColorClass();
  16:              pColor.RGB = 255;
  17:              pColor.Transparency = 0;
  18:   
  19:              IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
  20:              pFillSymbol.Color = pColor;
  21:              pFillSymbol.Outline = pOutline;
  22:   
  23:              IFillShapeElement pFillshapeEle = pEle as IFillShapeElement;
  24:              pFillshapeEle.Symbol = pFillSymbol;
  25:              return  pFillshapeEle as IElement;
  26:          }

By now, we have achieved half of the results. When the main map view is enlarged or reduced, the range labels on the eagleeye map are not changed. That is, the onextentupdated method of the main map. Its official description is as follows: "fires after the extent (visible bounds) of the mapcontrol is changed. "When the visual range of the map control changes, it is exactly what we want. Its implementation is the same as that during loading. You can also draw the changed view range on the map without re-loading the map. The specific code is as follows:

   1:          void pMap_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
   2:          {
// Delete the added element
   3:              IGraphicsContainer pGraphicsContainer = this.axMapEagle.Map as IGraphicsContainer;
   4:              IActiveView pActiveView = pGraphicsContainer as IActiveView;
   5:              pGraphicsContainer.DeleteAllElements();
   6:   
   7:              IElement pEle = Envelope2Element(e.newEnvelope as IEnvelope );
   8:              pGraphicsContainer.AddElement(pEle, 0);
   9:              pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
  10:          }
The work has been completed by 90%. Haha, The axmapeagle control will adapt to the changes in the master map view. What is missing is that the master map view must adapt to the changes in the axmapeagle view.
That is, when you click on the eagleeye view, the main map must be able to move to the clicked position, which is truly convenient. Map controls are required to implement such functions.
The Code is as follows:
   1:  private void axMapEagle_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
   2:          {
   3:              IRubberBand pBand = new RubberEnvelopeClass();
   4:              IGeometry pGeometry = pBand.TrackNew(axMapEagle.ActiveView.ScreenDisplay, null);
   5:            
   6:              if (pGeometry.IsEmpty)
   7:              {
   8:                  IPoint pPt = new PointClass();
   9:                  pPt.PutCoords(e.mapX, e.mapY);
10: // change the view range of the Master Control
  11:                  pMap.CenterAt(pPt);
  12:              }
  13:              else
  14:              {
  15:                  pMap.Extent = pGeometry.Envelope;
  16:                  pMap.ActiveView.Refresh();
  17:              }
  18:          }

The official explanation of the irubberband interface is "provides access to Members that control simple rubberbanding. "rubberbanding" is translated as 'rubber band generation line'. Literal Translation provides the permission to control the simple rubber band generation line'. (The English level is too concave. You can only look up the dictionary to translate it !) It can control the box range when you press the left mouse button to pull the box. The tracknew method of this interface is to convert the drop-down box into a geographical element, and then set the MAP range based on this element.

The success is that the main map and eagleeye interact in two ways!

Http://www.cnblogs.com/liuyh208/archive/2009/09/28/1576011.html

Http://blog.csdn.net/zhongjiekangping/article/details/6618412

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.