Eight MapX skills

Source: Internet
Author: User
Summary of eight MapX skills

1. Methods for searching objects in Mapx
Two methods:
1. Use the search method of the find object.
In mapx3.5, only full match lookup can be performed. In mapx4.0, The SEARCHEX method can find multiple matching records, and the results are obtained by findresult. Matches. For more information, see

Documentation and examples of the find. SEARCHEX method.
2. Use the object. Search (strwhere) method of the layer object. The parameter is the WHERE clause of SQL query. For example:
Set ftrs = lyr. Search ("character_name =" "Beijing """);
Set ftrs = lyrusa. Search ("totpop> 1000000 ")
Note:
1. String plus two double quotes.
2. Add layers to the dataset datasets before you can use the query.
The most convenient method for fuzzy search is to use the second method, for example
Set ftrs = lyr. Search ("character_name like" "% City """);

Ii. How to compress a table in Mapx
In mapx4.51, you can use layerinfo to create a temporary table with a structure and a new table to perform the following operations:
Set lyr = formmain. map1.layers (toolbars. combo1.text)
Set DS = formmain. map1.datasets. Add (6, lyr)
'Obtain the path and name of the compressed table.
Filespec = formmain. map1.layers. Item (toolbars. combo1.text). filespec
Layername = lyr. name' temporarily stores the table in the memory
Layerinfo. type = 6 'milayerinfotypetemp
Layerinfo. addparameter "tablestoragetype", "memtable" 'temporary files are stored on disks or in memory.
Layerinfo. addparameter "name", "lyrpack"
Layerinfo. addparameter "fields", DS. Fields
Layerinfo. addparameter "Features", lyr. allfeatures
Formmain. map1.layers. Add layerinfo, layerpos
Set layerinfo = nothing
'Delete the original table from the map window
Formmain. map1.datasets. Remove (Ds. Name)
Formmain. map1.layers. Remove (lyr. Name)
Formmain. map1.refresh
Set lyr = nothing
Set DS = nothing
Set lyr = formmain. map1.layers ("lyrpack ")
Set DS = formmain. map1.datasets. Add (6, lyr)
'Delete the original table from the disk
Kill filespec

3. How to use custom raster symbols in Mapx
To use custom symbols, you must first set style. symboltype to misymboltypebitmap, and then specify symbolbitmapname as the Raster image name.
The following code demonstrates how to use custom raster symbols in Delphi.
First, call the custom tool to draw points.
Procedure tform1.new1click (Sender: tobject );
Begin
Map1.controlinterface. currenttool: = 111;
End;
The tooluses event is as follows:
Procedure tform1.map1toolused (Sender: tobject; toolnum: smallint; X1, Y1,
X2, Y2, distance: Double; shift, CTRL: wordbool;
VaR enabledefault: wordbool );
VaR
Ssymbol: cmapxstyle;
P: cmapxpoint;
F: cmapxfeature;
Begin
Ssymbol: = costyle. Create;
Ssymbol. symboltype: = 1;
Ssymbol. symbolbitmapsize: = 25;
Please submit the test.bmp file to the MapX "common file path" + "custsymb" path, for example, C: "Program Files" common files "MapInfo shared" Mapx

Common is the default installation path for MapX files}
Ssymbol. symbolbitmapname: = 'test. BMP ';
P: = copoint. Create;
F: = cofeature. Create;
P. Set _ (x1, Y1 );
If toolnum= 111 then begin
F: = map1.controlinterface. featurefactory. createsymbol (p, ssymbol );
Map1.controlinterface. layers. Item (1). addfeature (F, emptyparam );
End;

4. How to use a custom mouse in Mapx
In mapx4.0 and later versions, you can customize the mouse. The procedure is as follows:
Map1.mousepointer = micustomcursor
Map1.mouseicon = "C:" Windows "cursors" globe. Ani"
MapX also provides support for mouse scroll wheels. The attributes are as follows:
Map. mousewheelsupport = mimousewheelnoautoscroll

V. How to set parameters when MapX prints a map?
In the printmap method of MapX: printmap (hdc x, Y, W, h), W, H, X, and Y are measured in himetric, 1 himetric = 0.01mm. Therefore, W

, H multiplied by 100 to mm.
Example in VB:
Private sub command4_click ()
On Error goto errorhandler 'set up error handler.
'Coords must be in himetric
'Print same size as on screen, in upper left of page
Scalemode = 6 'set mode to mm
'There is no printer. startdoc method, it seems it is done
'Implicitly when you use one of the printer. Print Methods
'So we need to print something before we print our map
'To start the page
Printer. currentx = 0
Printer. currenty = 0
Printer. Print ""
Map1.printmap printer. HDC, 0, 0, map1.width * 100 ,_
Map1.height * 100
Printer. Newpage 'send new page.
Printer. enddoc 'printing is finished.
Exit sub
Example in VC
// Map. paperunit Property
// Map. printmap Method
Void csampleprojectview: onprintmap (CDC * PDC, cprintinfo * pinfo ){
Try {
// Get paper width in mm and convert to himetric (100th of A mm)
M_map.setpaperunit (miunitmillimeter );
Double PW = m_map.getmappaperwidth () * 100;
Double pH = m_map.getmappaperheight () * 100;
M_map.printmap (long) PDC-> m_hdc,
Pinfo-> m_rectdra1_left, pinfo-> m_rectdraw.
Top, (long) PW, (long) pH );
} Catch (coledispatchexception * E ){
E-> reporterror ();
E-> Delete ();
} Catch (coleexception * E ){
E-> reporterror ();
E-> Delete ();
}
}

Vi. Example of creating a ranging tool in Mapx
First, create a ranging Tool
Global const calculatedistance = 1
Private sub form_load ()
Map1.createcustomtool (calcilatedistance, mitooltypepoly, microsscursor)
End sub
Private sub distances_click ()
Map1.currenttool = calculatetool
End sub
Then, in the polytoolused event of MapX, the distance is calculated using distance (x1, Y1, X2, Y2) and displayed in the status bar or label.
Private sub map1_polytoolused (byval toolnum as integer, byval flags as long, byval points as object, byval bshift as Boolean,

Byval bctrl as Boolean, enabledefault as Boolean)

Dim dissum as double
Dim DIS as double
Dim N as integer
Dim PTS as new mapxlib. Points
Dim X1 as double, Y1 as double, X2 as double, Y2 as double

Set PTS = points

Dissum = 0
Mdiform1.statusbar1. Panels. Item (3). Text = format (STR (dissum), "#,## 0.000000 ")
Select case flags
Case mipolympus toolbegin
Case mipolympus toolinprogress
If toolnum = calculatedistance then
For I = 1 to PTS. Count-1
X1 = pts. Item (I). x
Y1 = pts. Item (I). Y
X2 = pts. Item (I + 1). x
Y3 = pts. Item (I + 1). Y
Dis = map1.distance (x1, Y1, X2, Y2)
Dissum = dissum + dis
Mdiform1.statusbar1. Panels. Item (3). Text = format (STR (dissum), "#,## 0.000000 ")
Next I
End if
Case mipolympus toolend
End select

7. How to implement automatic screen scrolling in Mapx
MapX supports the mousemove event, which can be used to automatically scroll the screen. The example is as follows:
Private sub map1_mousemove (button as integer, shift as integer, X as single, y as Single)
If map_move = true then
If X> map1.mapscreenwidth-10 then
Map1.centerx = map1.centerx + 0.05
Map1.refresh
Else
If x <10 then
Map1.centerx = map1.centerx- 0.05
Map1.refresh
Else
If y> map1.mapscreenheight-10 then
Map1.centery = map1.centery-0.05
Map1.refresh
Else
If y <10 then
Map1.centery = map1.centery + 0.05
Map1.refresh
End if
End if
End if
End if
End if
End sub

8. How to drag and drop elements in Mapx
The following method moves the selected elements to the click area.
Private sub map1_mousedown (button as integer, shift as integer, X as single, y as Single)
Dim FTR as feature
Dim lyr as Layer
Dim MapX as double
Dim mapy as double
'Convert where the mouse is clicked to the map's current Coordinate System
Map1.convertcoord X, Y, MapX, mapy, miscreentomap
'Iterate through each selected feature in each layer
For each lyr in map1.layers
For each FTR in lyr. Selection

'Change the offset of the feature
FTR. offset MapX-FTR. centerx, mapy-FTR. centery
'Update the feature to make the change permanent
FTR. Update
Next
Next
End sub

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.