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

Toggle Provider map on/off

6 Answers 102 Views
Map
This is a migrated thread and some comments may be shown as answers.
Charlie
Top achievements
Rank 2
Charlie asked on 12 Apr 2011, 06:52 PM

We have a RadMap that uses the Bing provider.  We want to allow our users to be able to toggle the map background on and off.  How can we do this?
We have a toggle button for that, here is the (non-working) code:

private void ToggleMapBtn_Click(object sender, System.Windows.RoutedEventArgs e)
{
    this.CustomerMap.Providers.Clear();
    if (this.ToggleMapBtn.IsChecked == true)
    {
        this.CustomerMap.Provider = this.bingProvider;
    }
    else
    {
        this.CustomerMap.Provider = this.emptyProvider;
    }
    this.CustomerDataLayer.Refresh();
}
Thank You.

6 Answers, 1 is accepted

Sort by
0
Accepted
Jason D
Top achievements
Rank 1
Veteran
answered on 13 Apr 2011, 11:26 PM
I would like to know that as well. For now, I've been setting the Opacity to 0.
0
Charlie
Top achievements
Rank 2
answered on 14 Apr 2011, 02:33 PM
Thank you for that simple (hopefully temporary) solution.  
0
Accepted
Andrey
Telerik team
answered on 15 Apr 2011, 06:30 AM
Hello Charlie,

It is a known problem with using of the Clear method. We've fixed this problem already. We added new method RemoveAll to the providers collection. It should be used instead of Clear method. The fix will be available in the 2011.SP1 which will be available soon. 

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
0
Charlie
Top achievements
Rank 2
answered on 15 Apr 2011, 12:19 PM
Thank you for the reply, Andrey.
0
Jason D
Top achievements
Rank 1
Veteran
answered on 24 Mar 2016, 05:44 PM

Bringing this one back. I am not currently subscribed so my last source code is Dec 2014. However the problem still exists even though this problem was found back in 2011.

Clear calls OnCollectionChanged with Reset and null for the oldItems.

RadMap.ProvidersCollectionChanged is checking for oldItems of not null, so Clear does not have the proper effect. Calling Remove on each provider works fine.

There is no RemoveAll listed in the MapProviderCollection.

0
Petar Mladenov
Telerik team
answered on 28 Mar 2016, 02:28 PM
Hi Jason,

The RemoveAll method mentioned by Andrey Murzov is actually an IList extension method residing in Telerik.Windows.Controls.Map.
namespace Telerik.Windows.Controls.Map
{
    /// <summary>
    /// Holds extension methods for <see cref="IList"/> interface.
    /// </summary>
    public static class IListExtensions
    {
        /// <summary>
        /// Removes all items from the list.
        /// As opposed to Clear method raise CollectionChanged event with action Remove and OldItems property set.
        /// </summary>
        /// <param name="list">List to remove objects from.</param>
        public static void RemoveAll(this IList list)
So probably you only need to add the namespace with using in the top section of your file.

Regards,
Petar Mladenov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Map
Asked by
Charlie
Top achievements
Rank 2
Answers by
Jason D
Top achievements
Rank 1
Veteran
Charlie
Top achievements
Rank 2
Andrey
Telerik team
Petar Mladenov
Telerik team
Share this question
or