【问题标题】:WP7 Bing Map Pushpin - how to tweak the location of the custom pushpin?WP7 Bing 地图图钉 - 如何调整自定义图钉的位置?
【发布时间】:2011-01-14 18:21:24
【问题描述】:

好的,简单的问题,但我还没有找到明显简单的答案! 我有一个带有地图集成的 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>

【问题讨论】:

    标签: windows-phone-7 bing-maps


    【解决方案1】:

    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}" />
    

    【讨论】:

    • 好的,这是一个非常令人印象深刻的答案。谢谢,干得好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多