"The ArcGIS engine+c# Instance development tutorial" fifth talk about Eagle Eye's realization

Source: Internet
Author: User
Tags ipoint

In the original: "ArcGIS engine+c# instance Development tutorial" Fifth, the realization of Eagle eye

Abstract: The so-called Eagle Eye, is a thumbnail map, there is a rectangular box, rectangular box area is currently displayed in the map area, drag the rectangle can change the current map display location, change the size of the rectangle box, you can change the current map display area size, from the role of navigation. Eagle Eye is one of the most commonly used functions in map browsing. The most common way to implement the Eagle eye is to use a Mapcontrol control to display the map full-scale, and draw a red rectangle above it to indicate the current map's display range, and to realize the Mapcontrol interaction between the Eagle Eye Mapcontrol and the main form.

Tutorial directory:

First, the establishment of desktop GIS application framework

The addition of the second-speaking menu and its implementation

The third speaking Mapcontrol and Pagelayoutcontrol synchronization

The addition and implementation of status bar information

The realization of Eagle eye in the five words

Add and implement the right-click menu

Tutorial bugs and Optimization scenarios 1

Seventh implementation of Layer symbol selector 1

Seventh implementation of Layer symbol selector 2

Eighth, the query display of the property data table

------------------------------------------------------------------

In the previous lecture, we implemented the information on the status bar to show that we are going to implement eagle eye function in this talk.

The so-called Eagle Eye, is a thumbnail map, there is a rectangular box, rectangular box area is currently displayed in the map area, drag the rectangle can change the current map display location, change the size of the rectangle box, you can change the current map display area size, from the role of navigation. Eagle Eye is one of the most commonly used functions in map browsing.

The most common way to implement the Eagle eye is to use a Mapcontrol control to display the map full-scale, and draw a red rectangle above it to indicate the current map's display range, and to realize the Mapcontrol interaction between the Eagle Eye Mapcontrol and the main form. The final effect of this talk is as follows:

Figure 1 Eagle Eye effect

1 , add Eagle Eye Control

Since this tutorial does not pre-empt the position of Hawkeye in the first lecture, we need to tweak the program framework a little bit and add a mapcontrol to show the Eagle's eye.

In this tutorial, we put the eagle eye below the layer control and adjust it as follows:

(1) In Design view, select the TabControl1 control, which is the container where the layers and properties are placed, set its Dock property to None, and drag it down with the mouse. Drag the SplitContainer control in the Toolbox to the left pane of the form, which is placed next to the TabControl1 control. and set its Orientation property to horizontal.

(2) Select the TabControl1 control, press Ctrl+x to cut, and then select the Panel1 that you just pasted into SplitContainer2, as shown in 2. Effect 3 is shown when the operation is complete.

Figure 2

Figure 3

(3) Select the SplitContainer2 control (if it is not selected, select SplitContainer2 directly in the properties panel) and set its Dock property to Fill. Check tabControl1 again to set its Dock property to Fill.

(4) Select the Mapcontrol control from the Toolbox and drag it to the SplitContainer2 Panel2 as the Eagle Eye control. The final effect is shown in 4.

Figure 4

2 , the Eagle Eye realization

(1) loading the map into the Eagle Eye control

When the map is loaded into the master map control, it also loads into the Eagle Eye control, adding the following code to the Axmapcontrol1_onmapreplaced event response function (which has been added in the previous section of the function):

private void Axmapcontrol1_onmapreplaced (object sender, Imapcontrolevents2_onmapreplacedevent e)

{

The preceding code is omitted

When the map of the main map display controls is replaced, the map in Eagle's eye also follows the replacement

This.axMapControl2.Map = new Mapclass ();

Add all the layers in the main map control to the Eagle Eye control

for (int i = 1; I <= this.axMapControl1.LayerCount; i++)

{

This.axMapControl2.AddLayer (This.axMapControl1.get_Layer (this.axmapcontrol1.layercount-i));

}

Setting the Mapcontrol display range to the global extent of the data

This.axMapControl2.Extent = this.axMapControl1.FullExtent;

Refresh the Eagle Eye Control map

This.axMapControl2.Refresh ();

}

(2) Draw the Eagle Eye Rectangle box

Adds a onextentupdated event for the Hawkeye control MapControl1, which responds when the display range of the main Map control changes, updating the rectangle in the Eagle Eye control accordingly. Its response function code is as follows:

private void Axmapcontrol1_onextentupdated (object sender, Imapcontrolevents2_onextentupdatedevent e)

{

Get a new range

Ienvelope penv = (ienvelope) e.newenvelope;

Igraphicscontainer Pgra = Axmapcontrol2.map as Igraphicscontainer;

Iactiveview pAv = Pgra as Iactiveview;

Clears any graphic elements in the axMapControl2 before drawing

Pgra.deleteallelements ();

Irectangleelement Prectangleele = new Rectangleelementclass ();

IElement PEle = Prectangleele as ielement;

Pele.geometry = penv;

Set the red box in the Eagle Eye chart

Irgbcolor Pcolor = new Rgbcolorclass ();

pcolor.red = 255;

Pcolor.green = 0;

Pcolor.blue = 0;

Pcolor.transparency = 255;

Produces a line symbol object

Ilinesymbol poutline = new Simplelinesymbolclass ();

Poutline.width = 2;

Poutline.color = Pcolor;

Set color Properties

Pcolor = new Rgbcolorclass ();

pcolor.red = 255;

Pcolor.green = 0;

Pcolor.blue = 0;

pcolor.transparency = 0;

Set the properties of a fill symbol

Ifillsymbol Pfillsymbol = new Simplefillsymbolclass ();

Pfillsymbol.color = Pcolor;

Pfillsymbol.outline = Poutline;

Ifillshapeelement Pfillshapeele = PEle as ifillshapeelement;

Pfillshapeele.symbol = Pfillsymbol;

Pgra.addelement ((ielement) pfillshapeele, 0);

Refresh

Pav.partialrefresh (esriviewdrawphase.esriviewgraphics, NULL, NULL);

}

(3) Eagle Eye interacts with the master MAP control

Add the OnMouseDown event for the Hawkeye control MapControl2, with the following code:

private void Axmapcontrol2_onmousedown (object sender, Imapcontrolevents2_onmousedownevent e)

{

if (This.axMapControl2.Map.LayerCount! = 0)

{

Press the left mouse button to move the rectangle box

if (E.button = = 1)

{

IPoint ppoint = new Pointclass ();

Ppoint.putcoords (E.MAPX, e.mapy);

Ienvelope penvelope = this.axMapControl1.Extent;

Penvelope.centerat (PPoint);

This.axMapControl1.Extent = Penvelope;

This.axMapControl1.ActiveView.PartialRefresh (esriviewdrawphase.esriviewgeography, NULL, NULL);

}

Press the right mouse button to draw a rectangular box

else if (E.button = = 2)

{

Ienvelope penvelop = This.axMapControl2.TrackRectangle ();

This.axMapControl1.Extent = Penvelop;

This.axMapControl1.ActiveView.PartialRefresh (esriviewdrawphase.esriviewgeography, NULL, NULL);

}

}

}

Add OnMouseMove event for Hawkeye Control MapControl2, the main implementation is to move the rectangle when the left mouse button is pressed, and also change the display range of the master graph control. The code is as follows:

private void Axmapcontrol2_onmousemove (object sender, Imapcontrolevents2_onmousemoveevent e)

{

If it is not left-click, return directly

if (E.button! = 1) return;

IPoint ppoint = new Pointclass ();

Ppoint.putcoords (E.MAPX, e.mapy);

This.axMapControl1.CenterAt (PPoint);

This.axMapControl1.ActiveView.PartialRefresh (esriviewdrawphase.esriviewgeography, NULL, NULL);

}

1. Compile and run

Press F5 to compile and run the program.

Look for the Eagle eye function you have achieved, press the left arrow in the Eagle Eye window to move, or press the right button to draw a rectangle in the Hawkeye window, the main map window display range will follow the change. After zooming in and out of the map in the main map window, the size of the rectangular frame of the Hawkeye window will change as well.

"The ArcGIS engine+c# Instance development tutorial" fifth talk about Eagle Eye's realization

Related 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.