我正在向地图中心添加标记。但是,当地图的缩放级别发生变化时,中心将从“原始”地图中心移动(标记也是如此)。
无论缩放级别如何,如何以始终位于地图中心的方式绘制标记?
看起来PositionOrigin被设置为(0.5,0.5)并没有做它应该做的事情,即以画布中心位于GeoCoordinate“location”输入变量的方式绘制画布。 / p>
我绘制标记的代码如下:
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 );
}
谢谢,
答案 0 :(得分:0)
问题在于Canvas,改为网格,如下所示:
private void AddMarkerToMap( String symbol, GeoCoordinate location )
{
if ( _markerLayer != null )
{
Map1.Layers.Remove( _markerLayer );
_markerLayer = null;
}
_markerLayer = new MapLayer();
var mapCenterMarker = new MapOverlay();
var grid = new Grid();
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;
grid.Children.Add( circhegraphic );
var textBlock = new TextBlock
{
Text = symbol,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
FontWeight = FontWeights.ExtraBold,
FontSize = 14,
Foreground = new SolidColorBrush( Color.FromArgb( 0xFF, 0xFF, 0x00, 0x00 ) )
};
grid.Children.Add( textBlock );
mapCenterMarker.GeoCoordinate = location;
mapCenterMarker.Content = grid;
mapCenterMarker.PositionOrigin = new Point( 0.5, 0.5 );
_markerLayer.Add( mapCenterMarker );
Map1.Layers.Add( _markerLayer );
}
虽然我不确定为什么Canvas会出问题。