Toggle Provider map on/off

7 posts, 2 answers
  1. Charlie
    Charlie avatar
    32 posts
    Member since:
    Aug 2010

    Posted 12 Apr 2011 Link to this post

    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.
  2. Answer
    Jason D
    Jason D avatar
    72 posts
    Member since:
    Jan 2011

    Posted 13 Apr 2011 Link to this post

    I would like to know that as well. For now, I've been setting the Opacity to 0.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Charlie
    Charlie avatar
    32 posts
    Member since:
    Aug 2010

    Posted 14 Apr 2011 Link to this post

    Thank you for that simple (hopefully temporary) solution.  
  5. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 15 Apr 2011 Link to this post

    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
  6. Charlie
    Charlie avatar
    32 posts
    Member since:
    Aug 2010

    Posted 15 Apr 2011 Link to this post

    Thank you for the reply, Andrey.
  7. Jason D
    Jason D avatar
    72 posts
    Member since:
    Jan 2011

    Posted 24 Mar Link to this post

    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.

  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 28 Mar Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready