You should add this info to documentation

2 posts, 0 answers
  1. Keoz
    Keoz avatar
    1 posts
    Member since:
    Jul 2012

    Posted 31 Jul 2010 Link to this post

    When using the map control and having to add items to an information layer dynamically from code is important that you need to use a  ObservableCollection<FrameworkElement> instead of a List<FrameworkElement>, the list will add the elements to the map as you add it in code but will add frameworkelements in the location you specify and when you move the map the element will move to and not stay at the location specified, this does not happen with ObservableCollection
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 03 Aug 2010 Link to this post

    Hi Jorge,

    Similar to most of the items controls the InformationLayer can use any IEnumerable as items source. The List<FrameworkElement> can be used as well as ObservableCollection<FrameworkElement>. For example, the code below adds few geographically positioned rectangles to the list of the framework elements and then set this list as source for the information layer.

    List<FrameworkElement> source = new List<FrameworkElement>();
      
    for(int i = 0; i < 10; i++)
    {
        Rectangle rect = new Rectangle()
        {
            Width = 50,
            Height = 50,
            Fill = new SolidColorBrush(Colors.Red)
        };
        MapLayer.SetLocation(rect, new Location(i * 2, 0));
        source.Add(rect);
    }
      
    this.informationLayer.ItemsSource = source;

    The rectangles are geographically positioned and when you panning the map they are moved as well so they  always are over the geographical location specified in the code. This is how it should work.

    The only difference between List and ObservableCollection is that ObservableCollection raise collection changed event when you add or remove items. Information layer handle this event and draw new or remove old items.

    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
Back to Top