zoukankan      html  css  js  c++  java
  • 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));
    
            }
    
    
    
        }
    
    
    }
  • 相关阅读:
    收音机原理
    S3C2440之存储控制器学习记录
    南校十二天集训游记
    题解 洛谷 P2179 【[NOI2012]骑行川藏】
    题解 SP3734 【PERIODNI
    题解 洛谷 P4177 【[CEOI2008]order】
    题解 CF613D 【Kingdom and its Cities】
    题解 UVA11865 【Stream My Contest】
    题解 洛谷 P2046 【[NOI2010]海拔】
    Spring Bean管理(注解的方式)
  • 原文地址:https://www.cnblogs.com/gisoracle/p/12464336.html
Copyright © 2011-2022 走看看