Reputation: 2596
Right now my application reads an XML with latitude and longitude nodes (7k of locations). With the slider user can select what nodes he wants to display on the map. Now, everytime that the ValueChanged the following code will execute:
foreach (HueDataClass dataClass in plotThumbList)
{
Pushpin Lamp = new Pushpin();
Lamp.Location = new Microsoft.Maps.MapControl.WPF.Location(dataClass.Lat, dataClass.Lon);
hueMap.Children.Add(Lamp);
}
Sometimes the application freezes for a second and then displays all the Pushpins.. How could I boost the performance?
Kind regards, Niels
Upvotes: 0
Views: 670
Reputation: 128062
Instead of manually adding Pushpins to a MapLayer you should use a MapItemsControl and bind its ItemsSource property to an ObservableCollection of your data item.
<Window.Resources>
<DataTemplate x:Key="MapItemDataTemplate">
<m:Pushpin Location="{Binding ...}" ... />
</DataTemplate>
<local:DataItemsCollection x:Key="DataItems"/>
</Window.Resources>
<m:Map ... >
<map:MapItemsControl
ItemTemplate="{StaticResource MapItemDataTemplate}"
ItemsSource="{Binding Source={StaticResource DataItems}}"/>
</m:Map>
See also the Examples section in ItemsSource and the links in there for how to bind to collections.
Upvotes: 3
Reputation: 269
I think you should try to thread your application. Execute the code that add pushpins in a separate thread.
Here is some resources : http://msdn.microsoft.com/en-us/library/dd460717.aspx
http://msdn.microsoft.com/en-us/library/dd235678.aspx
You will have to deal with the fact that you can't udpate the UI thread from another thread. I know you have to play with InvokeRequired in WinForms, but I don't know for WPF.
Upvotes: 0