MapObject control used layer operation
Author: Beijing Zhangsong Wei
Zswzwy@163.com
The last time we have added a layer, but you can't do anything on the layer, such as moving, zooming, narrowing, full screen. Next I will introduce how to join these features in MapObject, is you ready? let's start.
First you have to join four press on the toolbar, ID is not ID_PAN, ID_ZOOMOUT, ID_ZOOMIN, ID_FULLSCREEN. Plus the call to change the way I don't have to say it. Add them to the Command UPDATE_COMMAND_UI message separately.
Then add member variables UINT M_MOTOOL in the view class; to identify the current task of the mouse.
Ok, the most critical time is here, we have to add message mapping to the MO. Everyone knows that the message mapping to join the control in the dialog is very simple. However, the MO control is created by our own, what do you join? Is it possible to map with ordinary messages? Let me see this fool. Give MO to join the message mapping a total of three steps:
1. Add the following code to the message map in the CPP file of the view class:
Begin_Eventsink_Map (CWEATHERGISVIEW, CVIEW)
// {{AFX_Eventsink_map (CWEATHERGISVIEW)
ON_EVENT (CWEATHERGISVIEW, ID_GISMAP, -605 / * mousedown * /, onmousedownloadoup1, vts_i2 vts_i2 VTS_I4 VTS_I4)
//}} AFX_EVENTSINK_MAP
END_EVENTSINK_MAP ()
2, join the view class. H filed
AFX_MSG Void OnMousedownMap1 (Short Button, Short Shift, long x, long y)
Note To join the Declare_EventSink_map () statement at the same time.
3, okay, mapping is added, the function also declares, the following will be implemented. Add:
Void CMYVIEW :: OnMouseDownMap1 (Short Button, Short Shift, long x, long y)
Success, the following is the operation of the layer. Let us start from amplification.
In the onMouseDownMap1 function we want to determine what the current mouse is, it makes the corresponding operation. If you use a Switch statement, it is so convenient:
Switch (m_motool)
{
Case ID_PAN:
{
m_map.setmousepointer (54); // Set mouse style
m_map.pan (); // Mobile
Break;
}
Case ID_Zoomout:
{
CMORECTANGLE prect (m_map.trackRectangle ()); // Mo rectangular class
IF (prect.getwidth () <10)
{
CMOPOINT PT (m_map.tomappoint (float) x, (float) y); // turn the mouse point to a map point
/ / Draw a rectangle and zoom
CMORECTANGLE R (m_map.getextent ());
R.Scalerectangle (0.5);
m_map.seltExttleT (r);
m_map.centerat (pt.getx (), pt.gety ());
}
Else if (prect.getwidth () <200)
{
CMOPOINT PT (M_Map.TomAppoint ((Float) x, (float) y);
CMORECTANGLE R (m_map.getextent ());
R.Scalerectangle (0.5);
M_map.seltent (r); m_map.centerat (pt.getx (), pt.gety ());
}
Break;
}
Case id_zoomin:
{
CMOPOINT PT (M_Map.TomAppoint ((Float) x, (float) y);
CMORECTANGLE R (m_map.getextent ());
R.Scalerectangle (1.5);
m_map.seltExttleT (r);
m_map.centerat (pt.getx (), pt.gety ());
Break;
}
Ok, the operation code we have written, now set the mouse task. The ID is attached to M_Motool in the Command message.
Add PCMDUI-> setCheck in Update_Command_UI (m_motool == id_ your ID); note that full screen can not add.
Ok, I'm big in 80%! It is a full screen. Add the following code in the ID_fullscreen's Command!
CMORECTANGLE R (M_Map.Getfullextent ());
m_map.seltExttleT (r);
Next time I will introduce how to draw points, lines, faces such as layers, good, see it next time.