ArcEngine的一个简单鹰眼

首先,添加两个MapControl,主图命名为mapMain,鹰眼图命名为mapEye

 

Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Display

 

Public Class Form1

 

    Private EyeRect As IEnvelope       '鹰眼矩形框范围
    Private EyeSym As ISimpleFillSymbol      ‘鹰眼矩形框符号

 

     ’得到鹰眼矩形框范围

    Private Function GetEyeRect() As IEnvelope

        Dim pEnvMainFull As IEnvelope
        pEnvMainFull = mapMain.FullExtent
        Dim pEnvMainExt As IEnvelope
        pEnvMainExt = mapMain.Extent

        Dim pEnvEyeFull As IEnvelope
        pEnvEyeFull = mapEye.FullExtent
        Dim pEnvEyeExt As IEnvelope
        pEnvEyeExt = New Envelope

        pEnvEyeExt.XMin = pEnvEyeFull.XMin + (pEnvMainExt.XMin - pEnvMainFull.XMin) / pEnvMainFull.Width * pEnvEyeFull.Width
        pEnvEyeExt.XMax = pEnvEyeFull.XMax - (pEnvMainFull.XMax - pEnvMainExt.XMax) / pEnvMainFull.Width * pEnvEyeFull.Width
        pEnvEyeExt.YMin = pEnvEyeFull.YMin + (pEnvMainExt.YMin - pEnvMainFull.YMin) / pEnvMainFull.Height * pEnvEyeFull.Height
        pEnvEyeExt.YMax = pEnvEyeFull.YMax - (pEnvMainFull.YMax - pEnvMainExt.YMax) / pEnvMainFull.Height * pEnvEyeFull.Height

        GetEyeRect = pEnvEyeExt

    End Function

 

    ‘得到RGB颜色

    Private Function GetRGBColor(ByVal pRed As Long, ByVal pGreen As Long, ByVal pBlue As Long) As IRgbColor

        Dim pRGB As IRgbColor
        pRGB = New RgbColor

        pRGB.Red = pRed
        pRGB.Green = pGreen
        pRGB.Blue = pBlue
        pRGB.UseWindowsDithering = True

        GetRGBColor = pRGB

    End Function

 

     ’得到鹰眼矩形框符号

    Private Function GetEyeSym() As ISimpleFillSymbol

        Dim pSym As ISimpleFillSymbol
        pSym = New SimpleFillSymbol

        Dim pLnSym As ISimpleLineSymbol
        pLnSym = New SimpleLineSymbol
        pLnSym.Color = Me.GetRGBColor(255, 0, 0)
        pLnSym.Style = esriSimpleLineStyle.esriSLSSolid
        pLnSym.Width = 2

        pSym.Color = Me.GetRGBColor(255, 0, 0)
        pSym.Style = esriSimpleFillStyle.esriSFSBackwardDiagonal
        pSym.Outline = pLnSym

        GetEyeSym = pSym

    End Function

 

    ‘mapEye.Refresh()事件激活了mapEye的OnAfterDraw事件 -> 开始绘制鹰眼矩形框

    Private Sub mapEye_OnAfterDraw(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnAfterDrawEvent) Handles mapEye.OnAfterDraw

        EyeRect = GetEyeRect()
        EyeSym = GetEyeSym()

        If Not EyeRect Is Nothing And Not EyeSym Is Nothing Then
            mapEye.DrawShape(EyeRect, EyeSym)
        End If
    End Sub

 

     '在主图(mapMain)上进行操作(放大,缩小,平抑等),激活了mapMain_OnAfterScreenDraw事件

    Private Sub mapMain_OnAfterScreenDraw(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnAfterScreenDrawEvent) Handles mapMain.OnAfterScreenDraw

        mapEye.Refresh()

    End Sub

 

End Class

 

在为MapControl添加事件时,我发现了三个事件:OnAfterDrawOnAfterScreenDraw,OnBeforeScreenDraw ;

                                                                经过调试,我发现三者的执行顺序是 OnBeforeScreenDraw -> OnAfterDraw -> OnAfterScreenDraw

                                                                OnBeforeScreenDraw 意思还比较好理解,意为“执行屏幕绘制钱”,OnAfterDrawOnAfterScreenDraw就有点混淆了

于是,我进行了一些调整和实验,把 mapEye.Refresh() 放在了 mapMain_OnAfterDraw 事件中,结果程序顺利运行;

                                          把 mapEye_OnAfterDraw() 事件改成为 mapEye_OnAfterScreenDraw() 事件,内容保持不变,结果程序没有现实鹰眼功能;

                                          由此我大概猜想:鹰眼框的绘制是不是算作“屏幕上图形的绘制”,故只能在OnAfterScreenDraw前执行,而主图上的一系列操作只要能够激发

                                          mapEye.Refresh()就可以了,放在  mapMain_OnAfterScreenDraw  或是 mapMain_OnAfterDraw 中都是一样

 

关于MapControl的三个事件OnAfterDrawOnAfterScreenDraw,OnBeforeScreenDraw 还望大家予以更详尽,更深入的讨论和讲解~~~                                                  


你可能感兴趣的:(ArcEngine)