More complete eagleeye implementation, share with you

Source: Internet
Author: User
Tags getcolor imap ipoint
It mainly implements the following: 1. load mxd file synchronization; onmapreplaced event 2. load layer file synchronization; onitemadded event 3. check the state of the layers in TOC and synchronize the visible state of the layers in eagleeye; contentschanged event 4. right-click the eagleeye view and select the display area in the main view. 5. in the eagleeye view, left-click to center the rectangle. 6. right-click the TOC menu and choose delete layer;
 
 
Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. windows. forms; using ESRI. arcGIS. CARTO; using system. diagnostics; using ESRI. arcGIS. geometry; using ESRI. arcGIS. display; using ESRI. arcGIS. controls; namespace demo1 {public partial class form1: FORM {public form1 () {initializecomponent ();} I Activeviewevents_event PAE; private void axmapcontrolpoliconmapreplaced (Object sender, ESRI. arcGIS. controls. imapcontrolevents2_onmapreplacedevent e) {axmapcontrol2.clearlayers (); // clear the layer IMAP pmap = E. NEWMAP as IMAP; // The parameter E is of the object type, and the int n = pmap must be converted to the interface. layercount; For (INT I = n-1; I> = 0; I --) {axmapcontrol2.addlayer (pmap. get_layer (I);} This. PAE = E. NEWMAP as iactiveviewevents_eve NT; Pae. itemadded + = new iactiveviewevents_itemaddeventhandler (this. onitemadded); Pae. contentschanged + = new callback (callback);} void pae_contentschanged () {ibasicmap map = NULL; ilayer layer = NULL; object other = NULL; object index = NULL; esritoccontrolitem item = esritoccontrolitem. esritoccontrolitemnone; axtoccontrol1.getselecteditem (ref it Em, ref map, ref layer, ref other, ref index); ilayer player; For (INT I = 0; I <axmapcontrol2.layercount; I ++) {player = axmapcontrol2.get _ layer (I); If (player. name = layer. name) {If (layer. visible = true) player. visible = true; else player. visible = false; axmapcontrol2.refresh (); break ;}} private void form1_load (Object sender, eventargs e) {// use code to set partner controls to better protect axtoccontrol1.setbuddycontrol (Axmapcontrol1); rotate (axmapcontrol1); // disable the scroll wheel zoom-in and zoom-out function of eagleeye mapcontrol axmapcontrol2.automousewheel = false; IMAP pmap; pmap = axmapcontrol1.map; // main view PAE = pmap as iactive; PAE. itemadded + = new iactiveviewevents_itemaddeventhandler (this. onitemadded); Pae. contentschanged + = new iactiveviewevents_contentschangedeventhandler (pae_contentschanged);} private void Onitemadded (Object item) {ilayer player; player = item as ilayer; axmapcontrol2.addlayer (player, 0); // eagleeye view axmapcontrol2.refresh ();} private void axmapcontrolpoliconextentupdated (Object sender, ESRI. arcGIS. controls. imapcontrolevents2_onextentupdatedevent e) {try {ESRI. arcGIS. geometry. ienvelope envelope = (ESRI. arcGIS. geometry. ienvelope) E. newenvelope; ESRI. arcGIS. carto. igraphicscontainer GC = axmap Control2.map as ESRI. arcGIS. carto. igraphicscontainer; ESRI. arcGIS. carto. iactiveview AC = GC as ESRI. arcGIS. carto. iactiveview; // clear the content GC in axmapcontrol2 before drawing. deleteallelements (); ESRI. arcGIS. carto. ielement elment = new ESRI. arcGIS. carto. rectangleelementclass (); elment. geometry = envelope; // set the red line in the eagleeye // generate a line symbol object ESRI. arcGIS. display. ilinesymbol outlinesymbol = new ESRI. arcGIS. display. simplelinesymbolc Lass (); outlinesymbol. width = 2; outlinesymbol. color = getcolor (255, 0, 0,255); // set the color attribute // set the attribute ESRI of the fill symbol. arcGIS. display. ifillsymbol fillsymbol = new ESRI. arcGIS. display. simplefillsymbolclass (); fillsymbol. color = getcolor (9, 0, 0, 0); fillsymbol. outline = outlinesymbol; ESRI. arcGIS. carto. ifillshapeelement fillshapeelement = elment as ESRI. arcGIS. carto. ifillshapeelement; fillshapeelement. symbol = Fillsymbol; GC. addelement (ESRI. arcGIS. carto. ielement) fillshapeelement, 0); AC. partialrefresh (ESRI. arcGIS. carto. esriviewdrawphase. esriviewgraphics, null, null);} catch (exception ecatch) {MessageBox. show (ecatch. tostring () + "\ n an error occurred while drawing the red rectangle in eagleeye");} private ESRI. arcGIS. display. irgbcolor getcolor (int r, int g, int B, int t) {ESRI. arcGIS. display. irgbcolor RGB = new ESRI. arcGIS. display. rgbcolorclass (); RGB. red = r; RGB. green = g; RGB. blue = B; RGB. transparency = (byte) T; return RGB;} // right-click the rectangle to select the display range of the main view: Private void axmapcontrol2_onmousedown (Object sender, ESRI. arcGIS. controls. imapcontrolevents2_onmousedownevent e) {If (E. button = 2) {try {ipoint Ppoint = new pointclass (); Ppoint. X = E. mapX; Ppoint. y = E. mapy; ienvelope penvelop = axmapcontrol2.trackrectangle (); axmapcontrol1.extent = penvelop ;} Catch {}} private void axmapcontrol2_onmousemove (Object sender, ESRI. arcGIS. controls. imapcontrolevents2_onmousemoveevent e) {If (E. button = 1) {try {ipoint Ppoint = new pointclass (); Ppoint. X = E. mapX; Ppoint. y = E. mapy; ienvelope penvelop = axmapcontrol1.extent as ienvelope; penvelop. centerat (Ppoint); igraphicscontainer pgraphiccontainer = axmapcontrol2.map as igraphicscontainer; iact Iveview pav = pgraphiccontainer as iactiveview; pgraphiccontainer. deleteallelements (); ESRI. arcGIS. carto. ielement elment = new ESRI. arcGIS. carto. rectangleelementclass (); elment. geometry = penvelop; // set the red line in the eagleeye // generate a line symbol object ESRI. arcGIS. display. ilinesymbol outlinesymbol = new ESRI. arcGIS. display. simplelinesymbolclass (); outlinesymbol. width = 2; outlinesymbol. color = getcolor (255, 0, 0,255); // you can specify the color attribute. // Set the attribute ESRI of the fill symbol. arcGIS. display. ifillsymbol fillsymbol = new ESRI. arcGIS. display. simplefillsymbolclass (); fillsymbol. color = getcolor (9, 0, 0, 0); fillsymbol. outline = outlinesymbol; ESRI. arcGIS. carto. ifillshapeelement fillshapeelement = elment as ESRI. arcGIS. carto. ifillshapeelement; fillshapeelement. symbol = fillsymbol; pgraphiccontainer. addelement (ESRI. arcGIS. carto. ielement) fillshapeelement, 0); Pav. partialrefresh (ESRI. arcGIS. carto. esriviewdrawphase. esriviewgraphics, null, null);} catch {}} private void axmapcontrol2_onmouseup (Object sender, ESRI. arcGIS. controls. imapcontrolevents2_onmouseupevent e) {If (E. button = 1) {try {ipoint Ppoint = new pointclass (); Ppoint. X = E. mapX; Ppoint. y = E. mapy; ienvelope penvelop = axmapcontrol1.extent as ienvelope; penvelop. centerat (Ppoint); ax Mapcontrol1.extent = penvelop;} catch {}} private void Delete layer toolstripmenuitem_click (Object sender, eventargs e) {If (selectedlayer! = NULL) {axmapcontrol1.map. deletelayer (selectedlayer); axmapcontrol2.map. deletelayer (selectedlayer); selectedlayer = NULL ;}} ilayer selectedlayer; private void axtoccontrolpoliconmousedown (Object sender, itoccontrolevents_onmousedownevent e) {If (E. button = 2) {ibasicmap map = NULL; ilayer layer = NULL; object other = NULL; object index = NULL; esritoccontrolitem item = esritoccontrolitem. esritoccontrolitemnone; axtoccontrol1.hittest (E. x, E. y, ref item, ref map, ref layer, ref other, ref index); If (item = esritoccontrolitem. esritoccontrolitemlayer) {selectedlayer = layer; tocmenustrip1.show (axtoccontrol1, E. x, E. Y );}}}}}

 

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.