Skip to main content
edited tags
Link
Devdatta Tengshe
  • 41.6k
  • 35
  • 144
  • 263
added 686 characters in body
Source Link
BradHards
  • 12.9k
  • 2
  • 39
  • 72

 
<UserControl x:Class="TruckGPS_Test.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
             xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client">
    <Grid x:Name="LayoutRoot" Background="White">
   
        
        <Grid.Resources>
             <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
            <esri:SimpleMarkerSymbol x:Key="YellowMarkerSymbol" Color="Yellow" Size="25" Style="Circle" />
            <esriSymbols:PictureMarkerSymbol x:Name="TRUCK" Source="images/bucket-truck-box.png" />
        </Grid.Resources>


        <esri:Map x:Name="MyMap" WrapAround="True" Margin="0,0,-325,-506" MouseMove="MyMap_MouseMove">
            <!--<esri:ArcGISTiledMapServiceLayer ID="MyLayer"
                Url="http://gisaprd/ArcGIS/rest/services/BaseMap_ArcReader_Cached/MapServer" />-->
            <!--<esri:ArcGISTiledMapServiceLayer ID="MyLayer"
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />-->
            <esri:ArcGISTiledMapServiceLayer ID="Aerials" Url="http://gisaprd/ArcGIS/rest/services/AerialCoordinateTest/MapServer" Visible="False"  />
            <esri:ArcGISDynamicMapServiceLayer Url="http://gisaprd/ArcGIS/rest/services/BaseMapCool__WebViewer/MapServer" />

            <esri:GraphicsLayer ID="TruckGPS" >

                <esri:GraphicsLayer.MapTip>
                    <Grid Background="#FFD65555" >
                        <Border BorderBrush="#FFFF0000" BorderThickness="1" CornerRadius="5" />
                        <StackPanel Orientation="Vertical" >
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding [USER_NAME]}" FontWeight="Bold" Foreground="White"  HorizontalAlignment="Left"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding [SYSTIME]}" FontWeight="Bold" Foreground="White"  HorizontalAlignment="Left"/>
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </esri:GraphicsLayer.MapTip>
            </esri:GraphicsLayer>

        </esri:Map>

        <Grid MinWidth="300" HorizontalAlignment="Right" Background="White" VerticalAlignment="Top" Margin="0,15,15,0" >
            <StackPanel Margin="5">
                <TextBlock x:Name="ScreenCoordsTextBlock" 
                    HorizontalAlignment="Left" VerticalAlignment="Center" Text="Screen Coords: "
                           TextWrapping="Wrap" />
                <TextBlock x:Name="MapCoordsTextBlock" 
                    HorizontalAlignment="Left" VerticalAlignment="Center" Text="Map Coords: " 
                           TextWrapping="Wrap" />
            </StackPanel>
        </Grid>


    </Grid>
</UserControl>

C#

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();C#

        QueryTask queryTaskTruckGPS = newusing QueryTask("http://gisaprd/ArcGIS/rest/services/TruckGPS/MapServer/8");System;
      using System.Collections.Generic;
using queryTaskTruckGPSSystem.ExecuteCompletedLinq;
using +=System.Net;
using QueryTask_ExecuteCompletedTruckGPS;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.Tasks.Query queryTruckGPS = newGeometry;
using ESRI.ArcGIS.Client.Tasks.Query();Symbols;
       using queryTruckGPSSystem.OutFieldsRuntime.Add("*");Serialization;
       using queryTruckGPSESRI.ReturnGeometry = false;ArcGIS.Client.Tasks;
       using queryTruckGPSSystem.Where = "1=1";Windows.Threading;
       using queryTaskTruckGPSESRI.ExecuteAsync(queryTruckGPS, "initial");ArcGIS.Client.Bing;

        //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();

   namespace }TruckGPS_Test
    {
    public voidpartial Each_Tick(objectclass o,MainPage EventArgs: sender)UserControl
    {
        QueryTask queryTaskTruckGPS = newpublic QueryTaskMainPage("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.AddInitializeComponent("*");
        queryTruckGPS.ReturnGeometry = false;
        queryTruckGPS.Where = "1=1";
        queryTaskTruckGPS.ExecuteAsync//AddMarkerGraphics(queryTruckGPS, "initial");

    }        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)
   //This {
timer updates the outage feature count after a //If30 Countersecond isn'twait
 working check the web service, make sure the table is added toSystem.Windows.Threading.DispatcherTimer themyDispatcherTimer map= servicenew System.Windows.Threading.DispatcherTimer();
            myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 10, 0);
    
         FeatureSetmyDispatcherTimer.Tick featureSet+= =new args.FeatureSet;EventHandler(Each_Tick);
        GraphicsLayer graphicsLayer = MyMap.Layers["TruckGPS"] as GraphicsLayer;myDispatcherTimer.Start();

        graphicsLayer.ClearGraphics();}
        if 
 (featureSet != null && featureSet.Features.Count > 0 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");

        }

    ////Check the system time and subtract the timeprivate amountvoid wantedQueryTask_ExecuteCompletedTruckGPS(object fromsender, theESRI.ArcGIS.Client.Tasks.QueryEventArgs lastargs)
 gps systime read for movement or idle truck{
            //System.DateTime dTimeIf =Counter DateTime.Now;
isn't working check the web service, make sure the table is added ////to tSpanthe ismap 0service
 days, 0 hours, 0 minutes, and 0 seconds.
            //System.TimeSpan tSpan = new System.TimeSpan(0, 1, 0, 0);
            //System.DateTimeFeatureSet resultfeatureSet = dTimeargs.FeatureSet;
 - tSpan;
          GraphicsLayer graphicsLayer = MyMap.Layers["TruckGPS"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();
            foreachif (ESRI.ArcGIS.Client.GraphicfeatureSet feature!= innull && 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
                if//System.DateTime ((featuredTime = DateTime.Attributes["LONGITUDE"]Now;
 !               //// tSpan is 0 days, 0 hours, 0 minutes, and 0 seconds.
                //System.TimeSpan tSpan = nullnew System.TimeSpan(0, 1, 0, 0);
 && (feature              //System.Attributes["LATITUDE"]DateTime !result = null)dTime )- tSpan;
                
     //&&          
                foreach (ESRI.ArcGIS.Client.Graphic feature in featureSet.Attributes["S"]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(); };
            }
            { (MyMap.Layers["TruckGPS"] as GraphicsLayer).Refresh(); };else
        }
        else{
        {
            graphicsLayer.ClearGraphics();
                //MessageBox.Show("No features returned from query");
            }
        }
       
    }
   
}

}

 
    <Grid.Resources>
         <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
        <esri:SimpleMarkerSymbol x:Key="YellowMarkerSymbol" Color="Yellow" Size="25" Style="Circle" />
        <esriSymbols:PictureMarkerSymbol x:Name="TRUCK" Source="images/bucket-truck-box.png" />
    </Grid.Resources>


    <esri:Map x:Name="MyMap" WrapAround="True" Margin="0,0,-325,-506" MouseMove="MyMap_MouseMove">
        <!--<esri:ArcGISTiledMapServiceLayer ID="MyLayer"
            Url="http://gisaprd/ArcGIS/rest/services/BaseMap_ArcReader_Cached/MapServer" />-->
        <!--<esri:ArcGISTiledMapServiceLayer ID="MyLayer"
            Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />-->
        <esri:ArcGISTiledMapServiceLayer ID="Aerials" Url="http://gisaprd/ArcGIS/rest/services/AerialCoordinateTest/MapServer" Visible="False"  />
        <esri:ArcGISDynamicMapServiceLayer Url="http://gisaprd/ArcGIS/rest/services/BaseMapCool__WebViewer/MapServer" />

        <esri:GraphicsLayer ID="TruckGPS" >

            <esri:GraphicsLayer.MapTip>
                <Grid Background="#FFD65555" >
                    <Border BorderBrush="#FFFF0000" BorderThickness="1" CornerRadius="5" />
                    <StackPanel Orientation="Vertical" >
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding [USER_NAME]}" FontWeight="Bold" Foreground="White"  HorizontalAlignment="Left"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding [SYSTIME]}" FontWeight="Bold" Foreground="White"  HorizontalAlignment="Left"/>
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </esri:GraphicsLayer.MapTip>
        </esri:GraphicsLayer>

    </esri:Map>

    <Grid MinWidth="300" HorizontalAlignment="Right" Background="White" VerticalAlignment="Top" Margin="0,15,15,0" >
        <StackPanel Margin="5">
            <TextBlock x:Name="ScreenCoordsTextBlock" 
                HorizontalAlignment="Left" VerticalAlignment="Center" Text="Screen Coords: "
                       TextWrapping="Wrap" />
            <TextBlock x:Name="MapCoordsTextBlock" 
                HorizontalAlignment="Left" VerticalAlignment="Center" Text="Map Coords: " 
                       TextWrapping="Wrap" />
        </StackPanel>
    </Grid>


</Grid>

C#

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();

        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");

        //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");
        }
    }
   
}

}

<UserControl x:Class="TruckGPS_Test.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
             xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client">
    <Grid x:Name="LayoutRoot" Background="White">
   
        
        <Grid.Resources>
             <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
            <esri:SimpleMarkerSymbol x:Key="YellowMarkerSymbol" Color="Yellow" Size="25" Style="Circle" />
            <esriSymbols:PictureMarkerSymbol x:Name="TRUCK" Source="images/bucket-truck-box.png" />
        </Grid.Resources>


        <esri:Map x:Name="MyMap" WrapAround="True" Margin="0,0,-325,-506" MouseMove="MyMap_MouseMove">
            <!--<esri:ArcGISTiledMapServiceLayer ID="MyLayer"
                Url="http://gisaprd/ArcGIS/rest/services/BaseMap_ArcReader_Cached/MapServer" />-->
            <!--<esri:ArcGISTiledMapServiceLayer ID="MyLayer"
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />-->
            <esri:ArcGISTiledMapServiceLayer ID="Aerials" Url="http://gisaprd/ArcGIS/rest/services/AerialCoordinateTest/MapServer" Visible="False"  />
            <esri:ArcGISDynamicMapServiceLayer Url="http://gisaprd/ArcGIS/rest/services/BaseMapCool__WebViewer/MapServer" />

            <esri:GraphicsLayer ID="TruckGPS" >

                <esri:GraphicsLayer.MapTip>
                    <Grid Background="#FFD65555" >
                        <Border BorderBrush="#FFFF0000" BorderThickness="1" CornerRadius="5" />
                        <StackPanel Orientation="Vertical" >
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding [USER_NAME]}" FontWeight="Bold" Foreground="White"  HorizontalAlignment="Left"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding [SYSTIME]}" FontWeight="Bold" Foreground="White"  HorizontalAlignment="Left"/>
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </esri:GraphicsLayer.MapTip>
            </esri:GraphicsLayer>

        </esri:Map>

        <Grid MinWidth="300" HorizontalAlignment="Right" Background="White" VerticalAlignment="Top" Margin="0,15,15,0" >
            <StackPanel Margin="5">
                <TextBlock x:Name="ScreenCoordsTextBlock" 
                    HorizontalAlignment="Left" VerticalAlignment="Center" Text="Screen Coords: "
                           TextWrapping="Wrap" />
                <TextBlock x:Name="MapCoordsTextBlock" 
                    HorizontalAlignment="Left" VerticalAlignment="Center" Text="Map Coords: " 
                           TextWrapping="Wrap" />
            </StackPanel>
        </Grid>


    </Grid>
</UserControl>

C#

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();

            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");

            //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");
            }
        }
       
    }

}
Source Link
bives
  • 13
  • 2
  • 9

Lat/Long to XY conversion with Geometry Service

I am attempting to make a simple map that will allow users to see a truck's GPS location on top of a tiled map service. I am having difficulty getting the graphic symbol to overlap my tiled service because the spatial systems do not match.

Is there a good example or could someone help me conversion through a geometry service? Is a geometry service even the correct method to use for plotting my graphics?

Here is my code so far.

Xaml:

    <Grid.Resources>
         <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
        <esri:SimpleMarkerSymbol x:Key="YellowMarkerSymbol" Color="Yellow" Size="25" Style="Circle" />
        <esriSymbols:PictureMarkerSymbol x:Name="TRUCK" Source="images/bucket-truck-box.png" />
    </Grid.Resources>


    <esri:Map x:Name="MyMap" WrapAround="True" Margin="0,0,-325,-506" MouseMove="MyMap_MouseMove">
        <!--<esri:ArcGISTiledMapServiceLayer ID="MyLayer"
            Url="http://gisaprd/ArcGIS/rest/services/BaseMap_ArcReader_Cached/MapServer" />-->
        <!--<esri:ArcGISTiledMapServiceLayer ID="MyLayer"
            Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />-->
        <esri:ArcGISTiledMapServiceLayer ID="Aerials" Url="http://gisaprd/ArcGIS/rest/services/AerialCoordinateTest/MapServer" Visible="False"  />
        <esri:ArcGISDynamicMapServiceLayer Url="http://gisaprd/ArcGIS/rest/services/BaseMapCool__WebViewer/MapServer" />

        <esri:GraphicsLayer ID="TruckGPS" >

            <esri:GraphicsLayer.MapTip>
                <Grid Background="#FFD65555" >
                    <Border BorderBrush="#FFFF0000" BorderThickness="1" CornerRadius="5" />
                    <StackPanel Orientation="Vertical" >
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding [USER_NAME]}" FontWeight="Bold" Foreground="White"  HorizontalAlignment="Left"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding [SYSTIME]}" FontWeight="Bold" Foreground="White"  HorizontalAlignment="Left"/>
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </esri:GraphicsLayer.MapTip>
        </esri:GraphicsLayer>

    </esri:Map>

    <Grid MinWidth="300" HorizontalAlignment="Right" Background="White" VerticalAlignment="Top" Margin="0,15,15,0" >
        <StackPanel Margin="5">
            <TextBlock x:Name="ScreenCoordsTextBlock" 
                HorizontalAlignment="Left" VerticalAlignment="Center" Text="Screen Coords: "
                       TextWrapping="Wrap" />
            <TextBlock x:Name="MapCoordsTextBlock" 
                HorizontalAlignment="Left" VerticalAlignment="Center" Text="Map Coords: " 
                       TextWrapping="Wrap" />
        </StackPanel>
    </Grid>


</Grid>

C#

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();

        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");

        //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");
        }
    }
   
}

}