Windows Phone map.setView()处于纵向模式
本文关键字:于纵 模式 Phone map setView Windows | 更新日期: 2023-09-27 17:59:18
我在Windows Phone的地图上显示了一条路线。现在我想根据地图上绘制的路线调整缩放比例。
我做了以下事情:
this.map.SetView(LocationRectangle.CreateBoundingRectangle(locations));
locations
是一个GeoCoordinate
s的数组。在横向方向,它工作得很好,但当我切换到纵向方向时,它就不工作了。
---编辑---
以下是相关代码:
在我的绘制方法中,它在我的OnLoad方法中被调用,我的位置数组在这里被填充:
double[,] givenCoordinates;
private MapOverlay overlay;
private Microsoft.Phone.Maps.Controls.MapLayer layer = new Microsoft.Phone.Maps.Controls.MapLayer();
private List<GeoCoordinate> locations = new List<GeoCoordinate>();
private void drawMap()
{
try
{
bool centerPosition = false;
for (int i = 0; i < givenCoordinates.GetLength(0); i++)
{
GeoCoordinate tmpCoord;
GeoCoordinate centerPoint = new GeoCoordinate(0, 0);
Image image = new Image();
BitmapImage myImage = new BitmapImage(new Uri(@"Images'pushpin.png", UriKind.Relative));
image.Width = 40;
image.Height = 40;
image.Opacity = 10;
image.Source = myImage;
if (givenCoordinates[i, 0] != 0 && givenCoordinates[i, 1] != 0)
{
tmpCoord = new GeoCoordinate(givenCoordinates[i, 0], givenCoordinates[i, 1]);
if (!centerPosition)
{
centerPoint = new GeoCoordinate(givenCoordinates[i, 0], givenCoordinates[i, 1]);
centerPosition = true;
}
overlay = new MapOverlay
{
GeoCoordinate = tmpCoord,
Content = image,
PositionOrigin = new System.Windows.Point(0.5, 1)
};
layer.Add(overlay);
locations.Add(tmpCoord);
}
}
delMap.Layers.Add(layer);
Microsoft.Phone.Maps.Controls.MapPolyline line = new Microsoft.Phone.Maps.Controls.MapPolyline();
}
catch (Exception ex)
{
MessageBox.Show("Error loading the map!");
MessageBox.Show(ex.Message);
}
}
我在OrientationChanged事件、Loaded事件和单击按钮后调用setView()方法,这样您就可以轻松地将缩放恢复为默认值。代码:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
this.delMap.SetView(LocationRectangle.CreateBoundingRectangle(locations));
}
private void btn_default_zoom_Click(object sender, RoutedEventArgs e)
{
this.delMap.SetView(LocationRectangle.CreateBoundingRectangle(locations));
}
private void PhoneApplicationPage_OrientationChanged_1(object sender, OrientationChangedEventArgs e)
{
delMap.SetView(LocationRectangle.CreateBoundingRectangle(locations));
}
所有这些在横向模式下都能很好地工作,在纵向模式下都不能工作,甚至连按钮点击都不能。
我在调用drawMap 时尝试了您的代码
//just for testing a list of locations
givenCoordinates = new double[3, 2];
givenCoordinates[0, 0] = 23.4896;
givenCoordinates[0, 1] = 12.1392;
givenCoordinates[1, 0] = 23.4835;
givenCoordinates[1, 1] = 12.1794;
givenCoordinates[2, 0] = 23.5153;
givenCoordinates[2, 1] = 12.1516;
drawMap();
await Task.Run(async () =>
{
Thread.Sleep(1);
Dispatcher.BeginInvoke(() =>
{
delMap.SetView(LocationRectangle.CreateBoundingRectangle(locations), MapAnimationKind.Linear);
});
});