I am attempting to draw points on a map using the lat/long values I am getting from a table. My problem is that my basemap and other data is in X/Y (Missouri State Plane) and when I try to do a mashup with a tiled service my graphics aren't where they are supposed to be.
I am having trouble understanding how to use a geometry service to convert the spatial reference. Any help would be greatly appreciated.
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using ESRI.ArcGIS.Client; using ESRI.ArcGIS.Client.Geometry; using ESRI.ArcGIS.Client.Symbols; using System.Runtime.Serialization; using ESRI.ArcGIS.Client.Tasks; using System.Windows.Threading; using ESRI.ArcGIS.Client.Bing;
namespace TruckGPS_Test { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); //AddMarkerGraphics();
//This timer updates the outage feature count after a 30 second wait System.Windows.Threading.DispatcherTimer myDispatcherTimer = new System.Windows.Threading.DispatcherTimer(); myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 10, 0); myDispatcherTimer.Tick += new EventHandler(Each_Tick); myDispatcherTimer.Start();
} public void Each_Tick(object o, EventArgs sender) { QueryTask queryTaskTruckGPS = new QueryTask("http://gisaprd/ArcGIS/rest/services/TruckGPS/MapServer/8"); queryTaskTruckGPS.ExecuteCompleted += QueryTask_ExecuteCompletedTruckGPS; ESRI.ArcGIS.Client.Tasks.Query queryTruckGPS = new ESRI.ArcGIS.Client.Tasks.Query(); queryTruckGPS.OutFields.Add("*"); queryTruckGPS.ReturnGeometry = false; queryTruckGPS.Where = "1=1"; queryTaskTruckGPS.ExecuteAsync(queryTruckGPS, "initial");
}
private void QueryTask_ExecuteCompletedTruckGPS(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { //If Counter isn't working check the web service, make sure the table is added to the map service FeatureSet featureSet = args.FeatureSet; GraphicsLayer graphicsLayer = MyMap.Layers["TruckGPS"] as GraphicsLayer; graphicsLayer.ClearGraphics(); if (featureSet != null && featureSet.Features.Count > 0) {
////Check the system time and subtract the time amount wanted from the last gps systime read for movement or idle truck //System.DateTime dTime = DateTime.Now; //// tSpan is 0 days, 0 hours, 0 minutes, and 0 seconds. //System.TimeSpan tSpan = new System.TimeSpan(0, 1, 0, 0); //System.DateTime result = dTime - tSpan; foreach (ESRI.ArcGIS.Client.Graphic feature in featureSet.Features) { if ((feature.Attributes["LONGITUDE"] != null) && (feature.Attributes["LATITUDE"] != null) ) //&& (feature.Attributes["S"]) {
var Machine_Name = feature.Attributes["MACHINE_NAME"].ToString(); var User_Name = feature.Attributes["USER_NAME"].ToString(); double x = Convert.ToDouble(feature.Attributes["LONGITUDE"]); double y =Convert.ToDouble(feature.Attributes["LATITUDE"]);
feature.Geometry = new MapPoint(x, y); //if (User_Name == "CU656") //{ feature.Symbol = LayoutRoot.Resources["TRUCK"] as ESRI.ArcGIS.Client.Symbols.Symbol; graphicsLayer.Graphics.Add(feature); //} //else //{ // feature.Symbol = LayoutRoot.Resources["RedMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; // graphicsLayer.Graphics.Add(feature); //} } } { (MyMap.Layers["TruckGPS"] as GraphicsLayer).Refresh(); }; } else { graphicsLayer.ClearGraphics(); //MessageBox.Show("No features returned from query"); } } private void MyMap_MouseMove(object sender, System.Windows.Input.MouseEventArgs args) { if (MyMap.Extent != null) { System.Windows.Point screenPoint = args.GetPosition(MyMap); ScreenCoordsTextBlock.Text = string.Format("Screen Coords: X = {0}, Y = {1}", screenPoint.X, screenPoint.Y);
ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = MyMap.ScreenToMap(screenPoint); if (MyMap.WrapAroundIsActive) mapPoint = ESRI.ArcGIS.Client.Geometry.Geometry.NormalizeCentralMeridian(mapPoint) as ESRI.ArcGIS.Client.Geometry.MapPoint; MapCoordsTextBlock.Text = string.Format("Map Coords: X = {0}, Y = {1}", Math.Round(mapPoint.X, 4), Math.Round(mapPoint.Y, 4)); } } }
I have been looking at this example in the help but I am having trouble taking my Truck_GPS graphics layer and changing the spatial reference to match my tiled map service.