Hi,
I need help to show lat long on mouse hover on map. I have tried the existing code sample ---
ESRI.ArcGIS.Client.Projection.WebMercator webmercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
ESRI.ArcGIS.Client.Geometry.MapPoint latlongpoint = (ESRI.ArcGIS.Client.Geometry.MapPoint)webmercator.FromGeographic(mapPoint);//here I have tried toGeographic also.. for just a try..but still got error ..
latlongTextBlock.Text = string.Format("Lat Long: X = {0}, Y = {1}", Math.Round(latlongpoint.Extent.XMin, 4), Math.Round(latlongpoint.Extent.YMin, 4));
But I kept on getting Invalid Spatial Reference error. My map wkid is 32640- wgs84 zone 40N projection.
therefore I added a line -> mapPoint.SpatialReference.WKID = 32640; //but then again got the same spatial reference error..
Then I tried the GEOMETRY SERVICE approach explained in another post in this forum..
Graphic pointGraphic = new Graphic();
pointGraphic.Geometry = mapPoint;
pointGraphic.Geometry.SpatialReference = new SpatialReference(32640);
IList<Graphic> inG = new List<Graphic>();
inG.Add(pointGraphic);
GeometryService svcGeometry = new GeometryService(Service_URL.GEOMETRY_SUPREME);
svcGeometry.ProjectCompleted += new EventHandler<GraphicsEventArgs>(svcGeometry_ProjectCompleted);
svcGeometry.Failed += new EventHandler<TaskFailedEventArgs>(svcGeometry_Failed);
SpatialReference sr = new SpatialReference();
sr.WKID = 32640;
svcGeometry.ProjectAsync(inG, sr);
void svcGeometry_ProjectCompleted(object sender, GraphicsEventArgs e)
{
IList<Graphic> results = e.Results;
Graphic projectedG = results[0]; //should just be one
//**Code here to build new extent at which to center the map.
ESRI.ArcGIS.Client.Geometry.MapPoint newpoint = new MapPoint();
newpoint.X = projectedG.Geometry.Extent.XMin;
newpoint.Y = projectedG.Geometry.Extent.YMin;
latlongTextBlock.Text = string.Format("Lat Long: X = {0}, Y = {1}", Math.Round(newpoint.X, 4), Math.Round(newpoint.Y, 4));
}
But with this instead of getting lat longs ...I get the same results like from the following code sample -
ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = Map.ScreenToMap(screenPoint);
MapCoordsTextBlock.Text = string.Format("Map Coords: X = {0}, Y = {1}",
Math.Round(mapPoint.X, 4), Math.Round(mapPoint.Y, 4));
My Map/datasets etc are in WGS_1984_UTM_Zone_40N Projection. I dont know where my approach is wrong here , please help...thanks in advance 😞