UWP mapcontrol AltitudeReferenceSystem 未应用于 mapitem
UWP mapcontrol AltitudeReferenceSystem not applied to a mapitem
我想将图像添加到 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 视图中围绕该点移动。
提前感谢您的任何建议。
斯特凡诺
编辑:我试过在网上找到的一些示例,我发现了同样的问题。
这是一张低倍率的图片,您可以看到主干道下方的红点:
缩放这是真实位置,在主干道上方很多:
Location binding doesn't work. I can set the image URI, rotation, ect., but changing the location do not move the image in the map. I've solved getting the image object and setting directly the location, but this not solve the second issue
问题是你没有为Geopoint
属性实现INotifyPropertyChanged
接口,当值改变时它不会更新ui。
the AltitudeReferenceSystem.Terrain seems not applied the to the location Geopoint so the image appears to be not at terrain level so zooming in and out seems to move around the point as in a 3D view.
来源于官方文档remark部分。
The altitude reference system that is returned for location fixes from the geolocation API may depend on the GPS/GNSS radio hardware. Most modern hardware will provide values using the Geoid reference system, but Map Control APIs will return values in the Elipsoid system. To find out which one is being used by a Geopoint object, see the AltitudeReferenceSystem property. You should not copy a BasicGeoposition without also copying the associated AltitudeReferenceSystem, otherwise the Altitude value will not be valid and could produce unexpected results.
Location = new Geopoint(new BasicGeoposition
{
Latitude = 0,
Longitude = 0,
Altitude = 0
},
AltitudeReferenceSystem.Terrain),
并且请注意,您需要使旋转中心与地图中心一致。
源自 Stefano Della Valle 解决方案。
In my case I've set the translation in the image creation with these X and Y:
Translate = new TranslateTransform { X = -55, Y = -45 },
我想将图像添加到 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 视图中围绕该点移动。
提前感谢您的任何建议。 斯特凡诺
编辑:我试过在网上找到的一些示例,我发现了同样的问题。
这是一张低倍率的图片,您可以看到主干道下方的红点:
缩放这是真实位置,在主干道上方很多:
Location binding doesn't work. I can set the image URI, rotation, ect., but changing the location do not move the image in the map. I've solved getting the image object and setting directly the location, but this not solve the second issue
问题是你没有为Geopoint
属性实现INotifyPropertyChanged
接口,当值改变时它不会更新ui。
the AltitudeReferenceSystem.Terrain seems not applied the to the location Geopoint so the image appears to be not at terrain level so zooming in and out seems to move around the point as in a 3D view.
来源于官方文档remark部分。
The altitude reference system that is returned for location fixes from the geolocation API may depend on the GPS/GNSS radio hardware. Most modern hardware will provide values using the Geoid reference system, but Map Control APIs will return values in the Elipsoid system. To find out which one is being used by a Geopoint object, see the AltitudeReferenceSystem property. You should not copy a BasicGeoposition without also copying the associated AltitudeReferenceSystem, otherwise the Altitude value will not be valid and could produce unexpected results.
Location = new Geopoint(new BasicGeoposition
{
Latitude = 0,
Longitude = 0,
Altitude = 0
},
AltitudeReferenceSystem.Terrain),
并且请注意,您需要使旋转中心与地图中心一致。 源自 Stefano Della Valle 解决方案。
In my case I've set the translation in the image creation with these X and Y:
Translate = new TranslateTransform { X = -55, Y = -45 },