【发布时间】:2013-12-29 07:03:13
【问题描述】:
我正在向地图中心添加一个标记。然而,随着地图缩放级别的变化,中心正在从“原始”地图中心移动(标记也是如此)。
无论缩放级别如何,如何以始终位于地图中心的方式绘制标记?
似乎 PositionOrigin 设置为 (0.5, 0.5 ) 没有做它应该做的事情,即以画布中心位于 GeoCoordinate“位置”输入变量的方式绘制画布。
我绘制标记的代码如下:
private void AddMarkerToMap( String symbol, GeoCoordinate location )
{
if ( _markerLayer != null )
{
Map1.Layers.Remove( _markerLayer );
_markerLayer = null;
}
_markerLayer = new MapLayer();
var mapCenterMarker = new MapOverlay
{
GeoCoordinate = location
};
var canvas = new Canvas();
//canvas.Opacity = 0.5;
var circhegraphic = new Ellipse();
circhegraphic.Fill = new SolidColorBrush( Color.FromArgb( 0x44, 0x00, 0xFF, 0x00 ) );
circhegraphic.Stroke = new SolidColorBrush( Color.FromArgb( 0xFF, 0x00, 0x00, 0xFF ) );
circhegraphic.StrokeThickness = 4;
circhegraphic.Opacity = 0.7;
circhegraphic.Height = 40;
circhegraphic.Width = 40;
canvas.Children.Add( circhegraphic );
var textBlock = new TextBlock
{
Text = symbol,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
FontWeight = FontWeights.ExtraBold,
Foreground = new SolidColorBrush( Color.FromArgb( 0xFF, 0xFF, 0x00, 0x00 ) )
};
Canvas.SetLeft( textBlock, 13 );
Canvas.SetTop( textBlock, 4 );
Canvas.SetZIndex( textBlock, 5 );
canvas.Children.Add( textBlock );
mapCenterMarker.Content = canvas;
mapCenterMarker.PositionOrigin = new Point( 0.5, 0.5 );
_markerLayer.Add( mapCenterMarker );
Map1.Layers.Add( _markerLayer );
}
谢谢,
【问题讨论】:
标签: c# windows-phone-8 here-api