二、创建地图对象
必要:创建地图对象,必须使用FeatureFactory对象 1、 创建一个点对象 点对象有一个坐标点(X,Y),点对象变量是Point类型,点对象的样式(Style)是符号 样式。 Dim Pnt AS MapXLib.Point Dim FeaFac AS MapXLib.FeatureFactory Dim Lyr AS MapXLib.Layer Dim Ftr AS MapXLib.Feature Dim NewStyle AS MapXLib.Style
‘绑定 SET Lyr=MainMap.Layers.Item(LayerName) SET FeaFac=mainmap.featurefactory ‘设置点对象样式 With NewStyle .SymbolType = miSymbolTypeBitmap .SymbolBitmapSize = 24 .SymbolBitmapTransparent = False .SymbolBitmapName = YIEL2-32.BMP End With Mainmap.AutoRedraw=False ‘禁止自动刷新 Lyr.Editable=True ‘置当前图层为可写状态 ‘创建点对象 pnt.set X1,Y1 ‘添加进当前图层 Set Ftr=FeaFac. CreateSymbol (Pnt,Newstyle) ‘创建符号 ‘Set Ftr=FeaFac. CreateSymbol (Pnt,MainMap.DefaultStyle) ‘添加 Lyr.AddFeature Ftr Lyr.Refresh Mainmap.AutoRedraw=True Lyr.Editable=False ‘释放 SET Pnt = Nothing SET FeaFac = Nothing SET Lyr = Nothing SET Ftr = Nothing ‘以上代码放在MapX的ToolUsed事件下
单独修改某个图元的样式:SET Ftr.Style=NewStyle,再用Update 即可 2、 创建一个线矩形 Dim Pnts AS MapXLib.Points
With NewStyle .LineColor=Rgb(0, 0,255) End With ‘第一个点 Pnt.Set X1,Y1 Pnts.add Pnt ‘第二个点 Pnt.Set X2,Y1 Pnts.add Pnt ‘第三个点 Pnt.Set X2,Y2 Pnts.add Pnt ‘第四个点 Pnt.Set X1,Y2 Pnts.add Pnt ‘第五个点 Pnt.Set X1,Y1 Pnts.add Pnt
‘创建线矩形 SET Ftr=FeaFac.CreateLine(Pnts,NewStyle) Lyr.AddFeature Ftr Lyr.Refresh
3、 上面创建对象中存在的问题:并未对其数据数据进行赋值 创建对象的同时创建其数据集合 Dim Pnt AS MapXLib.Point Dim FeaFac AS MapXLib.FeatureFactory Dim Lyr AS MapXLib.Layer Dim Ftr AS MapXLib.Feature Dim NewStyle AS MapXLib.Style Dim ds AS MapXLib.Dataset Dim Flds AS MapXLib.Fields
‘绑定 SET Lyr=MainMap.Layers.Item(LayerName) SET ds=Lyr.Datasets.Item(1) Set Flds=ds.Fields SET FeaFac=mainmap.featurefactory ‘设置点对象样式 With NewStyle .SymbolType = miSymbolTypeBitmap .SymbolBitmapSize = 24 .SymbolBitmapTransparent = False .SymbolBitmapName = YIEL2-32.BMP End With Mainmap.AutoRedraw=False ‘禁止自动刷新 Lyr.Editable=True ‘置当前图层为可写状态 ‘创建点对象 pnt.set X1,Y1 ‘创建图形 Set Ftr=FeaFac. CreateSymbol (Pnt,Newstyle) ‘创建符号 ‘Set Ftr=FeaFac. CreateSymbol (Pnt,MainMap.DefaultStyle) ‘设置属性 For I=1 to Flds.Count Lyr.KeyFields=Flds.Item(i).Name Ftr.KeyValue=ValueStr(I) ‘这里并没有对字段类型进行判断 Next ‘另外一种方法:使用RowValues和RowValue对象 ‘添加 Lyr.AddFeature Ftr Lyr.Refresh Mainmap.AutoRedraw=True Lyr.Editable=False ‘释放 SET Pnt = Nothing SET FeaFac = Nothing SET Lyr = Nothing SET Ftr = Nothing
SET ds = Nothing SET Flds = Nothing 4、 创建表 (1) 临时表: A、用MainMap.Layers.CreateLayer方法创建临时表。但这个临时表只有一个字段:GeoNa me( Char 24)。程序运行过程中该表存放位置为系统临时文件夹下 B、使用LayerInfo对象创建临时表,可以指定字段。示例:
Dim Lyr As MapXLib.Layer Dim LayerInfo As New MapXLib.LayerInfo Dim Flds As New MapXLib.Fields ‘字段定义 Flds.AddStringField ID, 12 Flds.AddStringField Name, 50 Flds.AddNumericField Deptch, 12, 2 Flds.AddIntegerField Length ´ LayerInfo.Type = miLayerInfoTypeTemp LayerInfo.AddParameter FileSpec, FileName LayerInfo.AddParameter NAME, LayerName LayerInfo.AddParameter Fields, Flds Set Lyr = MainMap.Layers.Add(LayerInfo, 1) Set Lyr = Nothing Set LayerInfo = Nothing
(2) 创建永久表 Dim Lyr As MapXLib.Layer Dim LayerInfo As New MapXLib.LayerInfo Dim Flds As New MapXLib.Fields Flds.AddStringField ID, 12 Flds.AddStringField Name, 50 Flds.AddNumericField Deptch, 12, 2 Flds.AddIntegerField Length ´ LayerInfo.Type = miLayerInfoTypeNewTable LayerInfo.AddParameter FileSpec, FilePath + + FileName LayerInfo.AddParameter NAME, LayerName LayerInfo.AddParameter Fields, Flds Set Lyr = MainMap.Layers.Add(LayerInfo, 1) Set Lyr = Nothing Set LayerInfo = Nothing
(责任编辑:admin) |