BingMapProvider and Unpinned RadPane

3 posts, 1 answers
  1. Alex Fioletov
    Alex Fioletov avatar
    7 posts
    Member since:
    Jul 2009

    Posted 04 Nov 2011 Link to this post

    Good afternoon,

    I have an issue with map control and Bing provider. Map is located in RadPane that is unpinned on start.
    When pane is open there are no tiles, the map is just empty.

    If you pin the pane and reset provider to map control you'll see the map. But unpin it again and change provider - map disappears again.

    Can you suggest any workaround for this issue?

    I put sample solution here https://a1optimize.accellos.com/MapinPane.rar
    Just change VE key in code to reproduce issue.

    Best regards,
    Alex Fioletov
  2. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 09 Nov 2011 Link to this post

    Hi Alex Fioletov,

    Thank you for the sample solution.
    We have reproduced the problem. When the map control is used inside the RadPane that is unpinned on start then at start it is loaded and then it is unloaded very quickly. The map control cannot initialize the map provider correctly in this case.
    I would recommend to use the Loaded and Unloaded events to set the map provider. The sample code is below.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Telerik.Windows.Controls.Map;
     
    namespace Map_in_Pane
    {
        public partial class MainPage : UserControl
        {
            const string VEKey = "YOUR VE KEY";
     
            BingMapProvider bing = new BingMapProvider(MapMode.Road, true, VEKey);
            OpenStreetMapProvider osm = new OpenStreetMapProvider();
     
            MapProviderBase currentProvider;
     
            bool firstInitialize;
     
            public MainPage()
            {
     
                InitializeComponent();
     
                currentProvider = bing;
     
                radMap.Unloaded += new RoutedEventHandler(radMap_Unloaded);
                radMap.Loaded += new RoutedEventHandler(radMap_Loaded);
            }
     
            private void radMap_Unloaded(object sender, RoutedEventArgs e)
            {
                if (!firstInitialize)
                {
                    radMap.Provider = null;
                    firstInitialize = true;
                }
            }
     
            private void radMap_Loaded(object sender, RoutedEventArgs e)
            {
                // set current provider
                radMap.Provider = currentProvider;
            }
     
            private void CheckBox_Checked(object sender, RoutedEventArgs e)
            {
                currentProvider = bing;
                this.UpdateProvider();
            }
     
            private void UpdateProvider()
            {
                // set current provider if the RadMap is displayed
                if (radMap.ActualWidth > 0)
                {
                    radMap.Provider = currentProvider;
                }
            }
     
            private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
            {
                currentProvider = osm;
                this.UpdateProvider();
            }
        }
    }

    Best wishes,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Alex Fioletov
    Alex Fioletov avatar
    7 posts
    Member since:
    Jul 2009

    Posted 09 Nov 2011 Link to this post

    Спасибо! :)
Back to Top