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

GetBestView incorrect ZoomLevel

4 Answers 116 Views
Map
This is a migrated thread and some comments may be shown as answers.
Jakub
Top achievements
Rank 1
Jakub asked on 03 Feb 2012, 12:18 PM
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

4 Answers, 1 is accepted

Sort by
0
Jakub
Top achievements
Rank 1
answered on 03 Feb 2012, 01:03 PM
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.
0
Andrey
Telerik team
answered on 08 Feb 2012, 09:09 AM
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 >>

0
Jakub
Top achievements
Rank 1
answered on 20 Apr 2012, 09:41 AM
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
0
Accepted
Andrey
Telerik team
answered on 25 Apr 2012, 08:02 AM
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 >>

Tags
Map
Asked by
Jakub
Top achievements
Rank 1
Answers by
Jakub
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or