ArcGIS Pro SDK (三)Addin控件 3 事件功能类

news2025/2/21 22:51:15

22 ArcGIS Pro 放置处理程序

22.1 添加控件

image-20240605102400652

image-20240605102500388

image-20240605102627851

22.2 Code

放置处理程序可以实现文件拖动放置、TreeVIew、ListBox等控件拖动放置功能,此处新建一个停靠窗并添加一个TreeVIew,实现节点拖动事件;

TestDropHandlerDockpane.xaml

<UserControl
             x:Class="WineMonk.Demo.ProAppModule.Code21_DropHandler.Dockpanes.TestDropHandlerDockpaneView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:extensions="clr-namespace:ArcGIS.Desktop.Extensions;assembly=ArcGIS.Desktop.Extensions"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:ui="clr-namespace:WineMonk.Demo.ProAppModule.Code21_DropHandler.Dockpanes"
             d:DataContext="{Binding Path=ui.TestDropHandlerDockpaneViewModel}"
             d:DesignHeight="300"
             d:DesignWidth="300"
             mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <extensions:DesignOnlyResourceDictionary Source="pack://application:,,,/ArcGIS.Desktop.Framework;component\Themes\Default.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <DockPanel
                   Grid.Row="0"
                   Height="30"
                   KeyboardNavigation.TabNavigation="Local"
                   LastChildFill="true">
            <TextBlock Style="{DynamicResource Esri_TextBlockDockPaneHeader}" Text="{Binding Heading}">
                <TextBlock.ToolTip>
                    <WrapPanel MaxWidth="300" Orientation="Vertical">
                        <TextBlock Text="{Binding Heading}" TextWrapping="Wrap" />
                    </WrapPanel>
                </TextBlock.ToolTip>
            </TextBlock>
        </DockPanel>
        <TreeView
                  Grid.Row="1"
                  AllowDrop="False"
                  MouseMove="TreeView_MouseMove"
                  PreviewMouseLeftButtonDown="TreeView_PreviewMouseLeftButtonDown">
            <TreeViewItem AllowDrop="False" Header="资源目录">
                <TreeViewItem AllowDrop="False" Header="矢量">
                    <TreeViewItem
                                  AllowDrop="True"
                                  Header="行政区划数据"
                                  Tag="C:\\xzqh.shp" />
                </TreeViewItem>
                <TreeViewItem AllowDrop="False" Header="栅格">
                    <TreeViewItem
                                  AllowDrop="True"
                                  Header="行政区正射影像"
                                  Tag="C:\\xzq.tif" />
                </TreeViewItem>
            </TreeViewItem>
        </TreeView>
    </Grid>
</UserControl>

TestDropHandlerDockpaneViewModel.cs

using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;


namespace WineMonk.Demo.ProAppModule.Code21_DropHandler.Dockpanes
{
    internal class TestDropHandlerDockpaneViewModel : DockPane
    {
        private const string _dockPaneID = "WineMonk_Demo_ProAppModule_Code21_DropHandler_Dockpanes_TestDropHandlerDockpane";

        protected TestDropHandlerDockpaneViewModel() { }

        /// <summary>
        /// Show the DockPane.
        /// </summary>
        internal static void Show()
        {
            DockPane pane = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
            if (pane == null)
                return;

            pane.Activate();
        }

        /// <summary>
        /// Text shown near the top of the DockPane.
        /// </summary>
        private string _heading = "My DockPane";
        public string Heading
        {
            get { return _heading; }
            set
            {
                SetProperty(ref _heading, value, () => Heading);
            }
        }
    }

    /// <summary>
    /// Button implementation to show the DockPane.
    /// </summary>
    internal class TestDropHandlerDockpane_ShowButton : Button
    {
        protected override void OnClick()
        {
            TestDropHandlerDockpaneViewModel.Show();
        }
    }
}

DropHandlerTest.cs

using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.DragDrop;
using System;
using System.Windows;


namespace WineMonk.Demo.ProAppModule.Code21_DropHandler
{
    internal class DropHandlerTest : DropHandlerBase
    {
        public override void OnDragOver(DropInfo dropInfo)
        {
            //default is to accept our data types
            dropInfo.Effects = DragDropEffects.All;
        }

        public override void OnDrop(DropInfo dropInfo)
        {
            //eg, if you are accessing a dropped file
            //string filePath = dropInfo.Items[0].Data.ToString();
            if (dropInfo.Items == null || dropInfo.Items.Count < 1)
            {
                return;
            }
            DropDataItem dropDataItem = dropInfo.Items[0];
            object data = dropDataItem.Data;
            if (data == null)
            {
                return;
            }
            if (data is DataObject dataObject)
            {
                string[] formats = dataObject.GetFormats();
                if (formats == null || formats.Length < 1)
                {
                    return;
                }
                string msg = string.Empty;
                foreach (string f in formats)
                {
                    object subData = dataObject.GetData(f);
                    msg += $"{Environment.NewLine}{f}: {subData}";
                }
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($"接收到数据:{msg}");
                dropInfo.Handled = true;
            }
            //set to true if you handled the drop
            //dropInfo.Handled = true;
        }
    }
}

Config.daml

<modules>
    <insertModule id="WineMonk_Demo_ProAppModule_Module" className="Module1" autoLoad="false" caption="Module1">
        <groups>
            <!-- comment this out if you have no controls on the Addin tab to avoid an empty group -->
            <!-- 如果您没有插件选项卡上的控件,请将其注释掉,以避免出现空组 -->
            <group id="WineMonk_Demo_ProAppModule_Group3" caption="Group 3" appearsOnAddInTab="false">
                <button refID="WineMonk_Demo_ProAppModule_Code21_DropHandler_Dockpanes_TestDropHandlerDockpane_ShowButton" size="large" />
            </group>
        </groups>
        <controls>
            <!-- add your controls here -->
            <!-- 在这里添加控件 -->
            <button id="WineMonk_Demo_ProAppModule_Code21_DropHandler_Dockpanes_TestDropHandlerDockpane_ShowButton" caption="Show TestDropHandlerDockpane" className="WineMonk.Demo.ProAppModule.Code21_DropHandler.Dockpanes.TestDropHandlerDockpane_ShowButton" loadOnClick="true" smallImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonPurple16.png" largeImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonPurple32.png">
                <tooltip heading="Show Dockpane">Show Dockpane<disabledText /></tooltip>
            </button>
        </controls>
        <dockPanes>
            <dockPane id="WineMonk_Demo_ProAppModule_Code21_DropHandler_Dockpanes_TestDropHandlerDockpane" caption="TestDropHandlerDockpane" className="WineMonk.Demo.ProAppModule.Code21_DropHandler.Dockpanes.TestDropHandlerDockpaneViewModel" dock="group" dockWith="esri_core_projectDockPane">
                <content className="WineMonk.Demo.ProAppModule.Code21_DropHandler.Dockpanes.TestDropHandlerDockpaneView" />
            </dockPane>
        </dockPanes>
    </insertModule>
</modules>
<dropHandlers>
    <!--specific file extensions can be set like so: dataTypes=".XLS|.xls"-->
    <insertHandler id="WineMonk_Demo_ProAppModule_Code21_DropHandler_DropHandlerTest" className="WineMonk.Demo.ProAppModule.Code21_DropHandler.DropHandlerTest" dataTypes="*" />
</dropHandlers>

23 ArcGIS Pro 构造工具

23.1 添加控件

image-20240605113928001

image-20240605114003342

image-20240605113851867

23.2 Code

ConstructionToolTest.cs

using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Mapping;
using System.Threading.Tasks;


namespace WineMonk.Demo.ProAppModule.Code22_ConstructionTool
{
    internal class ConstructionToolTest : MapTool
    {
        public ConstructionToolTest()
        {
            IsSketchTool = true;
            UseSnapping = true;
            // Select the type of construction tool you wish to implement.  
            // Make sure that the tool is correctly registered with the correct component category type in the daml 
            SketchType = SketchGeometryType.Point;
            // SketchType = SketchGeometryType.Line;
            // SketchType = SketchGeometryType.Polygon;
            //Gets or sets whether the sketch is for creating a feature and should use the CurrentTemplate.
            UsesCurrentTemplate = true;
            //Gets or sets whether the tool supports firing sketch events when the map sketch changes. 
            //Default value is false.
            FireSketchEvents = true;
        }

        /// <summary>
        /// Called when the sketch finishes. This is where we will create the sketch operation and then execute it.
        /// </summary>
        /// <param name="geometry">The geometry created by the sketch.</param>
        /// <returns>A Task returning a Boolean indicating if the sketch complete event was successfully handled.</returns>
        protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (CurrentTemplate == null || geometry == null)
                return Task.FromResult(false);
            // Create an edit operation
            var createOperation = new EditOperation();
            createOperation.Name = string.Format("Create {0}", CurrentTemplate.Layer.Name);
            createOperation.SelectNewFeatures = true;
            // Queue feature creation
            createOperation.Create(CurrentTemplate, geometry);
            // Execute the operation
            Notification notification = new Notification();
            notification.Title = "绘制";
            notification.Message = $"绘制图层{CurrentTemplate.Layer.Name}点要素...";
            FrameworkApplication.AddNotification(notification);
            return createOperation.ExecuteAsync();
        }
    }
}

Config.daml

<modules>
    <insertModule id="WineMonk_Demo_ProAppModule_Module" className="Module1" autoLoad="false" caption="Module1">
        <controls>
            <!-- add your controls here -->
            <!-- 在这里添加控件 -->
            <tool id="WineMonk_Demo_ProAppModule_Code22_ConstructionTool_ConstructionToolTest" categoryRefID="esri_editing_construction_point" caption="ConstructionToolTest" className="WineMonk.Demo.ProAppModule.Code22_ConstructionTool.ConstructionToolTest" loadOnClick="true" smallImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonRed16.png" largeImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonRed32.png">
                <!-- note: use esri_editing_construction_polyline,  esri_editing_construction_polygon for categoryRefID as needed -->
                <!-- esri_editing_construction_annotation
                     esri_editing_construction_dimension
                     esri_editing_construction_knowledge_graph_entity
                     esri_editing_construction_knowledge_graph_relationship
                     esri_editing_construction_multipatch
                     esri_editing_construction_multipoint
                     esri_editing_construction_point
                     esri_editing_construction_polygon
                     esri_editing_construction_polyline
                     esri_editing_construction_table -->
                <tooltip heading="Tooltip Heading">Tooltip text<disabledText /></tooltip>
                <content guid="cdfdb0f2-c229-458e-bac8-5a638cd98bb3" />
            </tool>
        </controls>
    </insertModule>
</modules>

24 ArcGIS Pro 表构造工具

24.1 添加控件

image-20240605114718537

image-20240605114949930

image-20240605115730930

24.2 Code

TableConstructionToolTest.cs

using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Mapping;
using System.Threading.Tasks;

namespace WineMonk.Demo.ProAppModule.Code23_TableConstructionTool
{
    internal class TableConstructionToolTest : MapTool
    {
        public TableConstructionToolTest()
        {
            IsSketchTool = false;
            // set the SketchType to None
            SketchType = SketchGeometryType.None;
            //Gets or sets whether the sketch is for creating a feature and should use the CurrentTemplate.
            UsesCurrentTemplate = true;
        }

        /// <summary>
        /// Called when the "Create" button is clicked. This is where we will create the edit operation and then execute it.
        /// </summary>
        /// <param name="geometry">The geometry created by the sketch - will be null because SketchType = SketchGeometryType.None</param>
        /// <returns>A Task returning a Boolean indicating if the sketch complete event was successfully handled.</returns>
        protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (CurrentTemplate == null)
                return Task.FromResult(false);
            // geometry will be null
            // Create an edit operation
            var createOperation = new EditOperation();
            createOperation.Name = string.Format("Create {0}", CurrentTemplate.StandaloneTable.Name);
            createOperation.SelectNewFeatures = false;
            // determine the number of rows to add
            var numRows = this.CurrentTemplateRows;
            for (int idx = 0; idx < numRows; idx++)
                // Queue feature creation
                createOperation.Create(CurrentTemplate, null);
            // Execute the operation
            Notification notification = new Notification();
            notification.Title = "添加行";
            notification.Message = $"添加表{CurrentTemplate.MapMember.Name}行...";
            FrameworkApplication.AddNotification(notification);
            return createOperation.ExecuteAsync();
        }
    }
}

Config.daml

<modules>
    <insertModule id="WineMonk_Demo_ProAppModule_Module" className="Module1" autoLoad="false" caption="Module1">
        <controls>
            <!-- add your controls here -->
            <!-- 在这里添加控件 -->
            <tool id="WineMonk_Demo_ProAppModule_Code23_TableConstructionTool_TableConstructionToolTest" categoryRefID="esri_editing_construction_table" caption="TableConstructionToolTest" className="WineMonk.Demo.ProAppModule.Code23_TableConstructionTool.TableConstructionToolTest" loadOnClick="true" smallImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonRed16.png" largeImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonRed32.png">
                <tooltip heading="Tooltip Heading">Tooltip text<disabledText /></tooltip>
                <content guid="a3d2b675-374a-44c1-be88-e0991cc7fe39" />
            </tool>
        </controls>
    </insertModule>
</modules>   

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1830772.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

开源项目推荐

这个资源列表集合了.NET开发领域的优秀工具、库、框架和软件等&#xff0c; 如果您目前研究开源大模型项目&#xff0c;请参考热门开源大模型项目推荐链接如下&#xff1a;https://blog.csdn.net/hefeng_aspnet/article/details/139669116 欢迎各位小伙伴收藏、点赞、留言、评论…

一文学会消息中间件的基础知识

什么是消息队列 队列数据结构 我们都学习过数据结构与算法相关的内容,消息队列从数据结构来看,就是一个由链表或是数组构成的一个先进先出的数据容器。由链表实现还是数组实现都没关系,它只要满足数据项是先进先出的特点,那么就可以认为它是一个队列结构。队列是只允许在…

个人云服务器已经被安全合规等卡脖子 建议不要买 买了必定后悔 安全是个大问题 没有能力维护

我的想法 自己买一个云服务器&#xff0c;先自己边做边学习&#xff0c;向往硅谷精神&#xff0c;财富与自由。如果能赚钱&#xff0c;就开个公司。这次到期就放弃了。 我前前后后6年花6000多元买云服务器。业余花了无数的精力&#xff0c;从2018到现在 &#xff0c;也没有折…

618购物节数码好物到底怎么选?盘点几款可闭眼入的数码好物分享

随着618购物节的热烈氛围逐渐升温&#xff0c;数码产品的选购成为了许多消费者关注的焦点。面对市场上层出不穷的新品和优惠&#xff0c;如何选择一款既符合自己需求又物超所值的数码好物&#xff0c;成为了不少人的难题&#xff0c;今天&#xff0c;我们就为大家带来几款精心挑…

QT Redis 中的实现发布/订阅功能(全网最全的教程)

Redis 介绍 Redis发布/ 订阅系统 是 Web 系统中比较常用的一个功能。简单点说就是 发布者发布消息&#xff0c;订阅者接收消息&#xff0c;这有点类似于我们的报纸/ 杂志社之类的 实现代码 #ifndef MAINWIDGET_H #define MAINWIDGET_H#include <QWidget> #include <…

【C++提高编程-09】----C++ STL之常用排序算法

&#x1f3a9; 欢迎来到技术探索的奇幻世界&#x1f468;‍&#x1f4bb; &#x1f4dc; 个人主页&#xff1a;一伦明悦-CSDN博客 ✍&#x1f3fb; 作者简介&#xff1a; C软件开发、Python机器学习爱好者 &#x1f5e3;️ 互动与支持&#xff1a;&#x1f4ac;评论 &…

基于单片机的无线遥控自动翻书机械臂设计

摘 要&#xff1a; 本设备的重点控制部件为单片机&#xff0c;充分实现了其自动化的目的。相关研究表明&#xff0c;它操作简单便捷&#xff0c;使残疾人在翻书时提供了较大的便利&#xff0c;使用价值性极高&#xff0c;具有很大的发展空间。 关键词&#xff1a; 机械臂&…

Django后台忘记管理员的账号

使用命令启动项目&#xff1a; python manage.py runserver输入后缀/admin&#xff0c;进入后台管理员&#xff0c;如果此时忘记你先前设置的用户名与密码怎么办&#xff1f; 终端输入&#xff1a; python manage.py shell 输入以下内容&#xff0c;并查看返回结果&#xff…

大跨度气膜综合馆有哪些优势—轻空间

1. 经济高效 材料和施工成本低 气膜综合馆的建设成本相对较低&#xff0c;主要材料为膜材和充气系统&#xff0c;不需要大量的钢筋混凝土和复杂的结构施工&#xff0c;降低了材料和施工成本。 能源消耗低 气膜馆的双层膜结构和充气系统具有良好的保温性能&#xff0c;减少了冬…

【经典爬虫案例】用Python爬取微博热搜榜!

一、爬取目标 本次爬取的是: 微博热搜榜 &#xff08;代码也可直接在下方拿&#xff09;&#xff1a; ​ 分别爬取每条热搜的&#xff1a; 热搜标题、热搜排名、热搜类别、热度、链接地址。 下面&#xff0c;对页面进行分析。 经过分析&#xff0c;此页面没有XHR链接通过&am…

Sping源码(九)—— Bean的初始化(非懒加载)— Bean的创建方式(自定义BeanPostProcessor)

序言 之前文章有介绍采用FactoryBean的方式创建对象&#xff0c;以及使用反射创建对象。 这篇文章继续介绍Spring中创建Bean的形式之一——自定义BeanPostProcessor。 之前在介绍BeanPostProcessor的文章中有提到&#xff0c;BeanPostProcessor接口的实现中有一个Instantiatio…

Proxmox VE 超融合集群扩容后又平稳运行了170多天--不重启的话,488天了

五个节点的Proxmox VE 超融合集群&#xff0c;扩从了存储容量&#xff0c;全NVMe高速盘&#xff0c;单机4条3.7TB容量&#xff08;扩容前是两块NVMe加两块16TB的慢速SATA机械盘&#xff0c;拔掉机械盘&#xff0c;替换成两块NVMe&#xff09;&#xff0c;速度那叫一个快啊。 当…

秋招突击——6/16——复习{(单调队列优化DP)——最大子序和,背包模型——宠物小精灵收服问题}——新作{二叉树的后序遍历}

文章目录 引言复习&#xff08;单调队列优化DP&#xff09;——最大子序和单调队列的基本实现思路——求可移动窗口中的最值总结 背包模型——宠物小精灵收服问题思路分析参考思路分析 新作二叉树的后续遍历加指针调换 总结 引言 复习 &#xff08;单调队列优化DP&#xff09…

Qt实现单例模式:Q_GLOBAL_STATIC和Q_GLOBAL_STATIC_WITH_ARGS

目录 1.引言 2.了解Q_GLOBAL_STATIC 3.了解Q_GLOBAL_STATIC_WITH_ARGS 4.实现原理 4.1.对象的创建 4.2.QGlobalStatic 4.3.宏定义实现 4.4.注意事项 5.总结 1.引言 设计模式之单例模式-CSDN博客 所谓的全局静态对象&#xff0c;大多是在单例类中所见&#xff0c;在之前…

使用ant-design/cssinjs向plasmo浏览器插件的内容脚本content中注入antd的ui组件样式

之前写过一篇文章用来向content内容脚本注入antd的ui&#xff1a;https://xiaoshen.blog.csdn.net/article/details/136418199&#xff0c;但是方法就是比较繁琐&#xff0c;需要将antd的样式拷贝出来&#xff0c;然后贴到一个单独的css样式文件中&#xff0c;然后引入到内容脚…

20个超实用的VS Code扩展(2024年版)

大家好&#xff0c;今天小程给大家带来一篇关于 VS Code 扩展的文章。VS Code 这几年做得是风生水起&#xff0c;可以算得上是微软的良心产品&#xff0c;其最大的优势就是拥有众多高质量的扩展。在本文中&#xff0c;将向大家推荐一些我认为在 2024 年对开发者来说又实用又好用…

分布式技术导论 — 探索分析从起源到现今的巅峰之旅(分布式协议)

探索分析从起源到现今的巅峰之旅2 前提回顾最终一致性Clock时钟机制局限性 CAP协议CAP理论的三要素A和C机制的保障P分区容错性AP机制的保障CP机制的保障 分布式系统方向 分布式系统之ZookeeperZK的作用和职责协调服务命名服务构建高可靠服务 ZK的常见用法ZK基本原理ZK的顺序一致…

将粘贴文本进输入框中时不带有任何格式(包括背景颜色和字体)解决办法

只需要四行代码解决&#xff0c;这里用到vue3里面的事件 paste"" 代码块&#xff1a; <div paste"handlePaste"></div>//粘贴文本时不带有任何格式&#xff08;包括背景颜色和字体&#xff09;function handlePaste(event) {event.preventDef…

【计算机毕业设计】234基于微信小程序的中国各地美食推荐平台

&#x1f64a;作者简介&#xff1a;拥有多年开发工作经验&#xff0c;分享技术代码帮助学生学习&#xff0c;独立完成自己的项目或者毕业设计。 代码可以私聊博主获取。&#x1f339;赠送计算机毕业设计600个选题excel文件&#xff0c;帮助大学选题。赠送开题报告模板&#xff…