This is a migrated thread and some comments may be shown as answers.

RadMap with ListBox of Locations

1 Answer 94 Views
Map
This is a migrated thread and some comments may be shown as answers.
Kurt
Top achievements
Rank 1
Kurt asked on 11 Oct 2010, 04:50 AM
Hi,

I'm trying to get a slight variation on one of your demos working, but I'm somewhat stumped.  I'm returning a description, latiitude and longitude list and while it is adding the Location objects to the list box (it moves to them when they are clicked on), the description is left blank.  Any ideas why my code is not working?  By the way, I tried figuring out my problem in the documentation, but since it is all in C#, it's useless.  Thanks ahead.

Private Sub DoIT(ByVal sender As Object, ByVal e As ProjectsListCompletedEventArgs)
        Dim providerMode As MapMode = MapMode.Aerial
        Dim isLabelVisible As Boolean = True
        Dim provider As MapProviderBase
        provider = New BingMapProvider(providerMode, isLabelVisible, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
 
        With RadMap1
            .ZoomBarVisibility = Windows.Visibility.Collapsed
            .DistanceUnit = DistanceUnit.Mile
            .NavigationVisibility = Windows.Visibility.Collapsed
            .ScaleVisibility = Windows.Visibility.Collapsed
            .CommandBarVisibility = Windows.Visibility.Collapsed
            .Provider = provider
        End With
 
        For Each result In e.Result
            Dim pinPoint As MapPinPoint = New MapPinPoint
            With pinPoint
                .Background = New SolidColorBrush(Colors.White)
                .Foreground = New SolidColorBrush(Colors.Blue)
                .FontSize = 10
                .Text = result.ProjectName
            End With
 
            MapLayer.SetLocation(pinPoint, New Location(result.ProjectLat, result.ProjectLong))
            Me.InformationLayer.Items.Add(pinPoint)
 
            '*****Location works but description is not shown for some reason*********
            Dim loc As New Location
            With loc
                .Description = "TEST"
                .Latitude = result.ProjectLat
                .Longitude = result.ProjectLong
            End With
 
            ProjectBox.Items.Add(loc)
        Next
 
        '*****Displays name, but of course, location doesn't work*********
        'ProjectBox.ItemsSource = e.Result
        'ProjectBox.DisplayMemberPath = "ProjectName"
    End Sub

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 13 Oct 2010, 01:00 PM
Hi Kurt,

You didn't provide your XAML, but I can assume that you didn't use any DataTemplate for items in your ListBox. By default ListBox control uses string representation of the object (result of the ToString() call) added to the items collection. The ToString() method of the Location class returns values of the Latitude and Longitude properties only. So you don't see any description there. You have to specify data template which will be used by ListBox to represent Location items. For example:

<UserControl x:Class="Telerik.RadMap.Silverlight.VB.MainPage"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             Width="600" Height="400">
    <UserControl.Resources>
        <DataTemplate x:Key="ProjectItemTemplate">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
  
                <TextBlock Grid.Row="0" 
                           Grid.Column="0" 
                           Text="Latitude:" />
                <TextBlock Grid.Row="0" 
                           Grid.Column="1" 
                           Text="{Binding Path=Latitude}" />
  
                <TextBlock Grid.Row="1" 
                           Grid.Column="0" 
                           Text="Longitude:" />
                <TextBlock Grid.Row="1" 
                           Grid.Column="1" 
                           Text="{Binding Path=Longitude}" />
  
                <TextBlock Grid.Row="2" 
                           Grid.Column="0" 
                           Text="Description:" />
                <TextBlock Grid.Row="3" 
                           Grid.Column="1" 
                           Text="{Binding Path=Description}" />
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <telerik:RadMap x:Name="RadMap1">
            <telerik:RadMap.Provider>
                <telerik:OpenStreetMapProvider />
            </telerik:RadMap.Provider>
            <telerik:InformationLayer  Name="informationLayer">
            </telerik:InformationLayer>
        </telerik:RadMap>
  
        <ListBox Name="ProjectBox" 
                 Grid.Column="1" 
                 Width="200"
                 ItemTemplate="{StaticResource ProjectItemTemplate}"></ListBox>
    </Grid>
</UserControl>


Kind regards,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Map
Asked by
Kurt
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or