I'm using RadMap in an MVVM pattern, so I'm not able to get a reference to the map or the InformationLayer so that I can get the best possible LocationRect based on information in the view as mentioned in the first response in this thead:
http://www.telerik.com/community/forums/wpf/map/how-to-get-best-possible-map-view-when-considering-all-poi-s.aspx
I attempted to use the second approach (the method posted at the end of the post), but it too is giving me some problems. I'm able to get a LocationRect, but I'm not able to call the SetView method to center/zoom the map appropriately.
I created properties in my view model for center and zoom. The MapCenter property seems to be working fine, but I'm having a hard time with the zoom property.
The problem is the LocationRect.ZoomLevel property isn't set and I don't know how to set it without having more information from the map, itself.
For reference, here is the method posted in the original thread:
http://www.telerik.com/community/forums/wpf/map/how-to-get-best-possible-map-view-when-considering-all-poi-s.aspx
I attempted to use the second approach (the method posted at the end of the post), but it too is giving me some problems. I'm able to get a LocationRect, but I'm not able to call the SetView method to center/zoom the map appropriately.
I created properties in my view model for center and zoom. The MapCenter property seems to be working fine, but I'm having a hard time with the zoom property.
List<Telerik.Windows.Controls.Map.Location> locations =
this
.MyPushpins.Select(pin => pin.Location).ToList();
LocationRect rect = this.GetBestView(locations,
new
Size(0.01, 0.01));
MapCenter = rect.Center;
MapZoomLevel = rect.ZoomLevel;
The problem is the LocationRect.ZoomLevel property isn't set and I don't know how to set it without having more information from the map, itself.
For reference, here is the method posted in the original thread:
public
LocationRect GetBestView(IEnumerable<PointOfInterest> itemsList, Size defaultSize)
{
LocationRect bestView =
new
LocationRect();
Location northEast = Location.Empty;
Location southWest = Location.Empty;
foreach
(PointOfInterest item
in
itemsList)
{
Location location = item.Location;
if
(northEast.IsEmpty)
{
northEast = location;
}
else
{
if
(!location.IsEmpty)
{
northEast.Latitude = Math.Max(northEast.Latitude, location.Latitude);
northEast.Longitude = Math.Max(northEast.Longitude, location.Longitude);
}
}
if
(southWest.IsEmpty)
{
southWest = location;
}
else
{
if
(!location.IsEmpty)
{
southWest.Latitude = Math.Min(southWest.Latitude, location.Latitude);
southWest.Longitude = Math.Min(southWest.Longitude, location.Longitude);
}
}
}
if
(!northEast.IsEmpty && !southWest.IsEmpty)
{
bestView =
new
LocationRect(northEast, southWest);
if
(bestView.IsEmpty)
{
bestView =
new
LocationRect(
new
Location(bestView.North + defaultSize.Height / 2.0, bestView.West - defaultSize.Width / 2.0),
new
Location(bestView.North - defaultSize.Height / 2.0, bestView.West + defaultSize.Width / 2.0));
}
}
return
bestView;
}