WP7 Bing地图-如何调整自定义图钉的位置?

4
好的,简单的问题,但我还没有找到显然容易的答案! 我有一个带有地图集成的Windows Phone 7应用程序,在地图上设置了一组标记。这个标记是自定义的(只是一个椭圆/圆形)。
不幸的是,自定义标记的位置与地理位置有所偏差。当您放大时,它会越来越接近准确,并且在最缩小的级别下最偏离。
我认为这是一个偏移问题。我查看了RenderTransformOnOrigin,但它似乎对我没有帮助。
提前感谢,以下是相关代码:
<phone:PhoneApplicationPage.Resources>
    <ControlTemplate x:Key="PushpinControlTemplateBlue" TargetType="my2:Pushpin">
        <Grid x:Name="ContentGrid" Width="34" Height="34" RenderTransformOrigin="0.5,0.5">
            <StackPanel Orientation="Vertical" >
                <Grid MinHeight="31" MinWidth="29" Margin="0">
                    <Ellipse Fill="Blue"
                            Margin="1"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Width="20"
                            Height="20"
                            Stroke="White"
                            StrokeThickness="3" />
                    <ContentPresenter HorizontalAlignment="Center"
                                Content="{TemplateBinding Content}"
                                ContentTemplate="{TemplateBinding ContentTemplate}"
                                Margin="4"/>
                </Grid>
            </StackPanel>
        </Grid>
    </ControlTemplate>
</phone:PhoneApplicationPage.Resources>


    <my1:Map Canvas.Left="16" Canvas.Top="13" CopyrightVisibility="Collapsed" CredentialsProvider="AtqOU-L_liZekzqR0mEG7dGDwswKnnXSoSmsVs6eGtAe7S9NZDiAtpAd1vgPfhxD" Height="521" LogoVisibility="Collapsed" Name="mapMain" ScaleVisibility="Collapsed" VerticalContentAlignment="Top" Visibility="Visible" Width="446" ZoomBarVisibility="Collapsed" BorderThickness="1" Background="Tomato">
        <my2:Pushpin Name="pin1"
                 Location="51.461326390697344, -0.9261151403188705"
                 Content=""
                 Template="{StaticResource PushpinControlTemplateBlue}" />
    </my1:Map>
1个回答

8

PushPin类有一个PositionOrigin属性,它指示位置点相对于图钉的视觉表示的位置。

默认样式使用“BottomLeft”,因为它的形状在其左下极端有一个漏斗形状的刻度。

但是,由于您使用的是圆形,因此需要将PositionOrigin移动到中心。我还建议您使用样式而不仅仅是模板来“样式化”您的图钉:

    <ControlTemplate x:Key="PushpinControlTemplate" TargetType="my2:Pushpin">
        <Grid x:Name="ContentGrid" Width="34" Height="34" RenderTransformOrigin="0.5,0.5">
            <StackPanel Orientation="Vertical" >
                <Grid MinHeight="31" MinWidth="29" Margin="0">
                    <Ellipse Fill="{TemplateBinding Background}"
                            Margin="1"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Width="20"
                            Height="20"
                            Stroke="{TemplateBinding Foreground}"
                            StrokeThickness="3" />
                    <ContentPresenter HorizontalAlignment="Center"
                                Content="{TemplateBinding Content}"
                                ContentTemplate="{TemplateBinding ContentTemplate}"
                                Margin="4"/>
                </Grid>
            </StackPanel>
        </Grid>
    </ControlTemplate>

<Style TargetType="my2:Pushpin" x:Key="PushpinControlTemplateBlue">
    <Setter Property="Template" Value="{StaticResource PushpinControlTemplate}" />
    <Setter Property="PositionOrigin" Value="Center" />
    <Setter Property="Background" Value="Blue" />
    <Setter Property="Foreground" Value="White" />
    <Setter Property="FontSize" Value="18" />
</Style>

现在你的Xaml变成了:-
 <my2:Pushpin Name="pin1"
             Location="51.461326390697344, -0.9261151403188705"
             Content=""
             Style="{StaticResource PushpinControlTemplateBlue}" />

好的,那是非常令人印象深刻的答案。谢谢你,干得好。 - pearcewg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接