WP7必应地图图钉-如何调整自定义图钉的位置? [英] WP7 Bing Map Pushpin - how to tweak the location of the custom pushpin?

查看:85
本文介绍了WP7必应地图图钉-如何调整自定义图钉的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,很简单的问题,但是我还没有找到明显简单的答案! 我有一个具有地图集成功能的Windows Phone 7应用,在地图上带有一组图钉.图钉是自定义的(只是一个椭圆/圆形).

Ok, simple question, but I haven't found the obviously easy answer yet! I have a Windows Phone 7 app with map integration, with a set of pushpins on the map. The pushpin is custom (just a ellipse/circle).

不幸的是,自定义图钉的位置是从地理位置关闭"的.放大时,它会越来越接近精确度,并且在放大程度最高的地方距离最远.

Unfortunately, the location of the custom pushpin is "off" from the geolocation. when you zoom in, it gets closer and closer to accurate, and is the farthest off in the most zoomed out level.

我认为这是一个抵消性的问题.我看了看RenderTransformOnOrigin,但它似乎并没有帮助我.

I think this is an offset issue. I looked at RenderTransformOnOrigin, but it didn't appear to help me.

谢谢,这是相关代码:

<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>

推荐答案

PushPin类具有PositionOrigin属性,该属性指示位置点相对于引脚的视觉表示的位置.

A the PushPin class has a PositionOrigin property which indicates where the location point is relative the visual representation of the pin.

默认样式使用"BottomLeft",因为它的形状是在其左下角的一个点处有一个刻度线.

The default style use "BottomLeft" because of its shape it has a tick funneling to a point at its bottom left extremity.

但是您使用的是圆,因此您需要将PositionOrigin移动到中心.我还建议您使用样式而不是简单的模板来样式化"您的图钉:-

However you are using a circle hence you would need move the PositionOrigin to the center. I would also recommend that you use a style rather than simply a template to "style" your push pin:-

    <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变为:-

Now your Xaml becomes:-

 <my2:Pushpin Name="pin1"
             Location="51.461326390697344, -0.9261151403188705"
             Content=""
             Style="{StaticResource PushpinControlTemplateBlue}" />

这篇关于WP7必应地图图钉-如何调整自定义图钉的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆