AE + C # implement eagleeye functions -- (2) (move with the mouse)

Source: Internet
Author: User
Vs2005 + AE9.2 implementation, main functions: eagleeye view left-click to draw a red box, right-click to drag
In the code, the main view is Mapcontrol1, And the eagleeye view is MapControl2.
Envelope is used to transfer the view range to control view synchronization.
The Code is as follows:
Variable Declaration: // variable
IMapDocument pMapDocument = new MapDocumentClass ();
IEnvelope pEn = new EnvelopeClass ();
Object oFillobject = new object ();
Private void CreateOverviewSymbol ()
{
IRgbColor iRgb = new RgbColorClass ();
IRgb. RGB = 255;
ILineSymbol pOutline = new SimpleLineSymbolClass ();
POutline. Color = iRgb;
POutline. Width = 2.3;
ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass ();
PSimpleFillSymbol. Outline = pOutline;
PSimpleFillSymbol. Style = esriSimpleFillStyle. esriSFSHollow;
OFillobject = pSimpleFillSymbol;
}

Control the drag variable: private IMoveEnvelopeFeedback pSmallViewerEnvelope; // the red box of the eagleeye small map, IMoveEnvelopeFeedback, used to move the Envelope Interface
Private IPoint pSmallViewerMouseDownPt; // move the cursor
Private bool isTrackingSmallViewer = false; // identifies whether the image is being dragged.
Static int moveCount = 0; // records the number of moves, which is used to display a red box during the move process.


Axmapcontrolpoliconmapreplaced event: axMapControl2.LoadMxFile (axMapControl1.DocumentFilename );

Loading data from two views may result in incomplete data display on the eagleeye view (I don't know if it's my computer's fault ...), In this way, data synchronization can be controlled during loading.

Axmapcontrolpoliconextentupdated event:

PEn = e. newEnvelope as IEnvelope;
AxMapControl2.ActiveView. PartialRefresh (esriViewDrawPhase. esriViewForeground, null, null );

Axmapcontrolpoliconafterdraw: esriViewDrawPhase viewDrawPhase = (esriViewDrawPhase) e. viewDrawPhase;
If (viewDrawPhase = esriViewDrawPhase. esriViewForeground)
{
AxMapControl2.DrawShape (pEn, ref oFillobject );
}

AxMapControl2_OnMouseDown: if (e. button = 1) // left-click to draw a red box
{
PEn = axMapControl2.TrackRectangle ();
AxMapControl1.Extent = pEn;
AxMapControl2.DrawShape (pEn, ref oFillobject );

If (e. button = 2) // right-click and drag the red box
{
PSmallViewerMouseDownPt = new PointClass ();
PSmallViewerMouseDownPt. PutCoords (e. mapX, e. mapY );
AxMapControl1.CenterAt (pSmallViewerMouseDownPt );

IsTrackingSmallViewer = true;
If (pSmallViewerEnvelope = null)
{
PSmallViewerEnvelope = new MoveEnvelopeFeedbackClass ();
PSmallViewerEnvelope. Display = axMapControl2.ActiveView. ScreenDisplay;
PSmallViewerEnvelope. Symbol = (ISymbol) oFillobject;
}
PSmallViewerEnvelope. Start (pEn, pSmallViewerMouseDownPt );

AxMapControl2_OnMouseMove:

If (isTrackingSmallViewer)
{
MoveCount ++;
If (moveCount % 4 = 0) // as a result of refreshing, the red box is gone. Therefore, refresh every four moves to ensure the continuity of the red box.
AxMapControl2.ActiveView. PartialRefresh (esriViewDrawPhase. esriViewForeground, null, null );
PSmallViewerMouseDownPt. PutCoords (e. mapX, e. mapY );
PSmallViewerEnvelope. MoveTo (pSmallViewerMouseDownPt );
}

AxMapControl2_OnMouseUp: if (pSmallViewerEnvelope! = Null)
{
PEn = pSmallViewerEnvelope. Stop ();
AxMapControl1.Extent = pEn;
IsTrackingSmallViewer = false;
}

Form initialization: axMapControl1.LoadMxFile (@ "load data ");
PEn = axMapControl1.Extent; // initialize the eagleeye red box
CreateOverviewSymbol ();

After testing, you can draw a red box and drag the eagleeye.
The problem is that the drag function is not perfect yet, so we should study it and paste the result.
Here, part of the idea is to drag the code from ESRI Chinese community AE version.

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.