1 简单的GIS功能
对于地图缩放、平移、选取、标签等比较简单的功能,可以通过设置MapX控件对象的CurrentTool属性方便地获得。如平移功能就可以简单地用以下语句获得:
Map1.CurrentTool = miPanTool (假设MapX控件名字是Map1)
2 对象闪烁功能
很多GIS系统中要用到图形对象的闪烁功能。比如:节点在状态未知时显示灰色,在接受查询时以闪烁以表明状态。这部分功能是借助定时器控件实现的。程序代码主要部分如下:
'记录目前正在处理的节点图标
Dim CurCusSym As New MapXLib.Feature
'两个交替显示的图标
Dim NewStyle As New MapXLib.Style, OldStyle As New MapXLib.Style
'用于更换图标的布尔值
Dim blnold As Boolean
…………
Private Sub Timer1_Timer() (每次定时器间隔时间到时调用此函数)
Set lyr = Map1.Layers.Item(1)
Set FeaFac = Map1.FeatureFactory
With NewStyle
.SymbolType = miSymbolTypeBitmap
.SymbolBitmapSize = 24
.SymbolBitmapTransparent = True
.SymbolBitmapName = "red.BMP" (要显示的第一张图片)
End With
With OldStyle
.SymbolType = miSymbolTypeBitmap
.SymbolBitmapSize = 24
.SymbolBitmapTransparent = True
.SymbolBitmapName = "gray.BMP" (要显示的第二张图片)
End With
Map1.AutoRedraw = False (禁止自动刷新)
If (blnold = True) Then (如果正显示第一张图片,就替换为第二张图片)
CurCusSym.Style = OldStyle
blnold = False
Else
CurCusSym.Style = NewStyle (如果正显示第一张图片,就替换为第二张图片)
blnold = True
End If
CurCusSym.Update (刷新图片)
End Sub
3 增删站点图标功能
在增加、减少、改动节点时会用到该功能。该部分功能是通过一个自定义工具实现的。主要实现代码如下:
'在工程模块中定义增删节点的工具常数
Public Const CreateRTUSymbolTool = 106
Public Const DeleteRTUSymbolTool = 107
'注册工具
Private Sub Form_Load()
…………
Map1.CreateCustomTool CreateRTUSymbolTool, miToolTypePoint, miSizeAllCursor
Map1.CreateCustomTool DeleteRTUSymbolTool, miToolTypePoint, miSizeAllCursor
End Sub
'工具的调用
Private Sub Map1_ToolUsed(ByVal ToolNum As Integer, ByVal X1 As Double, ByVal Y1 As Double, ByVal X2 As Double, ByVal Y2 As Double, ByVal Distance As Double, ByVal Shift As Boolean, ByVal Ctrl As Boolean, EnableDefault As Boolean)
…………
'添加节点图标
If ToolNum = CreateRTUSymbolTool Then
Dim Pnt As New MapXLib.Point
Dim FeaFac As New MapXLib.FeatureFactory
Dim lyr As New MapXLib.Layer
Dim ftr As New MapXLib.Feature
Dim NewStyle As New MapXLib.Style
Set lyr = Map1.Layers.Item(1)
Set FeaFac = Map1.FeatureFactory
'设置节点图标的样式
With NewStyle
.SymbolType = miSymbolTypeBitmap
.SymbolBitmapSize = 24
.SymbolBitmapTransparent = True
.SymbolBitmapName = "gray.BMP"
End With
Map1.AutoRedraw = False '禁止图层自动刷新
lyr.Editable = True '置当前图层为可写状态
'创建点对象
Pnt.Set X1, Y1
Set ftr = FeaFac.CreateSymbol(Pnt, NewStyle) '创建符号
'记录目前正在处理的用户标记
Set CurCusSym = ftr
'添加节点图标进当前图层并刷新图层
lyr.AddFeature ftr
lyr.Refresh
Map1.AutoRedraw = True '恢复图层的自动刷新
lyr.Editable = False
'释放对象
Set Pnt = Nothing
Set FeaFac = Nothing
Set lyr = Nothing
Set ftr = Nothing
End If
'删除节点图标
If ToolNum = DeletePointTool Then
Dim obj As MapXLib.Feature
Dim selectedFtrs As MapXLib.Features
Dim lyr As MapXLib.Layer
Set lyr = Map1.Layers.Item(1)
Set selectedFtrs = lyr.Selection
For Each obj In selectedFtrs
lyr.DeleteFeature (obj)
Next
End If
End Sub
4 注意事项
用于显示的BMP图片必须放在MapX安装目录下的CUSTSYMB子目录下,存为不大于256色的图片,这样才可以用.SymbolBitmapName = "gray.BMP"这样的语句来调用显示。
5 MapX与.NET的结合
由于MapX是一个AvtiveX控件,所以可以被.NET托管使用。但由于.NET对ActiveX控件托管的实现是借助一个类似“壳”的包装对象实现的,而且很多在VB6下面的ActiveX方法不再支持(如默认参数等),将MapX应用到.NET中有一些难度。当然基本功能还是比较容易实现的,如选择工具调用的语句为:axMap1.CurrentTool = MapXLib.ToolConstants.miSelectTool(axMap1为相当于VB6下面的Map1对象)。
--------------------------------------------------
MapX从数据库读取数据形成新图层(C#)
说明: