Research and Development of underwater Terrain contour line connection technology based on ArcGIS Engine
Http://hi.baidu.com/giswoduxing/blog/item/12a6f388a2fb38b90e244445.html
1. Create a new project named eagleeye. At the end of the wizard, change the view class to cfromview.
2. import data to the Project
3. Add a toolbar control, a toccontrol Control, and two mapcontrol controls to the project.
Options: m_toolbar, m_toccontrol, m_mapcontrol1, and m_control2. Add two global variables for the View class: imapptr.
M_map1; imapptr m_map2. Add the following code to the cmoninitialupdate function:
Void cmyview: oninitialupdate ()
{
Cformview: oninitialupdate ();
Getparentframe ()-> recalclayout ();
Resizeparenttofit ();
Crect windowrect;
Getwindowrect (windowrect );
// Set the positions of the three controls
If (m_toolbar)
M_toolbar.setwindowpos (this, 5, 0, windowrect. Width (), 20, swp_nozorder );
If (m_toccontrol)
M_toccontrol.setwindowpos (this, 5, 25, (windowrect. Width ()-15)/5,
(Windowrect. Height ()-35) * 3/5, swp_nozorder );
If (m_mapcontrol1)
M_mapcontrol1.setwindowpos (this, (windowrect. Width ()-15)/5 + 10, 25,
(Windowrect. Width ()-15) * 4/5, windowrect. Height ()-35, swp_nozorder );
If (m_mapcontrol2)
M_mapcontrol2.setwindowpos (this, 5, (windowrect. Height ()-35) * 3/5 + 30,
(Windowrect. Width ()-15)/5, (windowrect. Height ()-35) * 2/5, swp_nozorder );
// Set the partner relationship
Lpunknown lpuk = m_mapcontrol1.getcontrolunknown ();
Lpdispatch lpdis = 0;
Lpuk-> QueryInterface (iid_idispatch, (void **) & lpdis );
M_toolbar.setbuddycontrol (lpdis );
M_toccontrol.setbuddycontrol (lpdis );
M_map1 = m_mapcontrol1.getmap ();
M_map2 = m_mapcontrol2.getmap ();
Long I, layercount;
Ilayerptr layer;
M_map1-> get_layercount (& layercount );
For (I = 0; I <layercount; I ++)
{
M_map1-> get_layer (I, & layer );
M_map2-> addlayer (layer );
}
}
Add the wm_size message RESPONSE event to the View class. The Code is as follows:
Void cmyview: onsize (uint ntype, int CX, int CY)
{
Cformview: onsize (ntype, CX, CY );
// Todo: add your message handler code here
Crect windowrect;
Getwindowrect (windowrect );
If (m_toolbar)
M_toolbar.setwindowpos (this, 5, 0, windowrect. Width (), 20, swp_nozorder );
If (m_toccontrol)
M_toccontrol.setwindowpos (this, 5, 25, (windowrect. Width ()-15)/5,
(Windowrect. Height ()-35) * 3/5, swp_nozorder );
If (m_mapcontrol1)
M_mapcontrol1.setwindowpos (this, (windowrect. Width ()-15)/5 + 10, 25,
(Windowrect. Width ()-15) * 4/5, windowrect. Height ()-35, swp_nozorder );
If (m_mapcontrol2)
M_mapcontrol2.setwindowpos (this, 5, (windowrect. Height ()-35) * 3/5 + 30,
(Windowrect. Width ()-15)/5, (windowrect. Height ()-35) * 2/5, swp_nozorder );
}
4. Add the onafterscreendraw event response function for the mapcontrol1 control. The Code is as follows:
Void cmyview: onafterscreendrawmapcontrol1 (long HDC)
{
// Todo: add your control notification handler code here
Iactiveviewptr ipactive (m_map2 );
Igraphicscontainerptr ipgraphics (ipactive );
// Clear the element of mapcontrol2
Ipgraphics-> deleteallelements ();
// Add the same layer as mapcontrol1 to mapcontrol2
M_mapcontrol2.clearlayers ();
Long I, layercount;
Ilayerptr layer;
M_map1-> get_layercount (& layercount );
For (I = 0; I <layercount; I ++)
{
M_map1-> get_layer (I, & layer );
M_map2-> addlayer (layer );
}
// Set the range box displayed in mapcontrol2
Irgbcolorptr iprgb (clsid_rgbcolor );
Iprgb-> put_blue (0 );
Iprgb-> put_green (0 );
Iprgb-> put_red (255 );
Icolorptr ipcolor (iprgb );
Ienvelopeptr ipenvelope;
Ipenvelope = m_mapcontrol1.getextent ();
Isimplelinesymbolptr ipsimplelinesymbol (clsid_simplelinesymbol );
Ipsimplelinesymbol-> put_color (ipcolor );
Ipsimplelinesymbol-> put_width (1 );
Ipsimplelinesymbol-> put_style (esrislssolid );
Ilinesymbolptr iplinesymbol (ipsimplelinesymbol );
Isimplefillsymbolptr ipsimplefillsymbol (clsid_simplefillsymbol );
Ipcolor-> put_transparency (0 );
Ipsimplefillsymbol-> put_color (ipcolor );
Ipsimplefillsymbol-> put_outline (iplinesymbol );
Irectangleelementptr iprectangleelement (clsid_rectangleelement );
Igeometryptr ipgeometry (ipenvelope );
Ifillsymbolptr ipfillsymbol (ipsimplefillsymbol );
Ifillshapeelementptr ipfillshape (iprectangleelement );
Ipfillshape-> put_symbol (ipfillsymbol );
Ielementptr ipelement (ipfillshape );
Ipelement-> put_geometry (ipgeometry );
Ipgraphics-> addelement (ipelement, 0 );
}
5. Add the onmousedown event response function for mapcontrol2. The Code is as follows:
Void cmyview: ononmousedownmapcontrol2 (long button, long shift, long X, long y, double MapX, double
Mapy)
{
// Todo: add your control notification handler code here
Ienvelopeptr ipenvelope (clsid_envelope );
Ipenvelope = m_mapcontrol1.getextent ();
Ipointptr ippoint (clsid_point );
Ippoint-> putcoords (MapX, mapy );
Ipenvelope-> centerat (ippoint );
M_mapcontrol1.setextent (ipenvelope); // The ononafterscreendrawmapcontrol1 function is activated at this time.
}