Run Effect chart
The map scale is an indispensable element in the map. In the process of designing and developing the GIS software, how to draw the map scale is a problem that needs to be solved seriously. There are several issues to be addressed in the process:
1. What tools are used?
2. How do different types of map scales be plotted separately?
3. How to control the drawing accuracy of map scale?
The first two questions are well solved. GDI can be used in VC to complete a variety of graphics, and by studying the characteristics of different types of scale, we can complete these scale graphics through the GDI function to draw.
Let's discuss in detail how to control the plotting accuracy of map scale. The so-called control map scale of the drawing accuracy, that is, the length of the display on the screen and the actual representation of the space distance should correspond to the number shown, otherwise, we have to draw the scale of the loss of meaning. To do this, we need to understand the coordinate mapping first.
We now have to touch two kinds of coordinates, one is device coordinates, the other is logical coordinates. Device coordinates for the computer output devices, such as the coordinates on the monitor, the printer coordinates, in general, the drawing operations are in pixels as a drawing unit. The logical coordinates can be understood as the actual coordinates on our map, and the unit may be rice or decimeter.
This situation requires that we have a corresponding relationship between the device coordinates and the logical coordinates, which is the coordinate mapping. Windows provides several ways of mapping to achieve the corresponding logical coordinate system. For example, in the Mm_text mode, the coordinate origin of the device coordinate system is located in the upper-left corner of the screen, and the square of the X and Y axes points to the right and bottom of the screen, and its plotting unit is pixel; Mm_lometric mode, The drawing unit is 0.1 mm, the coordinate origin is in the upper-left corner of the screen, and the x-axis and Y-axes are pointing to the right and top of the screen respectively. We will choose the mm_lometric way in the map scale drawing process, the reason is very simple, it and we actually use the map coordinate system very similar, their coordinate unit is only the order of magnitude difference, the conversion is very convenient.
Note: In this regard, we can refer to Mr. Liu published an article "VC6.0 mapping mode conversion and how to eliminate the coordinate error," but this article at the end of the proposal is not advisable, we can improve the improvement!
To facilitate the drawing of scales, we first define the scale class. An enumeration type is also defined to enumerate the types of the scale.
enum FGScaleType
{
ST_SINGLELINE,
ST_SINGLELINE2,
ST_SINGLELINE3,
ST_FILLRECT,
ST_FILLRECT2,
ST_STEPPEDLINE,
ST_LINERECT
};
class CFGScaleDraw
{
......
FGScaleType m_ScaleType;
float m_fScale;
int m_nMinX, m_nMaxX, m_nMinY, m_nMaxY;
public:
void SetScaleType(int type);
void SetScale(float scale);
void SetRect(CRect rect);
void SetRect(int minx, int miny, int maxx, int maxy);
void DrawScale(CDC* pdc);
};
Among them, M_fscale is the scale denominator, such as the scale of 1:10,000, M_fscale = 10000;m_nminx, M_nmaxx, M_nminy, M_nmaxy control map scale plotting range; Drawscale for scale output.
Let's take a look at how Drawscale is achieved. First we use Setmapmode to complete the transformation of the mapping pattern. Since the scale we are drawing is in the X direction full of the drawing range, the ratio of the display size (DS) on the screen to the actual representation of the space Distance (DS) is the scale size 1/m_fscale, namely:1/m_fScale = ds / DS;