飞蝗芜湖什么意思:基于Geomedia Professional平台的GIS开发(三)

来源:百度文库 编辑:九乡新闻网 时间:2024/05/01 02:38:53
基于Geomedia Professional平台的GIS开发(三) ......................................................................................................................... 发布时间:2006-1-20 16:05:39     c)       GetLegendEntry函数

Public Function GetLegendEntry(objRS As GRecordset) As RecordLegendEntry
'***********************************************************
    '功能描述:建立用来显示图形的图例
    '输入参数:
        'objRs:Grecordset 类型
    '输出:
        '返回一个recordLegendEntry
'****************************************************
    On Error GoTo errorhandler
    '建立由该函数返回的RecordLegendEntry
Set GetLegendEntry = CreateObject("GeoMedia.RecordLegendEntry")
'先由输入记录集的扩展属性集来得到用来显示地图的图形字段名,如果不能得到'就遍历States表中的每一个字段来得到图形字段名
    Dim objExt As Object
Set objExt = objRS.GetExtension("ExtendedPropertySet")
GetLegendEntry.GeometryFieldName=_
objExt.GetValue("PrimaryGeometryFieldName")
    If GetLegendEntry.GeometryFieldName = "" Then
        Dim objField As GField
        For Each objField In objRS.GFields
            If objField.Type = gdbSpatial Or objField.Type = gdbGraphic Then               GetLegendEntry.GeometryFieldName = objField.Name
                Exit For
            End If
        Next objField
        Set objField = Nothing
End If
    '将记录集的名称作为图例的标题
GetLegendEntry.Title = objExt.GetValue("Name")
'设置图例的显示格式。由于已知States实体类为面状实体,所以在此直接设置'RecordLegendEntry的显示格式。如果实体类型未知,则需要用'objExt.GetValue("GeometryType")来得到实体类型。
Dim objStyle As Object
Set objStyle = CreateObject("GeoMedia.AreaStyle")
objStyle.BoundaryOn = True
With objStyle.Boundary
    .StyleUnits = gmsStyleUnitsPaper
    .Mode = gmsLinearModeShowBackground
    .Color = RGB(0, 0, 0)
    .Width = 10
    .BackStyle = 0
End With
'返回通过CssTransformPipe将图形转换到MapView坐标系的记录集,并将此记
'录集作为图例的记录集
    Dim objCSSPipe As New CSSTransformPipe
    Set objCSSPipe.InputRecordset = objRS
    Set objCSSPipe.CoordSystemsMgr = frmMap.ocxMapView.CoordSystemsMgr
    objCSSPipe.InputGeometryFieldName = GetLegendEntry.GeometryFieldName
    objCSSPipe.OutputCSGUID= _
frmMap.ocxMapView.CoordSystemsMgr.CoordSystem.Guid
Set GetLegendEntry.Recordset = objCSSPipe.OutputRecordset
'将所用的对象设为Nothing,释放所占用的内存
    Set objExt = Nothing
    Set objCSSPipe = Nothing
    Exit Function
  errorhandler:
    MsgBox Err.Description, vbOKOnly + vbExclamation, "GetLegendEntry Error"
    On Error Resume Next
    Set objExt = Nothing
    Set objCSSPipe = Nothing
End Function

d)       DisplayTheLegendEntry过程
Public Sub DisplayTheLegendEntry(objLE As RecordLegendEntry)
'**********************************************************
'功能描述:显示地图
'输入参数:objLE-RecordLegendEntry类型
'**********************************************************
On Error GoTo errorhandler
    If Not (objLE Is Nothing) Then
        Dim objLegend As Legend
        Set objLegend = ocxMapView.Legend
        If objLE.ValidateSource Then
            ' ---------------------------------------------
            If objLegend.LegendEntries.Count = 0 Then
objLegend.LegendEntries.Append objLE
                objLE.LoadData
                frmMap.ocxMapView.Fit
            Else
                objLegend.LegendEntries.Append objLE, 1
                objLE.LoadData
            End If
'----------------------------------------------------------
frmMap.ocxMapView.Refresh True
        End If
        Set objLegend = Nothing
    End If
    Exit Sub
errorhandler:
    MsgBox Err.Description, vbOKOnly + vbExclamation, "DisplayTheLegendEntry Error"
    On Error Resume Next
    Set objLegend = Nothing
End Sub

    到此,显示一幅地图的过程就介绍完了,显示的地图如下图:


这里显示的地图是矢量图形,你可以对地图做你所需要的操作。比如说放大、缩小、漫游、鹰眼、图属互查、空间查询和分析、图形和属性数据的编辑等等。但是对地图的这些操作都离不开一个最基本的操作-鼠标操作。在Geomedia中是如何对地图响应鼠标事件的呢?你需要针对上面已介绍的实例做如下几步的扩展:

1)       在VB的Project->Components里选择如下的控件:

Intergraph Geomedia Event Control 5.0(事件响应控件)

将事件控件添加到frmMap窗体上,命名为ocxEventControl。

2)       将EventServer(作用是监听发生在MapView的鼠标和键盘操作,并且用事件控件来处理它们)和显示地图的MapView控件联系起来。为此你需要声明一个EventServer类型的对象,该对象的有效范围是整个frmMap窗体。

    具体操作如下:

a)       在VB的General添加如下代码:

Dim objEventServer As New EventServer

b)       在frmMap窗体的Form_Load事件(必须先于鼠标事件发生前)添加如下代码:

ocxEventControl.AddMapView ocxMapView.Dispatch, objEventServer

3)       现在你就可以在ocxEventControl的鼠标和键盘事件中添加代码来响应在MapView上执行的相应操作了。

5.结语

    Geomedia Professional这个GIS系统的二次开发平台代表着GIS技术的发展方向。其先进的数据库管理方式——图形和属性数据统一存储,先进的开发方式——组件式开发,使开发变得更加容易。它提供了大量的对象,灵活运用这些对象可以解决许多比较复杂的问题,开发出非常专业的GIS系统来。