c# - 纵向模式下的 Windows Phone map.setView()

标签 c# windows-phone-8

我在 Windows Phone 的 map 上显示了一条路线。现在我想根据 map 上绘制的路线进行缩放。

我做了以下事情:

this.map.SetView(LocationRectangle.CreateBoundingRectangle(locations));

locations 是一个 GeoCoordinate 数组。在横向模式下它工作得很好,但当我切换到纵向模式时它就不行了。

---编辑---

相关代码如下:

在我的 OnLoad-Method 中调用的绘制方法中,我的位置数组在此处填充:

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);
    });
});

关于c# - 纵向模式下的 Windows Phone map.setView(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23223633/

相关文章:

windows-phone-7 - 用于 Windows Phone 开发的 FFmpeg

c# - 使用嵌套异步调用锁定

c# - 如何读取.Doc模板文件并使用值编辑模板?

c# - 在 RavenDB 中加密和解密索引字段

c# - Visual Studio : [CS0433] type Func<T, TResult> 存在于 <System.Core (3.5.0.0)> 和 <mscorlib (4.0.0.0)> 中

c# - Windows Phone 8中BitmapImage/Image控件的内存消耗

c# - Windows Phone 8 中应用程序栏的本地化

c# - 菜鸟 WPF 数据绑定(bind) - 为什么我的 DataGrid 不自动生成列?

c# - MarshalByRefType

javascript - Windows 手机 8 : CSS orientation not recognized