选择工具自动绑定了mapControl的MapControl_OnSelChange事件,而自定义的选择最上层要素工具,并没有在选择完成后自动调用MapControl_OnSelChange事件。
于是声明委托事件,并将其与原MapControl_OnSelChange事件进行绑定,并在选择完成后调用。
结果:
//声明地图容器中选择要素改变事件的委托
public delegate void MapControl_OnSelectionChanged(object sender, EventArgs e);
public event MapControl_OnSelectionChanged MapControl_OnSelChange;
SelectFeatures(_mapCtrl, geometry);
if (MapControl_OnSelChange != null)
{
MapControl_OnSelChange(null, null); //调用
}
_envelopeFeedback = null;
_mapCtrl.ActiveView.Refresh();
并在创建ICoomand时将原本的OnSelChange函数关联:
ICommand toolSelectTopMostLayer = new ToolSelectTopMostLayer(_axMapControl);
(toolSelectTopMostLayer as ToolSelectTopMostLayer).MapControl_OnSelChange += new ToolSelectTopMostLayer.MapControl_OnSelectionChanged(GridViewManager.theMapControlMain_OnSelectionChanged);
BindRibbonItemWithCommand("rbiSelectTopMostLayer", toolSelectTopMostLayer);