Measuring Tool to show NAD 27

776
1
02-12-2014 11:24 AM
JeffreyUtter
Occasional Contributor
Currently the measure tool includes coordinates in LAT LONG ??? I need to change the tool, to enhance it to also include the NAD27 X&Y for the map.
Please help.
0 Kudos
1 Reply
PietaSwanepoel2
Occasional Contributor
Jeffery, you will have to write your own add-in for this.

Essentially you will have to do something like this:
(I don't know about NAD27 because of no relevance to me but this is the same idea)

  • Add mouse click eventhandler to map

  • Handle event and do geometry task on coordinate to find output format

  • display result


        private Map _currentmap;

        public CoordinateTool(Map currentmap)
        {
            // TODO: Complete member initialization
            this._currentmap = currentmap ?? MapApplication.Current.Map;

            if(_currentmap != null)
            {
                _currentmap.MouseClick += CurrentmapOnMouseClick;
             }

            CurrentCoordinates = new CurrentProjectionCoordinates() {X = "0", Y = "0"};
            DdCoordinates = new DDCoordinates() {X_DD = "0", Y_DD = "0"};
            DmsCoordinates = new DMSCoordinates() {X_DMS = "0", Y_DMS = "0"};

            //initialise service endpoints
            _geometryservice = new GeometryService(MapApplication.Current.Urls.GeometryServiceUrl);
            _geometryservice.ProjectCompleted += GeometryserviceOnProjectCompleted;
            _geometryservice.Failed += GeometryserviceOnFailed;
       }

        private void CurrentmapOnMouseClick(object sender, Map.MouseEventArgs mouseEventArgs)
        {
            MapPoint point = mouseEventArgs.MapPoint;

            if (point != null)
            {
                CurrentCoordinates.X = string.Format("{0:N4}", point.X);
                CurrentCoordinates.Y = string.Format("{0:N4}", point.Y);

                // Coordinates in WGS84 format
                Graphic pointgraphic = new Graphic() {Geometry = point};

                if (_geometryservice != null && _currentmap != null)
                {
                    IsReprojection = false;
                    if (!_geometryservice.IsBusy)
                    {
                        _geometryservice.ProjectAsync(new List<Graphic>() { pointgraphic }, new SpatialReference(WKID_WGS84)); 
                    }
                }
            }
        } 

        private void GeometryserviceOnFailed(object sender, TaskFailedEventArgs taskFailedEventArgs)
        {
            MainApplication.Handle("Error", taskFailedEventArgs.Error);
        }

        private void GeometryserviceOnProjectCompleted(object sender, GraphicsEventArgs graphicsEventArgs)
        {
            Graphic resultgraphic = graphicsEventArgs.Results.FirstOrDefault();

            if (resultgraphic != null)
            {
                if (!IsReprojection)
                {
                    IsReprojection = false;

                    MapPoint point = resultgraphic.Geometry as MapPoint;

                    if (point != null)
                    {
                            DdCoordinates.X_DD = string.Format("{0:N4}", point.X);
                            DdCoordinates.Y_DD = string.Format("{0:N4}", point.Y);

                            DmsCoordinates.X_DMS = string.Format("{0:N4}", DMSCoordinates.FromDecimalDegrees(point.X));
                            DmsCoordinates.Y_DMS = string.Format("{0:N4}", DMSCoordinates.FromDecimalDegrees(point.Y));

                    }
                }
                else
                {
                     //..........................
                } 
            }
        }


and the classes is something like so:
   
    public class CurrentProjectionCoordinates : NotificationBase
    {
        protected string x;
        protected string y;

        private double surrogate = 0;

        public string X
        {
            get { return (x); }
            set
            {
                x = value; OnNotifyPropertyChanged("X");
            }
        }

        public string Y
        {
            get { return (y); }
            set
            {
                y = value; OnNotifyPropertyChanged("Y");
            }
        }
    } 

    public class DDCoordinates : NotificationBase
    {
        private string x;
        private string y;

        public string X_DD
        {
            get { return (x); }
            set { x = value; OnNotifyPropertyChanged("X_DD"); }
        }

        public string Y_DD
        {
            get { return (y); }
            set { y = value; OnNotifyPropertyChanged("Y_DD"); }
        }

   }

........
0 Kudos