首页 delphi操作mapx部分技巧

delphi操作mapx部分技巧

举报
开通vip

delphi操作mapx部分技巧Delphi中使用Mapx目录-1-一.在地图上创建图层-1-二.在符号图元中使用自定义位图-2-三.屏幕坐标向地图坐标的转换-3-四.查找某一城市-3-五.鼠标点击选中一片区域-4-六.从数据库绘制MapX地图-6-七.MapX使用数据库数据添加专题图-10-八.在mapx中画圆-11-九.动态加载一个目录下所有图层安装好MapX后,选择Delphi的Component->ImportActive菜单添加,MapInfoMapX组件。添加完成后,在ActiveX面板上,将会出来一个TMap控件。拖一个TMa...

delphi操作mapx部分技巧
Delphi中使用Mapx目录-1-一.在地图上创建图层-1-二.在符号图元中使用自定义位图-2-三.屏幕坐标向地图坐标的转换-3-四.查找某一城市-3-五.鼠标点击选中一片区域-4-六.从数据库绘制MapX地图-6-七.MapX使用数据库数据添加专 快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题 图-10-八.在mapx中画圆-11-九.动态加载一个目录下所有图层安装好MapX后,选择Delphi的Component->ImportActive菜单添加,MapInfoMapX组件。添加完成后,在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     miLayerTypeDrilldownFeatureFactory对象的方法使您可以创建新的地图图元,也可通过对现有图元执行操作(例如缓冲区)来创建图元。以下是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:\ProgramFiles\CommonFiles\MapInfoShared\MapX   Common\CUSTSYMB下,这是MapInfo安装的黩认共享路径。三.屏幕坐标向地图坐标的转换procedureTMapForm.Map1MouseUp(Sender:TObject; Button:TMouseButton;Shift:TShiftState;X,Y:Integer);var lon,lat:Double; singleX,singleY:Single; fs:CMapXFeatures; pnt:CMapXPoint; name:String;begin ifMap1.CurrentTool=miArrowToolthen begin pnt:=CoPoint.Create; singleX:=X; singleY:=Y; Map1.ConvertCoord(singleX,singleY,lon,  lat,miScreenToMap); pnt.Set_(lon,lat); fs:=Map1.Layers.  Item('USTop20Cities').SearchAtPoint(pnt); iffs.Count>0then begin  name:=fs.Item(1).Name;  Application.MessageBox(PChar(name),'Info',0) end else  Application.MessageBox('Nothingfound','Nope',0); end;end;备注:    获取一个图元时最好用Layer.GetFeatureByID(FeatureKey);四.查找某一城市procedureTForm2.SearchForCapital(Capital:String);varFoundF:FindFeature;//在小城市层查beginFoundF:=Map1.Layers.Item['USMinorCities'].Find.Search(Capital,EmptyParam);//在usminorcities层中查找capitalif(FoundF.FindRCmod10)=1thenbeginMap1.Layers.Item['USMinorCities'].Selection.Replace(FoundF);Map1.Zoom:=60;//60英里Map1.CenterX:=FoundF.CenterX;Map1.CenterY:=FoundF.CenterY;endelseApplication.MessageBox('Noexactmatchfound.','Nope',0);end;五.鼠标点击选中一片区域procedureTForm2.Map1ToolUsed(ASender:TObject;ToolNum:Smallint;X1,Y1,X2,Y2,Distance:Double;Shift,Ctrl:WordBool;varEnableDefault:WordBool);varftrs:Features;//CMapXFeatures;newJersey:FindFeature;//CMapXFindFeature;usaLayer:Layer;//CMapXLayer;pt:Point;beginifToolNum=miSelectToolthenbeginpt:=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;六.从数据库绘制MapX地图这里提供的是一种更为高效的从数据库绘制MapX地图的方法,我在数据库中建立了如下的数据表:表名称:XunitID:字符串//用于唯一标识各个图元,也可以是数字类型的NAME:字符串//图元的名称X:浮点数//图元横坐标Y:浮点数//图元纵坐标 代码清单://aqXUnit是一个TADOQuery,其中SQL语句为“SELECT*FROMXUNIT”。procedureTfrmMain.DrawLayerFromDB;varoBLayer:BindLayer;SearchLayer:Layer;ds:Dataset;begin//使用这个过程必须保证aqXUnit表已经打开!ifnotaqXUnit.ActivethenbeginGiveMsg('系统基础表没有打开!');//调用自定义提示方法exit;end;oBLayer:=coBindLayer.Create;oBLayer.LayerName:='ARTEMIS';oBLayer.LayerType:=miBindLayerTypeXY;//必须使用这个参数才能绑定XY坐标oBLayer.RefColumn1:='X';//第一个参数必须指定为横坐标oBLayer.RefColumn2:='Y';//纵坐标//添加数据集ds:=mapMain.Datasets.Add(12,//数据集类型,这是miDataSetADO,即ADO专用的aqXUnit.Recordset,//使用这个方法获得ADO中的_Recordset类型'DS_SK',//数据集名称'ID',//传入的是Xunit表中的字段ID的名称EmptyParam,oBLayer,//BindLayerEmptyParam,EmptyParam);//下边将设置新图层的各项属性searchLayer:=mapMain.Layers.Item('ARTEMIS');//字体颜色searchLayer.LabelProperties.Style.TextFontColor:=miColorPurple;searchLayer.LabelProperties.Style.TextFontHalo:=true;searchLayer.LabelProperties.Style.TextFontBackColor:=miColorWhite;//设置图元显示的标签searchLayer.LabelProperties.Dataset:=ds;searchLayer.LabelProperties.DataField:=ds.Fields.Item('NAME');searchLayer.LabelProperties.LabelZoom:=true;//设置图层缩放比例范围searchLayer.ZoomMin:=0;searchLayer.ZoomMax:=200;searchLayer.ZoomLayer:=true;//设置标签缩放比例范围searchLayer.LabelProperties.LabelZoomMin:=0;searchLayer.LabelProperties.LabelZoomMax:=200;searchLayer.LabelProperties.LabelZoom:=true;//自动标记图元searchLayer.AutoLabel:=true;end; 七.MapX使用数据库数据添加专题图  OBJECT.Add([Type],[Field],[Name],[ComputeTheme]) OBJECTRepresentsaThemesobject.TypeSpecifiesthetypeofthematicmaptocreate.ThistakesaThemeTypeConstantsvalue.Thisisanoptionalparameter,andifnotspecified(orspecifiedasmiThemeAuto),MapXwillattempttochooseagooddefaultbasedonthenumberoffieldspassedinaswellaswhatotherthemetypesarealreadybeingdisplayed.IfMapXcannotchooseadefaultthemetype,anerrorisgenerated.Field(s)Specifiesthefieldorfieldstothematicallymap.Afieldcanbespecifiedbyname,index,orbyaFieldobject.Ifyouarecreatingathemeusingmultiplevariables(suchasabarchartorpiechart),passinaFieldscollectionoranarrayoffieldnames,indexes,orFieldobjects.Thisisanoptionalparameter,andifnotspecified,MapXusesthefirstnumericfieldoftheDataset.NameSpecifiesthenameofthethematicmap.ThisisaStringparameter.Thisisanoptionalparameter,andifnotspecified,MapXgeneratesanamesuchasStatesBySales.ComputeThemeBoolean.ThedefaultvalueisTruewhichwillcalculatethethemefromthetabledata.IfthevalueissettoFalseaninvisiblethemeobjectwillbecreatedwith10rangesforIndividualValuethemesand5rangesforRangedthemes.YoucanthenmanuallysettheminimumandmaximumvaluestodefinethethemewithTheme.DataMinandTheme.DataMax.Forrangedthemesyoucanmanuallysetthethemerangesorcalculateequalsizerangesdeterminedbytheminimum(Theme.DataMin)andmaximum(Theme.DataMax)values. 关于专题图的风格共有以下几种:miThemeRanged=0miThemeBarChart=1miThemePieChart=2miThemeGradSymbol=3miThemeDotDensity=4miThemeIndividualValue=5miThemeAuto=6miThemeNone=9 下面是我写的部分代码:unitMain;interfaceusesWindows,Messages,{略去一部分}SysUtils,Variants,Classes; typeTfrmMain=class(TForm)mapMain:TMap;{地图控件}private{Privatedeclarations}ThemesList:TStringList;{用来保存多个专题图的名称列表}public{Publicdeclarations}procedureToAddThemes(style:integer;TheName:string);{添加专题图}procedureToDeleteThemes;{删除专题图}end; varfrmMain:TfrmMain; implementation {$R*.dfm} {略去其他功能代码} {添加专题图,参数style表示专题图风格,TheName表示图例标题}procedureTfrmMain.ToAddThemes(style:integer;TheName:string);functionDefaultName:string;{用来生成一唯一的名称}begin{我用的方法是取一个当前时间,两次调用本函数的时间间隔应该不会少于0.5秒,所以这个方法在这个项目中可以取得唯一的名称}Result:='YYT'+FormatDateTime('YYYYMMDDHHNNSSzzz',now);end;varflds:arrayofstring;{字段列表}oBLayer:BindLayer;{绑定图层}ds:Dataset;{MapX数据集}i:integer;{循环变量}thm:theme;{MapX专题图}str:string;{用于保存字符串}begin{aqThemes可以是一个ADOQuery或者ADOTable,我使用的是ADOQuery。在这个ADOQuery中前四个字段分别是:ID(唯一的数字或者字符串,一般为编号),NAME(字符串,要素的标签),X(浮点数,要素的经度或者横坐标),Y(浮点数,要素的纬度或者纵坐标)。后面的其它字段都是数字类型,用来表示相关的数据。}ifnotaqThemes.ActivethenbegindmData.GiveMsg('系统基础表没有打开!');exit;end;try{取一个唯一的名字,}str:=DefaultName; {设置绑定图层的属性}oBLayer:=coBindLayer.Create;progress.StepPlus(2);oBLayer.LayerName:=str;oBLayer.LayerType:=miBindLayerTypeXY;oBLayer.RefColumn1:='X';oBLayer.RefColumn2:='Y';ds:=mapMain.Datasets.Add(12,aqThemes.Recordset,str,'ID',EmptyParam,oBLayer,EmptyParam,EmptyParam);{组织专题图现实的数据字段,存储在字符串数组中}SetLength(flds,aqThemes.Fields.Count-3);fori:=3toaqThemes.Fields.Count-1dobeginflds[i-3]:=aqThemes.Fields.Fields[i].FieldName;end;{实际添加专题图的过程}thm:=ds.Themes.Add(style,flds,DefaultName,EmptyParam);{设置专题图图例标题}thm.Legend.Title:=TheName;{ 记录 混凝土 养护记录下载土方回填监理旁站记录免费下载集备记录下载集备记录下载集备记录下载 新添加的专题图名称}ThemesList.Add(str);{btnDeleteThemes是一个在本窗口上的按钮,用来删除专题图,添加专题图后就将他显示出来,如果删除了全部专题图就将他隐藏}btnDeleteThemes.Visible:=true;exceptGiveMsg('创建专题图失败!');{自定义过程,给出出错提示}end;end;{删除专题图,我采用的方法是删除所有专题图}procedureTfrmMain.ToDeleteThemes;vari:integer;{循环变量}beginfori:=0toThemesList.Count-1do{循环所有添加了的专题图}begin{删除数据集}mapMain.Datasets.Remove(ThemesList.Strings[i]);{删除专题图}mapMain.Layers.Remove(ThemesList.Strings[i]);{如果只想删除某一个专题图,不用循环就行了}end;{此时已经没有专题图了,将删除专题图按钮隐藏}btnDeleteThemes.Visible:=false;{清除专题图名称列表}ThemesList.Clear;end; //... end.八.在mapx中画圆varStyle:CMapXStyle;f:CMapXFeature;pt:Point;beginMap1.ControlInterface.Layers.CreateLayer('temp',emptyparam,1,emptyparam,emptyparam);Style:=Map1.DefaultStyle.Clone;Style.RegionPattern:=miPatternNoFill;Style.RegionColor:=255;Style.RegionBorderColor:=125;Style.RegionBorderWidth:=2;Style.RegionBorderStyle:=1;pt:=CoPoint.Create;pt.Set_(122.8,40.8);map1.Zoom:=0.5;map1.CenterX:=pt.X;map1.CenterY:=pt.Y;f:=Map1.FeatureFactory.CreateCircularRegion(miCircleTypeMap,pt,0.2,miUnitKilometer,emptyParam,Style);Map1.Layers.Item('Temp').AddFeature(f,EmptyParam);end;九.动态加载一个目录下所有图层varpath,fileName:string;myLayerInfo:LayerInfo;hFindFile:Cardinal;FindFileData:WIN32_FIND_DATA;beginpath:=ExtractFilePath(Application.ExeName)+'map\';ChDir(path);hFindFile:=FindFirstFile('*.TAB',FindFileData);//找到第一个扩展名为tab的文件ifhFindFile<>windows.INVALID_HANDLE_VALUEthenbeginrepeatfilename:=FindFileData.cFileName;{在这里可以实现对当前文件的处理,比如文件的解密等功能}trymyLayerInfo:=CoLayerInfo.Create;myLayerInfo.Type_:=miLayerInfoTypeTab;myLayerInfo.AddParameter('FileSpec',path+filename);myLayerInfo.AddParameter('Name',ExtractFileName(fileName));Map1.Layers.Add(myLayerInfo,EmptyParam);//加载图层exceptend;until(FindNextFile(hFindFile,FindFileData)=false);WindowS.FindClose(hFindFile);;end;end;PAGE
本文档为【delphi操作mapx部分技巧】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_698138
暂无简介~
格式:doc
大小:115KB
软件:Word
页数:14
分类:互联网
上传时间:2012-02-03
浏览量:30