MVVM and Information Layer

5 posts, 0 answers
  1. Joshua Ault
    Joshua Ault avatar
    7 posts
    Member since:
    Mar 2010

    Posted 14 Apr 2010 Link to this post

    Hello:

    I just have a quick question. I am following the MVVM model and I am running into a problem with displaying an information layer. I have an ObservableCollection of locations. For each location I am adding a pinpoint to an information layer. My question is, how do I get this InformationLayer to display on the map after I have added the pinpoints to it, following MVVM.

    Thank You
    Josh
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 16 Apr 2010 Link to this post

    Hello Joshua,

    We are aware about this problem with information layer. It will be fixed in 2010.Q1 SP1.
    As workaround you can call the informationLayer.InvalidateArrange() method.

    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.
  3. DevCraft banner
  4. Sorin Mecu
    Sorin Mecu avatar
    10 posts
    Member since:
    Jan 2010

    Posted 19 May 2010 Link to this post

    Because InformationLayer derives from MapLayer you can use attached properties like so:

    ...
    <DataTemplate >
                <Grid  
                            layers:MapLayer.BaseZoomLevel="{Binding Path=BaseZoomLevel}"
                            layers:MapLayer.Location="{Binding Path=PinPointLocation}"
                            layers:MapLayer.ZoomRange="{Binding Path=ZoomRangeVisibility}" >

    ...

    Where your pinPoint have 3 properties with the same name like the ones from InformationLayer ( you can change them )
  5. Pete
    Pete avatar
    67 posts
    Member since:
    Sep 2012

    Posted 12 May 2011 Link to this post

    Has this problem been solved? I am unable to get binding to the information layer to work using MVVM.

    If I add items in code behind (this.informationLayer.Items.Add(location)) it works.
    If I bind to the ItemsSource and add items to the LocationCollection that it is bound to, then nothing shows.
    <telerik:InformationLayer x:Name="informationLayer" ItemsSource="{Binding Items}">
                    <telerik:InformationLayer.DataMappings>
                        <telerik:DataMapping FieldName="Location" ValueMember="Location" />
                    </telerik:InformationLayer.DataMappings>
                    <telerik:InformationLayer.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Ellipse
                                telerik:MapLayer.Location="{Binding}"
                                ToolTipService.ToolTip="{Binding Description}"
    ....
    private LocationCollection _items;
            private LocationCollection Items
            {
                get
                {
                    return _items;
                }
                set
                {
                    _items = value;
                    OnPropertyChanged("Items");
                }
            }
  6. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 17 May 2011 Link to this post

    Hi XamlmaX,

    The problem has been fixed in the 2010 Q3. The data binding works fine with latest build of the RadMap control. You can see how it can be done here:

    http://demos.telerik.com/silverlight/#Map/DataBinding

    Unfortunately your code snippets do not provide enough information about how you have implemented it. But I see a couple of possible problems in your XAML:

    1. Data mapping you are using will not work because the Location object does not have a property or field with name 'Location'. Actually you do not need data mapping at all in this scenario.

    2. Since your data objects are Locations it is not necessary to specify binding for MapLayer.Location attachable property in the data template. But if you are using it the telerik:MapLayer.Location="{Binding}" must be defined in the TOP level element in the data template (Grid in your case).

    Here it is code for simple implementation of the collection binding within MVVM (it adds new locations on mouse click):

    public class RadMapDataModel : INotifyPropertyChanged
    {
        private LocationCollection items;
      
        public RadMapDataModel()
        {
            this.Items = new LocationCollection();
        }
      
        public LocationCollection Items
        {
            get
            {
                return this.items;
            }
            set
            {
                this.items = value;
                OnPropertyChanged("Items");
            }
        }
      
        public event PropertyChangedEventHandler PropertyChanged;
      
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    <UserControl x:Class="ShowPinPointsCS.MainPage"
         mc:Ignorable="d"
         d:DesignHeight="300" d:DesignWidth="400">
      
        <UserControl.Resources>
            <DataTemplate x:Key="Ellipse">
                <Grid telerik:MapLayer.Location="{Binding}"
                      telerik:MapLayer.HotSpot="0.5,0.5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="14" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Ellipse Width="14"
                         Height="14"
                         Fill="Red" />
                </Grid>
            </DataTemplate>
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White">
            <telerik:RadMap x:Name="radMap" 
                    Center="37.7,2.2"
                    ZoomLevel="8"
                    MapMouseClick="AddLocationToCollection">
                <telerik:RadMap.Provider>
                    <telerik:OpenStreetMapProvider />
                </telerik:RadMap.Provider>
                <telerik:InformationLayer x:Name="informationLayer" 
                              ItemsSource="{Binding Items}"
                              ItemTemplate="{StaticResource Ellipse}" />
            </telerik:RadMap>
        </Grid>
    </UserControl>

    private void AddLocationToCollection(object sender, MapMouseRoutedEventArgs eventArgs)
    {
        this.dataModel.Items.Add(eventArgs.Location);
    }


    Greetings,
    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
Back to Top
DevCraft banner