arcengine 两地图进行联动

http://blog.csdn.net/zdb330906531

arcengine 两地图进行联动_第1张图片

设置左边和右边的地图分别为axMapLeft、axMapRight,在平移的时候出现联动效果。

要实现联动效果,需要使用OnViewRefreshed事件,关键代码

private void axMapLeft_OnViewRefreshed(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnViewRefreshedEvent e)
{
   axMapRight.Extent = axMapLeft.Extent;
   axMapRight.ActiveView.Refresh();
}

实现这一步,可以使右边的地图跟随左边的地图联动,如果需要左边的地图也跟随右边的地图联动的话,怎么做呢?

1、判断当前鼠标在哪个地图中,并且标识

2、根据标识,选择相应的联动

private string mapName = string.Empty;
private void axMapLeft_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
    mapName = (sender as AxMapControl).Name;
}

private void axMapRight_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
    mapName = (sender as AxMapControl).Name;
}

更新代码

private void axMapLeft_OnViewRefreshed(object sender, IMapControlEvents2_OnViewRefreshedEvent e)
{
    if (mapName == "axMapLeft")
    {
        axMapRight.Extent = axMapLeft.Extent;
        axMapRight.ActiveView.Refresh();
    }
}

private void axMapRight_OnViewRefreshed(object sender, IMapControlEvents2_OnViewRefreshedEvent e)
{
    if (mapName == "axMapRight")
    {
        axMapLeft.Extent = axMapRight.Extent;
        axMapLeft.ActiveView.Refresh();
    }
}
由于工具栏只能绑定一个地图,所以我使用两个工具栏分别绑定,隐藏第二个工具栏,两个工具栏进行联动,代码如下:

private void axToolbarControl1_OnItemClick(object sender, IToolbarControlEvents_OnItemClickEvent e)
{
    axToolbarControl2.CurrentTool = axToolbarControl2.GetItem(e.index).Command as ESRI.ArcGIS.SystemUI.ITool;
}
以上代码实现两地图进行联动,大功告成


你可能感兴趣的:(ArcEngine)