delphi操作mapx部分技巧

更新时间:2023-10-22 08:56:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Delphi

Mapx

中使用

目录

一.在地图上创建图层 ............................................................................................................. - 1 - 二.在符号图元中使用自定义位图 ......................................................................................... - 1 - 三.屏幕坐标向地图坐标的转换 ............................................................................................. - 2 - 四.查找某一城市 ..................................................................................................................... - 3 - 五. 鼠标点击选中一片区域 ...................................................................................................... - 3 - 六.从数据库绘制MapX地图 ................................................................................................. - 4 - 七.MapX使用数据库数据添加专题图 .................................................................................. - 6 - 八.在mapx中画圆 ................................................................................................................ - 10 - 九.动态加载一个目录下所有图层 ....................................................................................... - 11 -

安装好MapX后,选择Delphi的Component -> Import Active 菜单添加,MapInfo MapX组件。添加完成后,在ActiveX面板上,将会出来一个TMap控件。拖一个TMap控件到工程中改名为MainMap,这样就产生了一个TMap的对象。

一.在地图上创建图层

使用Layers属性的CreateLayer函数来创建一个图层

MainMap.Layers.CreateLayer(Name,[FileSpec],[Position],[KeyLength],[CoordSys]); 参数说明:

Name: 指定图层的名称

FileSpec: 所创建图层的路径名。如'c:\\china.tab'

Position: 它在图层列表中的初始位置.(其实就是在图层列表中的一个序列号) CoorSys: 指定存储新图层的坐标系。 附:图层类型参数: miLayerTypeNormal miLayerTypeRaster miLayerTypeSeamless miLayerTypeUnknown miLayerTypeUserDraw miLayerTypeDrilldown

FeatureFactory 对象的方法使您可以创建新的地图图元,也可通过对现有图元执行操作(例如缓冲区)来创建图元。以下是 FeatureFactory 对象的方法: BufferFeatures CombineFeatures CreateArc

CreateCircularRegion CreateEllipticalRegion CreateLine CreateRegion CreateSymbol CreateText EraseFeature IntersectFeatures IntersectionPoints IntersectionTest

二.在符号图元中使用自定义位图

定义一个cs: CMapXStyle 做为图元的样式属性设置

- 1 - - 1 -

cs := coStyle.Create;

cs.SymbolType := miSymbolTypeBitmap; cs.SymbolBitmapName := 'HOUS2-32.BMP';

cs.SymbolBitmapSize := 40;

注意: 自定义的位图一定要放到C:\\Program Files\\Common Files\\MapInfo Shared\\MapX Common\\CUSTSYMB 下,这是MapInfo安装的黩认共享路径。

三.屏幕坐标向地图坐标的转换

procedure TMapForm.Map1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var

lon, lat: Double;

singleX, singleY: Single; fs: CMapXFeatures; pnt: CMapXPoint; name: String;

begin

if Map1.CurrentTool = miArrowTool then begin

pnt := CoPoint.Create; singleX := X;

singleY := Y;

Map1.ConvertCoord(singleX, singleY, lon, lat, miScreenToMap); pnt.Set_(lon, lat);

fs := Map1.Layers.

Item('US Top 20 Cities').SearchAtPoint(pnt); if fs.Count > 0 then

begin

name := fs.Item(1).Name;

Application.MessageBox(PChar(name),'Info',0) end

else

Application.MessageBox('Nothing found', 'Nope', 0); end; end;

备注:

获取一个图元时最好用Layer.GetFeatureByID(FeatureKey);

- 2 - - 2 -

四.查找某一城市

procedure TForm2.SearchForCapital(Capital: String); var

FoundF:FindFeature; //在小城市层查 begin

FoundF := Map1.Layers.Item['US Minor Cities'].Find.Search(Capital, EmptyParam);

//在us minor cities层中查找capital if (FoundF.FindRC mod 10)=1 then begin

Map1.Layers.Item['US Minor Cities'].Selection.Replace(FoundF); Map1.Zoom := 60; //60英里 Map1.CenterX := FoundF.CenterX; Map1.CenterY := FoundF.CenterY; end else

Application.MessageBox('No exact match found.','Nope',0); end;

五. 鼠标点击选中一片区域

procedure TForm2.Map1ToolUsed(ASender: TObject; ToolNum: Smallint; X1, Y1,

X2, Y2, Distance: Double; Shift, Ctrl: WordBool; var EnableDefault: WordBool); var

ftrs:Features;// CMapXFeatures;

newJersey:FindFeature;// CMapXFindFeature; usaLayer:Layer;// CMapXLayer; pt: Point;

- 3 -

- 3 -

本文来源:https://www.bwwdw.com/article/3r7f.html

Top