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

Using ItemTemplateSelector

2 Answers 79 Views
Map
This is a migrated thread and some comments may be shown as answers.
Madison
Top achievements
Rank 1
Madison asked on 11 Jan 2011, 10:10 AM
Hi,

I'm trying to get the ItemTemplateSelector of the InformationLayer to work, and am not succeeding.
Initially I tried creating my layers dynamically in code as I needed them, but even when trying this other ways it does not seem to work.

My template is (I will write more once I get this working)
<DataTemplate x:Key="MapItemDataTemplate"
 <TextBlock Text="Hi"
  telerikMap:MapLayer.Location="{Binding Location}" 
   telerikMap:MapLayer.BaseZoomLevel="{Binding BaseZoomLevel}"
  telerikMap:MapLayer.ZoomRange="{Binding ZoomRange}" /> 
</DataTemplate
My map definition is:
<telerikDataVis:RadMap  x:Name="mapView" ZoomLevel="{Binding Zoom, Mode=TwoWay}" Center="{Binding Center, Mode=TwoWay}"                                
  CenterChanged="LocationRectChangedHandler" ZoomChanged="LocationRectChangedHandler"
   InitializeCompleted="mapView_InitializeCompleted"
   MouseLeftButtonDown="mapView_MouseLeftButtonDown"
   d:IsHidden="True"
     <telerikMap:InformationLayer x:Name="InformationLayer1"   Visibility="Collapsed"
       ItemsSource="{Binding FilteredItems}" /> 
    
</telerikDataVis:RadMap>

My CodeBehind:
public MapView()
        {
            InitializeComponent();
  
            // binding for DataContext (see note on InternalDataContextProperty)
            SetBinding(InternalDataContextProperty, new Binding());
  
            // set provider for maps
            this.mapView.Provider = new Telerik.Windows.Controls.Map.OpenStreetMapProvider();
  
            this.InformationLayer1.ItemTemplateSelector = new MyMapDataTemplateSelector() { mapView = this };
   
        }
  
private void mapView_InitializeCompleted(object sender, EventArgs e)
        {
            this.InformationLayer1.DataContext = (DataContext as IMapViewModel).GetLayer("main");
            this.InformationLayer1.Visibility = Visibility.Visible;
        }

The data context I set contains the FilteredItems property.
Please enlighten me
Thanks
Yaron

2 Answers, 1 is accepted

Sort by
0
Madison
Top achievements
Rank 1
answered on 11 Jan 2011, 10:35 AM

Sorry... forgot the DataTemplateSelector class

public class MyMapDataTemplateSelector : MapSystem.MapDataTemplateSelector
   {
       public MapView mapView { get; set; }
       public override DataTemplate SelectTemplate(object item, DependencyObject container)
       {
           MapItemViewModel mapItem = item as MapItemViewModel;
           if (mapItem == null) return null;
           if (mapItem.ContextObject is PolylineMapItemViewModel)
               return (mapView.Resources["PolylineMapItemDataTemplate"] as DataTemplate);
           if (mapItem.ContextObject is PolygonMapItemViewModel)
               return (mapView.Resources["PolygonMapItemDataTemplate"] as DataTemplate);
           return (mapView.Resources["MapItemDataTemplate"] as DataTemplate);
       }
   }
0
Andrey
Telerik team
answered on 14 Jan 2011, 11:29 AM
Hi Madison,

It is quite difficult to reproduce your situation having just the parts of code you have provided. I am afraid there are many things missing (structure of the data context is unknown, description of the MapItemViewModel class is not provided, etc). I've created small test application which uses as much from your code as I can get, and replace other things with my own. All things seems work just fine. I've attached my sample project to the message. Please, compare it with your own.

Kind regards,
Andrey Murzov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Map
Asked by
Madison
Top achievements
Rank 1
Answers by
Madison
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or