GetBestView incorrect ZoomLevel

5 posts, 1 answers
  1. Jakub
    Jakub avatar
    5 posts
    Member since:
    Apr 2011

    Posted 03 Feb 2012 Link to this post

    Hi,

    I am using the sample code to get the best view of  items in my map. It works fine for the first time, but when I leave the page where the map is and then return back I am getting incorrect zoom level (negative large number).
    The only difference between these two calls of the method is the zoom level of the map. First time it is, as just being initialized, one, but second time it remains set as it was for the best view and the new zoom level is calculated incorrectly. I tried to put a breakpoint inside of the method and when hit I changed the zoomlevel of the map back to 1 before it is assigned to rect.MapControl. New zoom level was calculated correctly.
    What is the reason for this behaviour?
    Code used is bellow. No chages made in the layer between two OnLoaded events.

    void InformationLayer_WPTs_Loaded(object sender, RoutedEventArgs e)
        {
          LocationRect rect = this.InformationLayer_WPTs.GetBestView(this.InformationLayer_WPTs.Items);
          rect.MapControl = this.radMap;
          this.radMap.Center = rect.Center;
          this.radMap.ZoomLevel = rect.ZoomLevel;
        }

    Thanks,

    Jakub
  2. Jakub
    Jakub avatar
    5 posts
    Member since:
    Apr 2011

    Posted 03 Feb 2012 Link to this post

    Update to my post:
    Changing map zoomlevel back to 1 helps only when debugging and changing it from debugger. I tried to change it back when unloading the layer and it did not help.
    Also, when I want to display another map (using MVVM and the map is in UserControl which is reused), the zoomlevel is incorrect even the first time.
  3. DevCraft banner
  4. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 08 Feb 2012 Link to this post

    Hi Jakub,

    It is very complicated and it is hard to reproduce the problem without your solution, but using just the code snippet you sent. Usually this problem occurs when the map control is not rendered or when the items of the layer are not rendered completely, because the best view calculation is performed using real size of elements which are in the layer.
    Also we already have a PITS issue regarding the best view calculation from different initial zoom levels. You can check when this feature will be available using the following link:
    http://www.telerik.com/support/pits.aspx#/public/silverlight/5248

    Greetings,
    Andrey Murzov
    the Telerik team

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

  5. Jakub
    Jakub avatar
    5 posts
    Member since:
    Apr 2011

    Posted 20 Apr 2012 Link to this post

    Hi,

    just now I found a solution/workaround.
    Instead of using the recommended approach, I implemented this in Loaded handler of the InformationLayer:

    private void InformationLayer_Loaded(object sender, RoutedEventArgs e)
    {
       InformationLayer informationLayer = sender as InformationLayer
       informationLayer.Dispatcher.BeginInvoke(() => { GetBestView(); });
    }

    GetBestView() method is implementing the code to get best view of the Layer.

    Jakub
  6. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 25 Apr 2012 Link to this post

    Hello Jakub,

    It is a possible way which sometimes can be used for RadMap applications. When you use databinding to the InformationLayer.ItemsSource or similar functionality then the rendering of information layer could not be completed in the Loaded event. But this can be completed when the Dispatcher invokes the Best View functionality.

    Kind regards,
    Andrey Murzov
    the Telerik team

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

Back to Top
DevCraft banner