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

You should add this info to documentation

1 Answer 68 Views
Map
This is a migrated thread and some comments may be shown as answers.
Keoz
Top achievements
Rank 2
Keoz asked on 31 Jul 2010, 05:58 AM
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

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 03 Aug 2010, 03:21 PM
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
Tags
Map
Asked by
Keoz
Top achievements
Rank 2
Answers by
Andrey
Telerik team
Share this question
or