Hope this helps someone. Was not able to get it to work by using projections. Found an old archived forum thread which helped me convert to lat long mathematically. Here's the code below.
#region Mouse Coordinates on screen //get the coordinates to show on the menu bar System.Windows.Threading.DispatcherTimer mouseTimer = new System.Windows.Threading.DispatcherTimer(); ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint; //initiate a map point to get the screen map point private void ArcGISTiledMapServiceLayer_Initialized(object sender, EventArgs e) { //Start the timer mouseTimer.Interval = new TimeSpan(0, 0, 0, 0, 500); // 500 Milliseconds = 1/2 second mouseTimer.Tick += new EventHandler(mouseTimer_Tick); mouseTimer.Start(); Map.MouseMove += new System.Windows.Input.MouseEventHandler(MyMap_MouseMove); } void mouseTimer_Tick(object sender, EventArgs e) { double mouseX; double mouseY; if (mapPoint != null) { Graphic mouseGraphic = new Graphic(); mouseX = mapPoint.X; mouseY = mapPoint.Y; mouseGraphic.Geometry = mapPoint; GeometryService latlonService = new GeometryService("http://<server>/ArcGIS/rest/services/Geometry/GeometryServer"); latlonService.ProjectCompleted += new EventHandler<GraphicsEventArgs>(latlonService_ProjectCompleted); latlonService.Failed += new EventHandler<TaskFailedEventArgs>(latlonService_Failed); SpatialReference sr = new SpatialReference(); sr.WKID = 4326; IList<Graphic> inG = new List<Graphic>(); inG.Add(mouseGraphic); latlonService.ProjectAsync(inG, sr); } } private void MyMap_MouseMove(object sender, System.Windows.Input.MouseEventArgs args) { if (Map.Extent != null) { Graphic mouseGraphic = new Graphic(); System.Windows.Point screenPoint = args.GetPosition(Map); mapPoint = Map.ScreenToMap(screenPoint); } } void latlonService_Failed(object sender, TaskFailedEventArgs e) { MessageBox.Show(e.Error.Message + "Latitude Longitude Service Failed"); } void latlonService_ProjectCompleted(object sender, GraphicsEventArgs e) { IList<Graphic> results = e.Results; string mouseCoords = "Latitude: " + Utilities.DDtoDMS(results[0].Geometry.Extent.YMax, false); mouseCoords += ", Longitude: " + Utilities.DDtoDMS(results[0].Geometry.Extent.XMax, false); LatLongText.Text = mouseCoords; } #endregion
I think the lag is because it is making a round trip to the server every time there is a map_mouse event...
Can anyone share a working code for this? I already have my mouse coordinates showing in xy, but want to give the user an option to change to lat/lon on the fly.
Your first atttempt with WebMercator. The WebMercator is a client side projection from "web mercator" to Geographic (4326 ) and back. You need to use the GeometryService projection and project 32640 to 4326. Looking at your geometry service projection it appears you are projecting from 32640 to 32640 which is the same thing as you started with. all you should need to do is reaplace the out spatial reference with 4326.
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.