创建ArcGIS Pro按钮——一键移除所有图层

有时候地图里面的图层加的乱七八糟的,想清空图层的时候一般是shift连选之后右键移除,但是如果图层上有图表就会经常点错行,很不方便。找了一圈竟然也没找到一键移除图层的按钮,所以使用SDK构建了一个地图上下文菜单按钮,一键移除所有图层。效果如下
在这里插入图片描述
按钮的核心代码十分简单

    internal class Button_RemoveAllLayers : Button
        public void RemoveAllLayers()
        {
    
    
            var mv = MapView.Active;
            var lyrs = mv.Map.Layers;
            //RemoveLayers方法必须在QueuedTask.Run中运行
            QueuedTask.Run(() =>
            {
    
    
                mv.Map.RemoveLayers(lyrs);
            });
        }

        protected override void OnClick()
        {
    
    
            RemoveAllLayers();
        }

为了将按钮加入到效果图所示的位置,DAML需要添加的代码

    <updateModule refID="esri_mapping">
      <menus>
        <updateMenu refID="esri_mapping_mapContextMenu">
          <!--Note: New_Menu_Item_Button is a button control that must exist within the controls tag-->
          <insertButton refID="ProAppModule_Button_RemoveAllLayers" placeWith="esri_mapping_addDataButton"/>
        </updateMenu>
      </menus>
    </updateModule>

这是出于自己的需求创建的第一个ArcGIS Pro 按钮,虽然很简单不过大大提升了学习的兴趣。

猜你喜欢

转载自blog.csdn.net/baidu_28157641/article/details/105484798