Application Design of MapObejcts Components

Source: Internet
Author: User

Application Design of MapObejcts component (Map Drawing Output)
Map plotting outputs use the attributes and methods provided by the Map control. Before learning this section, familiarize yourself with the Map control and focus on its plotting attributes and methods.

2.8.1 Coordinate System
1 Map control window Coordinate System
The Map control window uses the Cartesian coordinate system, which uses the upper left corner of the control window as the origin, the right side as the X axis, and the downward side as the Y axis. The default measurement unit of the coordinate system is twip, Tix is a fixed length unit, and 1 tix equals 1/1440 inch (inch ). The mouse event function of the Map control uses this coordinate system.

In VB, the Form. ScaleMode attribute sets the coordinate measurement units of the Form. In VB 6.0, seven measurement units can be set. The default value of ScaleMode indicates that the measurement unit of the form is. By default, all controls on the Form use the measurement units specified by the Form. ScaleMode attribute. Therefore, the default measurement unit of the Map control window is. In this example, the unit of coordinate Length Used in the program is, except for the program specified in this section.

The Map control window uses the coordinate measurement unit of Form, so you can use Form. scaleMode sets the coordinate measurement unit of the Map control window. However, the set measurement unit does not work for the functions and methods of the Map control. If you do not use the Windows API function, you should not change the Form. the default value of ScaeMode to avoid errors.

The Map control window coordinate system is defined by the compiler of the development language. If the compiler of the same language comes from different manufacturers, the window coordinate system may be different. Window coordinate systems defined in different languages are also different.

2 Map control window data Coordinate System
The coordinate system specified by the Map. CoordinateSystem attribute. The definition method of the coordinate system is the same as that of the layer data coordinate system.

If Map. CoordinateSystem is assigned a value without a statement in the program, its value is Nothing. The data Coordinate System of the Map control window uses the layer data coordinate system.

3 layer data Coordinate System
The map data in the file uses the Cartesian coordinate system. The coordinate system and its coordinate units are described in the projection element file. Map data is the coordinate value (X, Y) of the numbers of points, lines, and faces.

(1) Coordinate units of vector map data

If a map has been projected, the map data coordinates are measured in length units. The most common length units in China are meters, and small-scale maps are commonly used in kilometers.

If the map is not projected, the coordinate unit of the map data uses decimal degrees, the X coordinate represents the longitude, And the Y coordinate represents the latitude. Coordinates (123.5, 43.2) indicate that the longitude is 123.5 degrees, and the latitude is 43.2 degrees. Maps are not projected. Using geographic coordinates to record map data is the optimal data representation scheme in the geographic information system. This scheme is adopted by the national basic scale topographic map database in China.

(2) Coordinate units of raster map data

The coordinate unit is indicated by the length and width of the rectangle corresponding to the raster pixel on the ground. The column number of the pixel is X coordinate, and the row number is Y coordinate. The grid data coordinate system is consistent with the device coordinate system. In most cases, the grid pixel is a square or a rectangle.

4 device coordinate system
The output device has its own coordinate system, which represents coordinates using rows and columns, and uses pixels as the coordinate measurement unit. Pixels are the smallest image that the output device can depict on the media. Whether it is an image, image, or text, any output is converted into pixels and output on the device. Dot is often used in the printer or plotter instruction, which is a pixel. The dot per inch (dpi) is used to represent the resolution. The point on the device is measured in pixels (dot). The column where the point is located is the X coordinate, and the behavior Y coordinate of the point. The defined coordinate system is called the device coordinate system. The origin of the device coordinate system is in the upper left corner, and the right is in the X axis and the downward is in the Y axis. It is not hard to see that if the length unit of the coordinate is Pixel, the coordinate of the Map control is the coordinate system of the device. Therefore, the device coordinate system is a special case of the control coordinate system.

Most devices use squares and rectangles.

The minimum pixel size for drawing on some devices can be set through software or hardware. Printers, mappers, and monitors are common output devices. You can set resolutions according to instructions. The resolution of some devices is fixed and cannot be set.

The device coordinate system is used for device direct programming control. In Windows, you can call the device driver to control the device. The device driver and Windows API functions use the device coordinate system.

The Printer and Screen predefined object instances of VB provide the TwipsPerPixelX and TwipsPerPixelY attributes for conversion between pixels and coordinate units.

5 coordinate transformation during drawing display
The Map1 window shows the map coordinate transformation process as follows:

If Map1.CoordinateSystem = Nothing

Convert layer coordinate data to Map1 window Coordinate System Data

Drawing with Map1 window Coordinate System Data

Else

Convert layer coordinate data to Map1 control data Coordinate System Data

Convert the data in the data Coordinate System of the Map1 control to the data in the Map1 window coordinate system.

Drawing with Map1 window Coordinate System Data

End If

Drawing data in the Map1 window coordinate system is completed in two steps:

Convert the window coordinate system data to the device coordinate system data

Call Windows API function drawing with device coordinate system data

This is also the case with the coordinate transformation process for drawing with a printer.

6 Map. Extent attributes and coordinate system used in Map event Functions
Coordinate data in the Map1.Extent attribute uses the coordinate system of map data.

Component names of Map1.Extent attributes
Note
 
Map1.Extent. Width
Map1 window width
 
Map1.Extent. Height
Height of the Map1 window
 
Map1.Extent. Top
Y coordinate of the top edge of the Map1 window
 
Map1.Extent. Left
X coordinate of the left edge of the Map1 window
 

Components of the Map1.Extent attribute

The coordinate system of the Map control is used in the Map1 event function, as shown in figure

Map1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)

Map1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)

In other functions, X and Y indicate the coordinates of the current mouse position in the Windows Coordinate System of the Map1 control. The coordinate unit is. See the program running result in the MapExtent directory.

Example 1 calculate the coordinates of a point in the Map1 window in Four Coordinate Systems (for the complete program, see the sample directory Coordinate)

Map1.CoordinateSystem = Map1.Layers. Item (0). CoordinateSystem. GeoCoordSys

 

Private Sub Map1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim DevX, DevY As Single

Label1.Caption = "Map control window coordinate system X =" & X & "Y =" & Y

 

'Calculate the coordinates of the Map control device coordinate system:

DevX = Form1.ScaleX (X, Form1.ScaleMode, vbPixels)

DevY = Form1.ScaleY (Y, Form1.ScaleMode, vbPixels)

Label2.Caption = "Map control device coordinate system X =" & DevX & "Y =" & DevY

 

'Calculate the coordinates of the Map control data coordinate system:

Dim aPoint As New MapObjects2.Point

Dim TwipsX, TwipsY As Long

If Form1.ScaleMode <> vbTwips Then

TwipsX = ScaleX (X, Form1.ScaleMode, vbTwips)

TwipsY = ScaleY (Y, Form1.ScaleMode, vbTwips)

Else

TwipsX = X

TwipsY = Y

End If

Set aPoint = Map1.ToMapPoint (TwipsX, TwipsY)

Label3.Caption = "Map control data coordinate system X =" & aPoint. X & "Y =" & aPoint. Y

 

'Calculate coordinates of the coordinate system of the Map1 layer:

Dim thePrj As MapObjects2.ProjCoordSys

Dim bPoint As MapObjects2.Point

Set thePrj = Map1.Layers. Item (0). CoordinateSystem

Set bPoint = thePrj. Transform (Map1.CoordinateSystem, aPoint)

Label4.Caption = "Map control layer coordinate system X =" & bPoint. X & "Y =" & bPoint. Y

End Sub

Exercise

1. Run the example 1 program, observe the variation of coordinate values in the midpoint of the Map1 window, and summarize the definitions of four coordinate systems.

2. interactively change the values of Map1.CoordinateSystem and Form1. ScaleMode, and design the program to implement the function of Example 1.

2.8.2 drawing properties and methods of the Map control
1 hWnd attribute
HWnd As OLE_HANDLE

OLE_HANDLE is the alias of the long data type, so the hWnd data type is long.

Windows operating systems do not need to use the entire display area of the screen when drawing on the screen, but only send data to a rectangular area of the screen, which is called a window. Every application running on the desktop has a window. in Windows, a unique number (Handle) is assigned to each window to manage the window ). The window handle is used for window operations. In many Windows API (Application Programming Interface, Application Programming Interface) functions, the window handle is often used and expressed with the dedicated name hWnd. In other scenarios, hWnd is also commonly used to indicate the window handle. hWnd has become the dedicated name of the window handle. API provides rich window operation functions. The Map. hWnd attribute can be used to add the display content of the Map window and expand the Map control functions. In Objects Browser of Visaul Basic, locate Map. hWd and Press F1 to see the sample program.

2. output image or graphic file
A Map drawn in the Map control can form a raster structure image or a vector structure image and save it to a file. It can also be saved to the clipboard for use by other software. There are four methods to implement this function. The ExportMap, ExportMap1, and ExportMap2 methods work the same way.

(1) Sub ExportMap (exportType As ExportMapConstants, outputFile As String, scaleFactor As Double)

Output a map with a visible range in the Map1 window to a BMP or EMF format file, which can also be saved to the clipboard. The output data format and storage location are specified by the exportType parameter, which is described in the following table.

ExportType Value
Data format
Storage location
 
MoExportEMF 0
EMF
File
 
MoExportBMP 1
BMP
File
 
MoExportClipboardEMF 2
EMF
Clipboard
 
MoExportClipboardBMP 3
BMP
Clipboard
 

ExportType parameter value table

The outputFile parameter specifies the name of the output file.

The scaleFactor parameter specifies the number of pixels to enlarge. X and Y use the same coefficient. For example, if the Map1 window contains 110 pixels per row and the scaleFactor is 3, the output image contains 330 pixels per row.

 

(2) Sub ExportMap2 (exportType As ExportMapConstants, outputFile As String, scaleFactor As Double, [useSourceDepth])

Add useSourceDepth to the interface parameters of ExprotMap to form ExportMap2. Use the ExportMap2 method when the Map control window contains an image layer.

The useSourceDepth parameter is Boolean and the default value is False ,. Specifies whether the color palette of the image layer is used in the output image ). If useSourceDepth is set to True, the output image uses the color palette of the original image layer, that is, the number of bit layers of the target image is the same as that of the original image, and the image color is fidelity.

 

(3) Sub ExportMap3 (formatType As ExportMapConstants, formatData, [scaleFactor As Double = 1], [scaleSymbology As topology = topology], [exportDepth As ExportDepthConstants = moExport8BitDepth], [palette As ExportPaletteConstants = moDefaultPalette])

This method adds three parameters to the ExportMap interface parameters to set more parameters for the output image. The meanings are as follows:

1) ExportSymbology specifies whether the symbols in the output image are scaled according to the scaleFactor. The meanings of the values are as follows.

ExportSymbology parameter value
Description
 
MoNoSymbologyScaled 0
Symbol size unchanged
 
MoLineSymbolsNotScaled 1
The width of the line remains unchanged. Multiply the dimensions of the symbol by scaleFactor.
 
MoAllSymbologyScaled 2
Symbol size multiplied by scaleFactor
 

ExportSymbologyScaleConstants enumerated constant value table

 

2) The exportDepth parameter specifies the number of bit planes of the output image. The meanings of the values are as follows.

ExportDepth parameter value
Number of bit planes of the output image
 
MoExport8BitDepth 0
8 bit, the palette parameter is valid
 
MoExportSourceDepth 1
24 bit. If Map1 contains 24 bit images. Otherwise, 8 bit
 
MoExport24BitDepth 2
24 bit
 

ExportDepthConstants enumerated constant value table

3) when the palette outputs an 8-Bit Bitmap, it specifies the color palette of the output bitmap. The meanings of the values are shown in the following table.

Palette parameter value
Color Palette used for output bitmap
 
MoDefaultPalette 0
Default palette for Windows operating systems
 
MoHalfTonePalette 1
The closest half color palette to Map1
 
MoWebSafePalette 2
The palette on the network closest to Map1
 
MoGraysWithSystemColorsPalette 3
The 8-bit color is mapped to the gray value palette,
 

ExportPaletteConstant enumeration constant value table

 

(4) Sub ExportMapToJpeg (outputFile As String, [percentQuality As Long = 85], [isProgressive As Boolean = False], [scaleFactor As Double = 1], [scaleSymbology As ExportSymbologyScaleConstants = moLineSymbolsNotScaled])

This method outputs JPEG images. Two parameters are not described above:

1) The percentQuality value ranges from 0 to 100, indicating the quality of the output image. The larger the value, the higher the quality, but the larger the image file.

2) isProgressive specifies whether the output image uses an Improved JPEG format.

 

3 PrintMap Method
Sub PrintMap (docName As String, outputFile As String, landscapeOrientation As Boolean)

Output the map in the Map1 window to the printer, or save it as a print file. When printing, the map size is automatically adjusted to the size of the printed paper.

1) docName: Specifies the name of the printed document. You can enter the name in the print task queue of the printer.

2) If outputFile saves the printed result to a file, you can specify the file name here. Otherwise, an empty string is used.

3) landscape specifies the printing direction of the map on the paper. If the value is True, vertical printing is performed. Otherwise, horizontal printing is performed.

 

4. Copy the map to the device marked by hDC.
(1) Sub OutputMap (hDC As OLE_HANDLE)

Copy all the content displayed in the Map window to the device marked by the hDC.

The hDC long parameter (OLE_HANDLE is the alias for long) is used to specify the output device. HDC is a special term for API function parameters in Windows operating systems. It is called a device description table Handle (Handle of device context). It essentially identifies the device parameter table and its driver number, in Windows, hDC is used as the input/output API function of a device.

In Visual Basic, Form forms, Picture image boxes, and Printer instances have hDC attributes.

Example 1: copy the map to the control. Copy all the displayed content in the Map1 window to the Picture1 window of the image control (see the button in the OutMap program window in the OutMap directory to copy the map to the corresponding code of the control ).

Private Sub commandateclick () 'copies the map in Map1 to the Picture1 control window.

Map1.OutputMap Picture1.hDC

End Sub

The OutputMap method can also hard copy the content in the Map window and output it to the printer.

Example 2 print the map. Output the map in the Map1 window to the printer.

Private Sub Command4_Click () 'print map

Printer. Print 'initialize the Printer

Map1.OutputMap Printer. hDC print map

Printer. EndDoc 'end Printing

End Sub

 

(2) Sub OutputMap2 (hDC As OLE_HANDLE, X As Long, Y As Long, Width As Long, Height As Long, [DrawFlags])

Copy all the content displayed in the Map window to the device marked by the hDC.

X coordinate system X coordinate in the upper left corner of the drawing rectangle of the target device

Y coordinate system: Y coordinate in the upper left corner of the drawing rectangle of the target device

Width: width of the rectangle area of the drawing of the target device in the coordinate system of the device

Height the height of the rectangular area of the drawing of the target device in the coordinate system of the device.

DrawFlags is a numeric constant that specifies how to plot. The meanings are shown in the following table:

Value of drawFlags
Description
 
MoNoBackground 1
Do not copy the border of the background rectangle
 
MoClipToExtent 2
Copy only content within Map1.Extent
 

DrawFlags

Example 3 print the combined map. Copy the map in Map1 to the upper-right area 1/4 and lower-right area 1/4 of the printed paper to form a map.

Private Sub Command5_Click () 'print the combined map

Dim pixHeight As Long

Dim PixWidth As Long

Printer. Print 'initialize the Print page

'Convert the page size to the number of imaging elements.

PixHeight = Printer. ScaleHeight/Printer. TwipsPerPixelY

PixWidth = Printer. ScaleWidth/Printer. TwipsPerPixelX

'Print the map

Map1.OutputMap2 Printer. hDC, PixWidth/2, 0, PixWidth/2, pixHeight/2

Map1.OutputMap2 Printer. hDC, PixWidth/2, pixHeight/2, PixWidth/2, pixHeight/2

Printer. EndDoc 'print the end of the document, output the current print page, and end printing

End Sub

 

The parameter hDC is required for OutputMap and OutputMap2. If you do not know the hDC but know the hWnd of the window, you can use the API function to obtain the hDC. The following program obtains the hDC of the current FORM:

Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As long' API Function

Private Sub commandementclick ()

Dim GethDC As Long

GethDC = GetDC (Me. hWnd) 'Use the API function to obtain the hDC of the window.

End Sub

 

5 CopyMap Method
Sub CopyMap (scaleFactor As Double)

Copy the map in the Map1 window to the clipboard and use EMF (enhanced metafile format, Windows enhanced metafile format) and WMF (standard metafile format, Windows standard metafile format) format.

ScaleFactor map output scaling factor.

For example, see the code for copying a map to the clipboard command button in the OutMap directory.

 

Exercise

1. Write a program to implement the functions of Example 1, example 2, and example 3.

2. Copy the map to the clipboard using the Map1.CopyMap method and use the image processing software you are familiar with to extract the map from the clipboard.

2.8.3 Map Drawing Output
1. Drawing Output on forms and controls
Maps in the Map control can be output to the form or control. Both forms and controls are Windows. Map controls implement function plotting at the underlying layer on Windows. Therefore, the two outputs share the same programming principle. Map. OutputMap or Map. OutputMap2 can implement these two functions.

Example 1: copy the map to another form. Copy the map in Map1 on Form1 form to the form ShowMap (see the program in the OutMap2 directory ).

1) copy the map to another form by using the command button to display the ShowMap form.

Private Sub Command2_Click ()

ShowMap. Show

End Sub

2) copy the map in the Paint event of the ShowMap form.

Private Sub Form_Paint ()

Form1.Map1. OutputMap Me. hDC

End Sub

Example 2 Map combination. Copy the map in Map1 to the upper and lower sides of the right half of the Picture1 image box (see the code corresponding to the map combination command button in the OutMap2 directory ).

Private Sub Command3_Click ()

With Me. Picture1

Map1.OutputMap2. hDC,. ScaleWidth/2, 0,. ScaleWidth/2,. ScaleHeight/2

Map1.OutputMap2. hDC,. ScaleWidth/2,. ScaleHeight/2,. ScaleWidth/2,. ScaleHeight/2

End

End Sub

The coordinate parameters in the Map1.OutputMap2 method use the device coordinate system. Set the Me. Picture1.ScaleMode attribute value to Pixel. In this way, the control Coordinate System of Picture1 is consistent with the device coordinate system.

2 printer Drawing Output
Map. printMap or Map. the OutputMap method copies the Map in the Map window to the printer. The output chart range is the whole Map window, and the Map output scale is adjusted to obtain a larger output Map as much as possible.

The Map. PrintMap method can print a page of Map with a single statement. You do not need to use the printer to initialize and print the concluding remarks of the document.

The Map. OutputMap2 method can specify the size of the output Map and its position on the paper, and output the combined Map.

3. Scale Calculation
(1) Definition of scale

If the actual distance between two places on the ground is L, the distance on the drawing is M, the ratio is B

B = L/M

Note

1: B

It is called the scale of a map.

(2) Calculate the B value

In MapObjects2, the map output function Map1.OutputMap Map1.OutPutMap2 Map1.PrintMap Map1.CopyMap outputs the map rectangle area displayed in the Map1 window. The B value is calculated based on the size and print size of the rectangle area on the ground.

1) determine the value of L. in MappObjects2, if the projection metadata is complete, the data in Map1.Extent records the actual size of the map window rectangle on the ground. Accordingly, the value of L can be obtained, if the map data is projected, from Map1, CoordinateSystem. unit. type can determine the length unit of the L value. If the map data is not projected, the length unit of the L value is latitude and longitude. In this case, the actual size of the ground rectangle needs to be obtained through projection calculation.

2) determine the M value Printer. ScaleWidth Printer. ScaleHeight: the width and height of the printing area, measured in twips. Map1.OutputMap Map1.PrintMap Map1.CopyMap three functions print the map in the rectangle area of the map window in the largest possible size. The M value can be determined based on the aspect ratio of the map window and the aspect ratio of the printing area.

When Map1.OutputMap2 prints a map, the M value can be determined based on its interface parameter Width or Height.

Example 3: Calculate the print scale. In the Map1 window, the map is projected. Calculate the scale of the map by Map1.OutputMap Map1.PrintMap Map1.CopyMap (see the code corresponding to the map scale calculation command button in the OutMap2 directory ).

Private Sub Command7_Click () 'calculate the scale

Dim MapUnitToTwipsFactor As Double

Dim M As Double, L As Double, B As Double

MapUnitToTwipsFactor =-1

If Map1.CoordinateSystem. IsProjected Then 'map is projected.

Select Case Map1.CoordinateSystem. Unit. Type

Case moUnit_Meter the unit of map data length is meter.

MapUnitToTwipsFactor = 1440 # * 100/2 .54 'meters become the multiplier factor of Twips

Case moUnit_Kilometer the map data length unit is kilometers.

MapUnitToTwipsFactor = 1440 # * 100/2 .54*1000 'km becomes the multiplier of Twips

When 'case is another unit of length .......

End Select

If MapUnitToTwipsFactor> 0 # Then

'Map1.outputmap Printer. hDC print map

If Map1.Extent. Width/Map1.Extent. Height> Printer. ScaleWidth/Printer. ScaleHeight Then

L = Map1.Extent. Width * MapUnitToTwipsFactor

M = Printer. ScaleWidth

Else

L = Map1.Extent. Height * MapUnitToTwipsFactor

M = Printer. ScaleHeight

End If

B = L/M

MsgBox "The Map Printing scale is 1:" & B

End If

End If

End Sub

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/lgmawei/archive/2006/09/26/1285750.aspx

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.