Answered Multiple data service with Pushpins

  • Tuesday, June 05, 2012 1:42 PM
     
     

    How call from two different tables of locations for two different layers?

    I have one layer that shows around 350 locations on it and works fine. I have been trying to create either a second SQL call or a seperate data service.

    I have not figured out how I am supposed to call a second set of pushpin locations for the second layer.

    Any suggestions or if someone else has done this, I would appreciate the assist.

    Thanks, Brian

All Replies

  • Wednesday, June 06, 2012 10:09 AM
    Owner
     
     
    It's not clear what you are trying to do. Are you using a webservice to query data from SQL? Are you then trying to display that data on a MapLayer? Are you trying to bind two different data sets to two different layers?

    http://rbrundritt.wordpress.com

  • Wednesday, June 06, 2012 12:16 PM
     
      Has Code

    Hi Richard, I appologize for not being clear. Too many days with too many things going on...

    Yes, presently I have a Data service that I use to Query an SQL database table with list of locations that does display in a silverlight Map Layer.

    Yes, I want a second Map layer with a different SQL database table with additional locations.

    So, what I am trying to  accomplish is add a second Data Layer, and display the PushPins from the Second laywer in addition to the PushPins from the first layer. Both PushPin sets will have a different color and will hae different info when the Mouseover occurs.

    The Navigation bar I am adding Command buttons to turn on and off layers and filter by State. I will also add a search feature so that I can find the pushpin I need to look at without having to look at all of them.

    Here is my working project;

    I hope this helps better understand what I am trying to do.

    Brian

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    
    namespace Bases.Web
    {
        [ServiceContract(Namespace = "")]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    
        public class DataService
        {
            static readonly string connectionString = ConfigurationManager.ConnectionStrings["PTC"].ConnectionString;
    
            [OperationContract]
            public List<Locations> GetLocations(string selectedItem)
            {
                SqlConnection sqlConnection = new SqlConnection(connectionString);
                DataSet objSet = new DataSet();
                SqlCommand sqlCommand = new SqlCommand();
                sqlCommand.Connection = sqlConnection;
                sqlCommand.CommandText = "GetMapLocationsByState";
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Add("@LocationState", SqlDbType.VarChar).Value = selectedItem;
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
                sqlDataAdapter.SelectCommand = sqlCommand;
                sqlDataAdapter.Fill(objSet);
    
                List<Locations> lstResult = new List<Locations>();
                Locations objLocations;
    
                if (objSet.Tables.Count > 0)
                {
                    foreach (DataRow dr in objSet.Tables[0].Rows)
                    {
                        objLocations = new Locations();
                        objLocations.ID = Convert.ToInt32(dr["ID"]);
                        objLocations.Subdivision = dr["Subdivision"].ToString();
                        objLocations.SiteName = dr["SiteName"].ToString();
                        objLocations.ST = dr["ST"].ToString();
                        objLocations.Status = dr["Status"].ToString();
                        objLocations.Latitude = Convert.ToDouble(dr["Latitude"]);
                        objLocations.Longitude = Convert.ToDouble(dr["Longitude"]);
                        objLocations.Antenna = dr["Antenna"].ToString();
                        objLocations.TwrHeight = dr["TwrHeight"].ToString();
                        objLocations.Azimuth = dr["Azimuth"].ToString();
                        objLocations.Director = dr["Director"].ToString();
                        objLocations.Notes = dr["Notes"].ToString();
                        lstResult.Add(objLocations);
                    }
                }
                return lstResult;
            }
        }
    }
    
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using Microsoft.Maps.MapControl;
    using Microsoft.Maps.MapControl.Navigation;
    
    namespace Bases
    {
        public partial class MainPage : UserControl
        {
            ComboBox cb1 = new ComboBox()
            {
                Height = 18,
                Width = 50,
                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Center
            };
    
            public MainPage()
            {
                InitializeComponent();
                MyMap.MapForeground.TemplateApplied += new EventHandler(MapForeground_TemplateApplied);
            }
    
            void MapForeground_TemplateApplied(object sender, EventArgs e)
            {
                MyMap.MapForeground.NavigationBar.TemplateApplied += new EventHandler(NavigationBar_TemplateApplied);
            }
    
            public void NavigationBar_TemplateApplied(object sender, EventArgs e)
            {
                CommandButton aboutButton = new CommandButton(new MyShowMessageCommand(MyMap, "Train Control CTC Locations Map"), "About", "An Interactive Map for Displaying CTC Bases and Waysides");
                MyMap.MapForeground.NavigationBar.HorizontalPanel.Children.Add(new CommandSeparator());
                MyMap.MapForeground.NavigationBar.HorizontalPanel.Children.Add(aboutButton);
                MyMap.MapForeground.NavigationBar.HorizontalPanel.Children.Add(new CommandSeparator());
                MyMap.MapForeground.NavigationBar.HorizontalPanel.Children.Add(cb1);
                MyMap.MapForeground.NavigationBar.HorizontalPanel.Children.Add(new CommandSeparator());
                cb1.Items.Add(new ComboBoxItem() { Content = "SA", IsSelected = true });
                cb1.Items.Add(new ComboBoxItem() { Content = "AL" });
                cb1.Items.Add(new ComboBoxItem() { Content = "AR" });
                cb1.Items.Add(new ComboBoxItem() { Content = "AZ" });
                cb1.Items.Add(new ComboBoxItem() { Content = "CA" });
                cb1.Items.Add(new ComboBoxItem() { Content = "CO" });
                cb1.Items.Add(new ComboBoxItem() { Content = "ID" });
                cb1.Items.Add(new ComboBoxItem() { Content = "IL" });
                cb1.Items.Add(new ComboBoxItem() { Content = "IA" });
                cb1.Items.Add(new ComboBoxItem() { Content = "KS" });
                cb1.Items.Add(new ComboBoxItem() { Content = "LA" });
                cb1.Items.Add(new ComboBoxItem() { Content = "MN" });
                cb1.Items.Add(new ComboBoxItem() { Content = "MS" });
                cb1.Items.Add(new ComboBoxItem() { Content = "MO" });
                cb1.Items.Add(new ComboBoxItem() { Content = "MT" });
                cb1.Items.Add(new ComboBoxItem() { Content = "NE" });
                cb1.Items.Add(new ComboBoxItem() { Content = "NM" });
                cb1.Items.Add(new ComboBoxItem() { Content = "ND" });
                cb1.Items.Add(new ComboBoxItem() { Content = "OR" });
                cb1.Items.Add(new ComboBoxItem() { Content = "TN" });
                cb1.Items.Add(new ComboBoxItem() { Content = "TX" });
                cb1.Items.Add(new ComboBoxItem() { Content = "SD" });
                cb1.Items.Add(new ComboBoxItem() { Content = "WA" });
                cb1.Items.Add(new ComboBoxItem() { Content = "WI" });
                cb1.Items.Add(new ComboBoxItem() { Content = "WY" });
                MyMap.MapForeground.NavigationBar.HorizontalPanel.Children.Add(new CommandSeparator());
                Bases.DataService.DataServiceClient objCust = new Bases.DataService.DataServiceClient();
                objCust.GetLocationsCompleted += new EventHandler<Bases.DataService.GetLocationsCompletedEventArgs>(GetLocationsCompleted);
                ComboBoxItem cbi = cb1.SelectedItem as ComboBoxItem;
                string selectedValue = cbi.Content.ToString(); objCust.GetLocationsAsync(selectedValue);
                cb1.SelectionChanged += new SelectionChangedEventHandler(Cb1ItemSelected);
            }
    
            public void GetLocationsCompleted(object sender, Bases.DataService.GetLocationsCompletedEventArgs e)
            {
                LocationDataCollection locationList = new LocationDataCollection();
                foreach (Bases.DataService.Locations C in e.Result)
                {
                    LocationData T = new LocationData();
                    T.ID = C.ID;
                    T.Subdivision = C.Subdivision;
                    T.SiteName = C.SiteName;
                    T.ST = C.ST;
                    T.Status = C.Status;
                    T.Location = new Location(C.Latitude, C.Longitude);
                    T.Antenna = C.Antenna;
                    T.TwrHeight = C.TwrHeight;
                    T.Azimuth = C.Azimuth;
                    T.Director = C.Director;
                    T.Notes = C.Notes;
                    locationList.Add(T);
                }
                ListOfItems.ItemsSource = locationList;
            }
    
            private void Cb1ItemSelected(object sender, SelectionChangedEventArgs e)
            {
                Bases.DataService.DataServiceClient objCust = new Bases.DataService.DataServiceClient();
                objCust.GetLocationsCompleted += new EventHandler<Bases.DataService.GetLocationsCompletedEventArgs>(GetLocationsCompleted);
                ComboBoxItem cbi = cb1.SelectedItem as ComboBoxItem;
                string selectedValue = cbi.Content.ToString(); objCust.GetLocationsAsync(selectedValue);
            }
    
            private void MyMap_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
            {
                Point viewportPoint = e.GetPosition(MyMap);
                Location location;
                if (MyMap.TryViewportPointToLocation(viewportPoint, out location))
                {
                    Coords.Text = String.Format("Lat: {0:f4}, Lon: {1:f4}", location.Latitude, location.Longitude);
                }
            }
        }
    }
    
    <UserControl 
        x:Class="Bases.MainPage"
        xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
        mc:Ignorable="d"
        xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" MouseMove="MyMap_MouseMove">
        <UserControl.Resources>
            <DataTemplate x:Key="LogoTemplate">
                <m:Pushpin m:MapLayer.Position="{Binding Location}" Background="OrangeRed">
                    <m:Pushpin.RenderTransform>
                        <ScaleTransform ScaleX=".5" ScaleY=".5" CenterX="17" CenterY="35"/>
                    </m:Pushpin.RenderTransform>
                    <m:Pushpin.Content>
                        <TextBlock x:Name="txtCustId" FontSize="7" Text="{Binding ID}" Margin="2,2,2,2"/>
                    </m:Pushpin.Content>
                    <ToolTipService.ToolTip>
                        <Border MinHeight="40" 
                                MaxHeight="250" 
                                Margin="-10,-5,-10,-5" 
                                MinWidth="150"
    					        Background="WhiteSmoke"
    					        Opacity="1" 
                                VerticalAlignment="Top"
    					        BorderBrush="Black" 
    					        BorderThickness="1"
    					        CornerRadius="10">
                            <StackPanel>
                                <Grid >
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="ID:"  Grid.Column="0" Grid.Row="0" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtID" Grid.Column="1" Grid.Row="0" Text="{Binding ID}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="Subdivision:"  Grid.Column="0" Grid.Row="1" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtSubdivision" Grid.Column="1" Grid.Row="1" Text="{Binding Subdivision}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="SiteName:"  Grid.Column="0" Grid.Row="2" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtSiteName" Grid.Column="1" Grid.Row="2" Text="{Binding SiteName}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="ST:"  Grid.Column="0" Grid.Row="3" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtState" Grid.Column="1" Grid.Row="3" Text="{Binding ST}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="Status:"  Grid.Column="0" Grid.Row="4" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtStatus" Grid.Column="1" Grid.Row="4" Text="{Binding Status}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="Latitude:"  Grid.Column="0" Grid.Row="5" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtLatLocation"  Grid.Column="1" Grid.Row="5"  Text="{Binding Location.Latitude}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="Longitude:" Grid.Column="0" Grid.Row="6" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtLongLocation" Grid.Column="1" Grid.Row="6" Text="{Binding Location.Longitude}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="Antenna:"  Grid.Column="0" Grid.Row="7" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtAntenna" Grid.Column="1" Grid.Row="7" Text="{Binding Antenna}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="Tower Height:"  Grid.Column="0" Grid.Row="8" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtHeight" Grid.Column="1" Grid.Row="8" Text="{Binding TwrHeight}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="Azimuth:"  Grid.Column="0" Grid.Row="9" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtAzimuth" Grid.Column="1" Grid.Row="9" Text="{Binding Azimuth}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="Director:"  Grid.Column="0" Grid.Row="10" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtDirector" Grid.Column="1" Grid.Row="10" Text="{Binding Director}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock Text="Notes:"  Grid.Column="0" Grid.Row="11" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock x:Name="txtNotes" Grid.Column="1" Grid.Row="11" Text="{Binding Notes}" Margin="2,2,2,2"></TextBlock>
                                </Grid>
                            </StackPanel>
                        </Border>
                    </ToolTipService.ToolTip>
                </m:Pushpin>
            </DataTemplate>
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <m:Map CredentialsProvider="BINGMAPKEY"  
                       HorizontalAlignment="Stretch"  
                       LogoVisibility="Collapsed"   
                       VerticalAlignment="Stretch"
                       Mode="AerialWithLabels"
                       x:Name="MyMap"   
                       Grid.Column="0"  
                       Grid.Row="0"  
                       ZoomLevel="5" 
                       Center="38.5, -104.000" 
                       MouseMove="MyMap_MouseMove">
                <m:MapItemsControl x:Name="ListOfItems" ItemTemplate="{StaticResource LogoTemplate}"/>
                <m:MapLayer x:Name="PushPinLayer"/>
            </m:Map>
            <TextBlock Height="16" 
                       Name="Coords" 
                       Text="Lat, Lon" 
                       HorizontalAlignment="Right" 
                       Width="200" 
                       TextAlignment="Right" 
                       Margin="0,5,5,65" 
                       Grid.Row="1" 
                       Foreground="Yellow" 
                       VerticalAlignment="Bottom" 
                       FontWeight="Bold" />
        </Grid>
    </UserControl>
    

    using System;
    using System.Collections;
    using System.Collections.ObjectModel;
    using System.Windows.Media;
    using Microsoft.Maps.MapControl;
    
    namespace Bases
    {
        public class LocationDataCollection : ObservableCollection<LocationData>
        {
            public bool IsDataSource
            {
                get
                {
                    return true;
                }
    
                set
                {
    
                }
            }
    
            public void GetLocationsCompleted(object sender, Bases.DataService.GetLocationsCompletedEventArgs e)
            {
                LocationDataCollection locationList = new LocationDataCollection();
                foreach (Bases.DataService.Locations C in e.Result)
                {
                    LocationData T = new LocationData();
                    T.ID = C.ID;
                    T.Subdivision = C.Subdivision;
                    T.SiteName = C.SiteName;
                    T.ST = C.ST;
                    T.Status = C.Status;
                    T.Location = new Location(C.Latitude, C.Longitude);
                    T.Antenna = C.Antenna;
                    T.TwrHeight = C.TwrHeight;
                    T.Azimuth = C.Azimuth;
                    T.Director = C.Director;
                    T.Notes = C.Notes;
                    locationList.Add(T);
                }
    
                IEnumerator ppEnum = locationList.GetEnumerator();
                while (ppEnum.MoveNext())
                {
                    this.Add((LocationData)ppEnum.Current);
                }
            }
    
            //public void GetWiuLocationsCompleted(object sender, Bases.DataService.GetLocationsCompletedEventArgs e)
            //{
            //    LocationDataCollection WiuList = new LocationDataCollection();
            //    foreach (Bases.DataService.Locations C in e.Result)
            //    {
            //        LocationData T = new LocationData();
            //        T.ID = C.ID;
            //        T.Subdivision = C.Subdivision;
            //        T.SiteName = C.SiteName;
            //        T.ST = C.ST;
            //        T.Status = C.Status;
            //        T.Location = new Location(C.Latitude, C.Longitude);
            //        T.Antenna = C.Antenna;
            //        T.TwrHeight = C.TwrHeight;
            //        T.Azimuth = C.Azimuth;
            //        T.Director = C.Director;
            //        T.Notes = C.Notes;
            //        WiuList.Add(T);
            //    }
    
            //    IEnumerator ppEnum = WiuList.GetEnumerator();
            //    while (ppEnum.MoveNext())
            //    {
            //        this.Add((LocationData)ppEnum.Current);
            //    }
            //}
    
            public class LocationsPushpin : Pushpin
            {
                public Int32 ID { get; set; }
                public String Subdivision { get; set; }
                public String SiteName { get; set; }
                public String ST { get; set; }
                public String Status { get; set; }
                public double Latitude { get; set; }
                public double Longitude { get; set; }
                public String Antenna { get; set; }
                public String TwrHeight { get; set; }
                public String Azimuth { get; set; }
                public String Director { get; set; }
                public String Notes { get; set; }
                public LocationsPushpin(Color bg)
                {
                    this.Name = Guid.NewGuid().ToString();
                    SolidColorBrush scb = new SolidColorBrush(bg);
                    this.Background = scb;
                }
            }
    
            //public class WiuLocationsPushpin : Pushpin
            //{
            //    public Int32 ID { get; set; }
            //    public String Subdivision { get; set; }
            //    public String SiteName { get; set; }
            //    public String ST { get; set; }
            //    public String Status { get; set; }
            //    public double Latitude { get; set; }
            //    public double Longitude { get; set; }
            //    public String Antenna { get; set; }
            //    public String TwrHeight { get; set; }
            //    public String Azimuth { get; set; }
            //    public String Director { get; set; }
            //    public String Notes { get; set; }
            //    public WiuLocationsPushpin(Color bg)
            //    {
            //        this.Name = Guid.NewGuid().ToString();
            //        SolidColorBrush scb = new SolidColorBrush(bg);
            //        this.Background = scb;
            //    }
            //}
        }
    }
    

    using System;
    using System.Collections.ObjectModel;
    using Microsoft.Maps.MapControl;
    
    namespace Bases
    {
        public class LocationData
        {
            public Location Location
            { get; set; }
    
            public String Subdivision
            { get; set; }
    
            public String SiteName
            { get; set; }
    
            public String ST
            { get; set; }
    
            public String Status
            { get; set; }
    
            public Int32 ID
            { get; set; }
    
            public String Antenna
            { get; set; }
    
            public ObservableCollection<LocationData> Locations
            { get; set; }
    
            public LocationData()
            {
                this.Location = new Location();
            }
    
            public String TwrHeight
            { get; set; }
    
            public String Azimuth
            { get; set; }
    
            public String Director
            { get; set; }
    
            public String Notes
            { get; set; }
        }
    }
    

    using System;
    using System.Runtime.Serialization;
    
    namespace Bases.Web
    {
        [DataContract]
        public class Locations
        {
            [DataMember]
            public Int32 ID { get; set; }
    
            [DataMember]
            public String Subdivision { get; set; }
    
            [DataMember]
            public String SiteName { get; set; }
    
            [DataMember]
            public String ST { get; set; }
    
            [DataMember]
            public String Status { get; set; }
    
            [DataMember]
            public double Latitude { get; set; }
    
            [DataMember]
            public double Longitude { get; set; }
    
            [DataMember]
            public String Antenna { get; set; }
    
            [DataMember]
            public String TwrHeight { get; set; }
    
            [DataMember]
            public String Azimuth { get; set; }
    
            [DataMember]
            public String Director { get; set; }
    
            [DataMember]
            public String Notes { get; set; }
        }
    }

    using System.Collections.Generic;
    using System.ServiceModel;
    
    namespace Bases.Web
    {
        [ServiceContract]
        public interface IDataService
        {
            [OperationContract]
            List<Locations> GetLocations();
        }
    }
    

    <?xml version="1.0"?>
    <configuration>
      <appSettings/>
      <connectionStrings>
        <add name="dbSource" connectionString="Data Source=dbserver;Initial Catalog=PTC;Persist Security Info=True;User ID=user;Password=password" providerName="System.Data.SqlClient"/>
      </connectionStrings>
      <system.web>
        <compilation debug="true" targetFramework="4.0">
        </compilation>
        <authentication mode="Windows"/>
        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <customBinding>
            <binding name="Bases.Web.DataService.customBinding0">
              <binaryMessageEncoding/>
              <httpTransport/>
            </binding>
          </customBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
        <services>
          <service name="Bases.Web.DataService">
            <endpoint address="" binding="customBinding" bindingConfiguration="Bases.Web.DataService.customBinding0" contract="Bases.Web.DataService"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
      </system.serviceModel>
    </configuration>
    



  • Thursday, June 07, 2012 9:59 AM
    Owner
     
     Answered
    How about adding two MapLayer objects as children of the map and adding a MapItemControl in each MapLayer. You will need to give each MapItemControl a unbique name and populate each control accordingly in your GetLocationsCompleted method.

    http://rbrundritt.wordpress.com

  • Thursday, June 07, 2012 1:10 PM
     
      Has Code

    That is wath I was thinking. With that in mind, do I assume then that I need a new Locations class with a different name, or do I just add into the original? Then the same questions for the LocationData, LocationDataCollection classes.

    Do I need/Should I create a second DataService?

    OK, here is how I did the DataService.cs;

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    
    namespace Bases.Web
    {
        [ServiceContract(Namespace = "")]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    
        public class DataService
        {
            static readonly string connectionString = ConfigurationManager.ConnectionStrings["PTC"].ConnectionString;
    
            [OperationContract]
            public List<Locations> GetLocations(string selectedItem)
            {
                SqlConnection sqlConnection = new SqlConnection(connectionString);
                DataSet objSet = new DataSet();
                SqlCommand sqlCommand = new SqlCommand();
                sqlCommand.Connection = sqlConnection;
                sqlCommand.CommandText = "GetMapLocationsByState";
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Add("@LocationState", SqlDbType.VarChar).Value = selectedItem;
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
                sqlDataAdapter.SelectCommand = sqlCommand;
                sqlDataAdapter.Fill(objSet);
    
                List<Locations> lstResult = new List<Locations>();
                Locations objLocations;
    
                if (objSet.Tables.Count > 0)
                {
                    foreach (DataRow dr in objSet.Tables[0].Rows)
                    {
                        objLocations = new Locations();
                        objLocations.ID = Convert.ToInt32(dr["ID"]);
                        objLocations.Subdivision = dr["Subdivision"].ToString();
                        objLocations.SiteName = dr["SiteName"].ToString();
                        objLocations.ST = dr["ST"].ToString();
                        objLocations.Status = dr["Status"].ToString();
                        objLocations.Latitude = Convert.ToDouble(dr["Latitude"]);
                        objLocations.Longitude = Convert.ToDouble(dr["Longitude"]);
                        objLocations.Antenna = dr["Antenna"].ToString();
                        objLocations.TwrHeight = dr["TwrHeight"].ToString();
                        objLocations.Azimuth = dr["Azimuth"].ToString();
                        objLocations.Director = dr["Director"].ToString();
                        objLocations.Notes = dr["Notes"].ToString();
                        lstResult.Add(objLocations);
                    }
                }
                return lstResult;
            }
    
            [OperationContract]
            public List<WiuLocations> GetWiuLocations(string selectedItem)
            {
                SqlConnection sqlConnection = new SqlConnection(connectionString);
                DataSet objSet = new DataSet();
                SqlCommand sqlCommand = new SqlCommand();
                sqlCommand.Connection = sqlConnection;
                sqlCommand.CommandText = "GetWiuLocationsByState";
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Add("@LocationState", SqlDbType.VarChar).Value = selectedItem;
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
                sqlDataAdapter.SelectCommand = sqlCommand;
                sqlDataAdapter.Fill(objSet);
    
                List<WiuLocations> lstResult = new List<WiuLocations>();
                WiuLocations objLocations;
    
                if (objSet.Tables.Count > 0)
                {
                    foreach (DataRow dr in objSet.Tables[0].Rows)
                    {
                        objLocations = new WiuLocations();
                        objLocations.WiuID = Convert.ToInt32(dr["WiuID"]);
                        objLocations.Subdivision = dr["Subdivision"].ToString();
                        objLocations.LS = dr["LS"].ToString();
                        objLocations.MilePost = dr["MilePost"].ToString();
                        objLocations.TmdsCl = dr["TmdsCl"].ToString();
                        objLocations.SiteName = dr["SiteName"].ToString();
                        objLocations.ST = dr["ST"].ToString();
                        objLocations.AtcsAddress = dr["AtcsAddress"].ToString();
                        objLocations.Latitude = Convert.ToDouble(dr["Latitude"]);
                        objLocations.Longitude = Convert.ToDouble(dr["Longitude"]);
                        objLocations.Antenna = dr["Antenna"].ToString();
                        objLocations.TwrHeight = dr["TwrHeight"].ToString();
                        objLocations.Azimuth = dr["Azimuth"].ToString();
                        objLocations.SignalDirector = dr["ST"].ToString();
                        objLocations.TelecomDirector = dr["Director"].ToString();
                        objLocations.Notes = dr["Notes"].ToString();
                        lstResult.Add(objLocations);
                    }
                }
                return lstResult;
            }
        }
    }
    

    And I have the WiuLocationDataCollection.cs like this, which when compiled returns the error;

    Cannot confert type 'Bases.DataService.Locations to Bases.DataService.WiuLocations.

    Not sure where to go from here.

    Thanks,

  • Thursday, June 07, 2012 2:02 PM
    Owner
     
     
    You can probaubly reuse just about everything that's there, just set the ItemSource of a different MapItemControl

    http://rbrundritt.wordpress.com

  • Thursday, June 07, 2012 4:43 PM
     
     

    I am not sure where you are saying to reuse. The ItemSource in the XML, I don't have an issue with creating. The Codebehind is where I am stuck.

    Can you provide a snip of what you mean on the codebehind?

    Thanks,

  • Thursday, June 07, 2012 5:45 PM
    Owner
     
     Answered Has Code

    In the following code block:

     public void GetLocationsCompleted(object sender, Bases.DataService.GetLocationsCompletedEventArgs e)
            {
                LocationDataCollection locationList = new LocationDataCollection();
                foreach (Bases.DataService.Locations C in e.Result)
                {
                    LocationData T = new LocationData();
                    T.ID = C.ID;
                    T.Subdivision = C.Subdivision;
                    T.SiteName = C.SiteName;
                    T.ST = C.ST;
                    T.Status = C.Status;
                    T.Location = new Location(C.Latitude, C.Longitude);
                    T.Antenna = C.Antenna;
                    T.TwrHeight = C.TwrHeight;
                    T.Azimuth = C.Azimuth;
                    T.Director = C.Director;
                    T.Notes = C.Notes;
                    locationList.Add(T);
                }
                ListOfItems.ItemsSource = locationList;
            }
    
    
    You are binding your list of locations to the MapItemControl called ListOfItems. Create a second MapItemControl in a different MapLayer and set the ItemSource for the second data source to this other MapItemControl.

    http://rbrundritt.wordpress.com

  • Friday, June 08, 2012 1:19 PM
     
     

    Ding the light goes on! Now I understand. Why is it the simple things that are the hardest to grasp...

    Thanks Richard, that cleared it up for me. Appreciate your time.

    Brian