MapXtreme开发经验分享-实现鹰眼

由于MapXtreme没有提供鹰眼控件,需要自己来写。实现鹰眼有两个步骤:

1)在地图的视图改变的时候根据地图当前的边距生成一个矩形框,然后把这个矩形框绘制到鹰眼窗口上。

2)根据用户在鹰眼窗口上点击的位置,同步显示地图窗口对应的位置。

 

VB.NET代码如下:

 

    ' 更新鹰眼图
    Private Sub UpdateEyeMap()
        Try
            Dim tblRect As Table
            tblRect = Session.Current.Catalog.GetTable("TempRect")
            If Not tblRect Is Nothing Then
                tblRect.Close()
            End If

            Dim tblInfo As TableInfo
            tblInfo = TableInfoFactory.CreateTemp("TempRect")
            Dim tblSessionInfo As TableSessionInfo = New TableSessionInfo()

            tblRect = Session.Current.Catalog.CreateTable(tblInfo, tblSessionInfo)
            Dim feaLayer As FeatureLayer = New FeatureLayer(tblRect)
            MapControl_EagleEye.Map.Layers.Add(feaLayer)

            '实时在鹰眼临时表图上画矩形
            tblRect = Session.Current.Catalog.GetTable("TempRect")
            CType(tblRect, ITableFeatureCollection).Clear()

            '设置矩形的样式
            Dim rect As MapInfo.Geometry.DRect = MapControl1.Map.Bounds
            Dim feageo As FeatureGeometry = New MapInfo.Geometry.Rectangle(MapControl1.Map.GetDisplayCoordSys(), rect)
            Dim simLineStyle As SimpleLineStyle = New SimpleLineStyle(New LineWidth(2, MapInfo.Styles.LineWidthUnit.Point), 2, System.Drawing.Color.Red)
            Dim simInterior As SimpleInterior = New SimpleInterior(9, System.Drawing.Color.Gray, System.Drawing.Color.Green, True)
            Dim comStyle As CompositeStyle = New CompositeStyle(New AreaStyle(simLineStyle, simInterior), Nothing, Nothing, Nothing)

            '将矩形插入到图层中
            Dim fea As Feature = New Feature(feageo, comStyle)
            tblRect.InsertFeature(fea)

            '重新定位鹰眼图的中心
            MapControl_EagleEye.Map.Center = Map.Center
            MapControl_EagleEye.Map.Layers("TempRect").Invalidate()

        Catch ex As Exception
            MessageBox.Show("鹰眼显示错误:" + ex.Message)
        End Try
    End Sub

 

    Private Sub Map_ViewChanged(ByVal sender As System.Object, ByVal e As MapInfo.Mapping.ViewChangedEventArgs)
        UpdateEyeMap()
    End Sub

 

 


    Private Sub MapControl_EagleEye_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MapControl_EagleEye.Click
       
        Dim DisplayPoint As System.Drawing.PointF = New PointF(CType(e, System.Windows.Forms.MouseEventArgs).X, CType(e, System.Windows.Forms.MouseEventArgs).Y)
        Dim MapPoint As New MapInfo.Geometry.DPoint()
        Dim converter As MapInfo.Geometry.DisplayTransform = Me.MapControl_EagleEye.Map.DisplayTransform
        converter.FromDisplay(DisplayPoint, MapPoint)
        Map.Center = MapPoint
    End Sub

posted @ 2012-08-30 21:19  雪藩  阅读(153)  评论(0编辑  收藏  举报