• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

ArcGIS Pro二次开发-在地图上插入一个点

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using System.Windows.Input;





namespace ProAppModule1
{
    internal class MapToolSelect : MapTool
    {
        private CIMPointSymbol _pointSymbol = null;

        private IDisposable _graphic = null;



        public MapToolSelect()

        {

            IsSketchTool = true;

            SketchType = SketchGeometryType.Point;

            SketchOutputMode = SketchOutputMode.Screen;

        }



        protected async override Task OnToolActivateAsync(bool active)

        {

            if (_pointSymbol == null) _pointSymbol = await CreatePointSymbolAsync();

        }



        protected async override Task<bool> OnSketchCompleteAsync(Geometry geometry)

        {

            if (geometry.SpatialReference == null)

            {

                // screen coordinates

                var screenPointAsMapPoint = geometry as MapPoint;

                if (screenPointAsMapPoint != null)

                {

                    var pnt = new System.Windows.Point

                    {

                        X = screenPointAsMapPoint.X,

                        Y = screenPointAsMapPoint.Y

                    };

                    var mapScreenPoint = await QueuedTask.Run<MapPoint>(

                           () => MapView.Active.ClientToMap(pnt));

                    if (mapScreenPoint.IsEmpty)

                    {

                        System.Diagnostics.Debug.WriteLine(@"Screen Point is empty");

                    }

                    else

                    {

                        _graphic = await this.AddOverlayAsync(mapScreenPoint, _pointSymbol.MakeSymbolReference());

                    }

                }

            }

            else

            {

                // map coordinates

                _graphic = await this.AddOverlayAsync(geometry, _pointSymbol.MakeSymbolReference());

            }

            return true;

        }



        protected override Task OnToolDeactivateAsync(bool hasMapViewChanged)

        {

            if (_graphic != null) _graphic.Dispose();//Clear out the old overlay

            _graphic = null;

            return base.OnToolDeactivateAsync(hasMapViewChanged);

        }



        internal static Task<CIMPointSymbol> CreatePointSymbolAsync()

        {

            return QueuedTask.Run(() => SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 14, SimpleMarkerStyle.Circle));

        }



    }


}

 

posted on 2020-03-11 18:23  gisai  阅读(939)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3