【问题标题】:UWP mapcontrol AltitudeReferenceSystem not applied to a mapitemUWP mapcontrol AltitudeReferenceSystem 未应用于地图项
【发布时间】:2020-09-25 16:56:48
【问题描述】:

我想将图像添加到 MapControl。这是简单的代码:

<maps:MapControl x:Name="Map"    
    <maps:MapItemsControl x:Name="mapItems">
                    <maps:MapItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <Image Source="{Binding ImageSourceUri}"
                                       Loaded="Image_Loaded"
                                       maps:MapControl.Location="{Binding Location }">
                                    <Image.RenderTransform>
                                        <TransformGroup>
                                            <RotateTransform Angle="{Binding Rotate.Angle}"
                                                             CenterX="{Binding Rotate.CenterX}"
                                                             CenterY="{Binding Rotate.CenterY}"/>
                                            <TranslateTransform X="{Binding Translate.X}"
                                                                Y="{Binding Translate.Y}"/>
                                            <ScaleTransform ScaleX="{Binding Scale.ScaleX}" 
                                                            ScaleY="{Binding Scale.ScaleY}" />
                                        </TransformGroup>
                                    </Image.RenderTransform>
                                </Image>
                            </StackPanel>
                        </DataTemplate>
                    </maps:MapItemsControl.ItemTemplate>
                </maps:MapItemsControl>
    </maps:MapControl>

这是设置ItemSource的相关C#代码:

public class InterestPoint 
    {
        public Uri ImageSourceUri { get; set; }
        public Geopoint Location { get; set; }
        public RotateTransform Rotate { get; set; }
        public TranslateTransform Translate { get; set; }
        public Point CenterPoint { get; set; }
        public ScaleTransform Scale { get; set; }
    }

public sealed partial class MainPage : Page
    {
        private List<InterestPoint> points = new List<InterestPoint>();

        private void Map_Loaded(object sender, RoutedEventArgs e)
        {
            points.Add(new InterestPoint
            {
                ImageSourceUri = new Uri("ms-appx:///Assets/my_position_red.png"),
                Location = new Geopoint(new BasicGeoposition
                {
                    Latitude = 0,
                    Longitude = 0,
                    Altitude = 0
                },
                AltitudeReferenceSystem.Terrain),

                Rotate = new RotateTransform
                {
                    Angle = 00,
                    CenterX = 187 / 2,
                    CenterY = 0
                },
                Translate = new TranslateTransform
                {
                    X = 0,
                    Y = 0
                },
                Scale = new ScaleTransform
                {
                    ScaleX = 0.3,
                    ScaleY = 0.3
                }
            });

            mapItems.ItemsSource = points;
        }
}

这段代码有两个问题:

  • 位置绑定不起作用。我可以设置图像 URI、旋转等,但更改位置不会移动地图中的图像。我已经解决了获取图像对象并直接设置位置,但这并不能解决第二个问题
  • AltitudeReferenceSystem.Terrain 似乎未应用到位置 Geopoint,因此图像似乎不在地形级别,因此放大和缩小似乎在 3D 视图中围绕该点移动。

提前感谢您的任何建议。 斯特凡诺

编辑:我尝试了一些在网上找到的示例,但发现了同样的问题。

这是一张低放大率的图片,您可以看到主干道下方的红点:

放大这是真实的位置,在主干道上方很多:

【问题讨论】:

  • 你还没有为Geopoint属性实现INotifyPropertyChanged接口,当值改变时它不会更新ui。
  • AltitudeReferenceSystem问题请参考本文档备注part
  • 感谢@NicoZhu-MSFT。实施 INotifyPropertyChanged 解决了第一个问题。我很想知道为什么即使没有此修复程序也会更新其他参数。我已按照您的建议阅读了该评论,因此我更新了从 Geolocator 提供的 Geopoint 处理 AltitudeReferenceSystem 的代码,但没有任何改变。
  • 你用其他枚举测试过吗?
  • 你有给 Altitude 特定的值吗?

标签: c# uwp bing-maps


【解决方案1】:

位置绑定不起作用。我可以设置图像 URI、旋转等,但更改位置不会移动地图中的图像。我已经解决了获取图像对象并直接设置位置,但这并不能解决第二个问题

问题是你没有为Geopoint属性实现INotifyPropertyChanged接口,当值改变时它不会更新ui。

AltitudeReferenceSystem.Terrain 似乎没有应用于位置 Geopoint,因此图像似乎不在地形级别,因此放大和缩小似乎在 3D 视图中围绕该点移动。

来源于官方文档remark部分。

地理定位 API 为定位返回返回的高度参考系统可能取决于 GPS/GNSS 无线电硬件。大多数现代硬件将使用大地水准面参考系统提供值,但地图控制 API 将返回椭球系统中的值。要找出 Geopoint 对象正在使用哪一个,请参阅 AltitudeReferenceSystem 属性。不应该复制 BasicGeoposition 而不复制关联的 AltitudeReferenceSystem,否则 Altitude 值将无效并可能产生意外结果。

Location = new Geopoint(new BasicGeoposition
            {
                Latitude = 0,
                Longitude = 0,
                Altitude = 0
            },
            AltitudeReferenceSystem.Terrain),

请注意,您需要使旋转中心与地图中心相匹配。 源自 Stefano Della Valle 解决方案。

在我的例子中,我使用这些 X 和 Y 在图像创建中设置了翻译:

 Translate = new TranslateTransform { X = -55, Y = -45 }, 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    相关资源
    最近更新 更多