一、安装好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 做为图元的样式属性
设置
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);
八.查找某一城市
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;
begin
if ToolNum=miSelectTool then
begin
pt := CoPoint.Create;
pt.Set_(X1, Y1);
usaLayer := Map1.Layers.Item['USA'];
newJersey := usaLayer.Find.Search('NY', EmptyParam);
//找到ny500英里之内的区域
ftrs := usaLayer.SearchWithinDistance(pt, 500, miUnitMile, miSearchTypePartiallyWithin);
ftrs.Common(usaLayer.SearchWithinDistance(newJersey, 500, miUnitMile, miSearchTypePartiallyWithin));
usaLayer.Selection.Replace(ftrs);//选中
end;
end;