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 { //.......................... } } }
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"); } } } ........
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.