I think I have come up with a solution:
Private
Sub
MainWindow_SizeChanged(
ByVal
sender
As
Object
,
ByVal
e
As
System.Windows.SizeChangedEventArgs)
Handles
Me
.SizeChanged
SetCenterAndZoomByRectangle()
End
Sub
Private
Sub
SetCenterAndZoomByRectangle()
Dim
oImage =
New
BitmapImage(
New
Uri(
"pack://application:,,,"
+ UriImageProvider1.Uri.OriginalString))
Dim
wNwLatitude = (1 - (oImage.Height / oImage.Width)) / 2
Dim
wSeLatitude = -1 * (1 - wNwLatitude)
wNwLatitude = wNwLatitude * -1
Dim
leftTop
As
New
Location(wNwLatitude, 0)
Dim
rightBottom
As
New
Location(wSeLatitude, 1)
Dim
centerLocation
As
Location =
New
Location((leftTop.Latitude + rightBottom.Latitude) / 2, (leftTop.Longitude + rightBottom.Longitude) / 2)
radMap.GeoBoundsNW = leftTop
radMap.GeoBoundsSE = rightBottom
radMap.Center = centerLocation
Dim
leftTopPoint
As
Point = radMap.SpatialReference.GeographicToLogical(leftTop)
Dim
rightBottomPoint
As
Point = radMap.SpatialReference.GeographicToLogical(rightBottom)
Dim
viewportWidth
As
Double
= rightBottomPoint.X - leftTopPoint.X
Dim
viewportHeight
As
Double
= rightBottomPoint.Y - leftTopPoint.Y
Dim
proportionalWidth
As
Double
= viewportWidth / radMap.ActualWidth
Dim
proportionalHeight
As
Double
= viewportHeight / radMap.ActualHeight
Dim
tileSize
As
Double
= (oImage.Width / oImage.Height) * 119
If
(proportionalWidth > proportionalHeight)
Then
radMap.ZoomLevel = Convert.ToInt32(Math.Log(radMap.ActualWidth / tileSize / viewportWidth, 2D))
radMap.MinZoomLevel = Convert.ToInt32(Math.Log(radMap.ActualWidth / tileSize / viewportWidth, 2D))
Else
radMap.ZoomLevel = Convert.ToInt32(Math.Log(radMap.ActualHeight / tileSize / viewportHeight, 2D))
radMap.MinZoomLevel = Convert.ToInt32(Math.Log(radMap.ActualHeight / tileSize / viewportHeight, 2D))
End
If
End
Sub
My only concern is with the tileSize formula. In previous posts it was always hard coded to 256. My formula appears to be working, but wasn't sure if I was overlooking something. Not really sure why a constant of 119 causes everything to work.
Thanks,
Seth