代码名称:MapX中紧缩表、使用自定义鼠标、地图打印参数设置、自定义工具画点

收集者:James.Liu

开发环境:VB+ MapX

代码:

在mapx中如何紧缩表
在Mapx4.51下可以使用LayerInfo 的创建带结构的临时表和新表的功能来完成紧缩:
Set lyr = Formmain.Map1.Layers(ToolBars.combo1.Text)
Set ds = Formmain.Map1.Datasets.add(6, lyr) 
'获取被紧缩表的路径及表名
filespec = Formmain.Map1.Layers.Item(ToolBars.combo1.Text).filespec
layername = lyr.Name '将表临时存放于内存 

LayerInfo.Type = 6 'miLayerInfoTypeTemp
LayerInfo.AddParameter "TableStorageType", "MemTable" '临时文件保存在磁盘上还是内存。
LayerInfo.AddParameter "Name", "lyrpack"
LayerInfo.AddParameter "Fields", ds.Fields
LayerInfo.AddParameter "Features", lyr.AllFeatures
Formmain.Map1.Layers.add LayerInfo, LayerPos 
Set LayerInfo = Nothing 
'从地图窗口删除原表
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)
'从磁盘删除原表
Kill filespec 回页首

在mapx中如何使用自定义栅格符号
使用自定义符号首先需要设定style.SymbolType 为miSymbolTypeBitmap,然后指定SymbolBitmapName 为栅格图像名即可。

下面的代码演示了如何在delphi中使用自定义的栅格符号


首先调用自定义工具画点
procedure TForm1.new1Click(Sender: TObject);
begin
map1.ControlInterface.CurrentTool :=111;
end;

在tooluses事件中如下:
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;
{请注意将test.bmp文件考到mapx “共有文件路径”+“\CUSTSYMB”路径下,例如C:\Program Files\Common Files\MapInfo Shared\MapX Common 是 MapX 共有文件的缺省安装路径}
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;
回页首 

在mapx中如何使用自定义鼠标

在mapx4.0,及以上版本中允许用户自定义鼠标。程序如下:
Map1.MousePointer = miCustomCursor
Map1.MouseIcon = "c:\windows\cursors\globe.ani" 

mapx 中还对鼠标滚动轮提供支持,属性如下

Map.MouseWheelSupport=miMousewheelNoAutoScroll 回页首

mapx 打印地图时的参数如何设置
在mapx 的 printmap方法:PrintMap (hDC x, y, w, h)之中,w,h,x,y的单位为himetric,1 himetric=0.01毫米。所以,打印地图时需要将w,h 乘100换算为毫米。

在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


在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_rectDraw.left,pInfo->m_rectDraw.

top,(long)pw,(long)ph);

} catch (COleDispatchException *e) {


e->ReportError();

e->Delete();

} catch (COleException *e) {

e->ReportError();

e->Delete();

}