如何以编程方式添加 PushPin,我可以让它具有自定义图像吗? [英] How can I add programmatically add a PushPin, and could I make it have a custom image?

查看:22
本文介绍了如何以编程方式添加 PushPin,我可以让它具有自定义图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个地图应用程序,但我找到的示例描述了一个 myMap.Children 列表,我的 myMap 对象没有:-(

I'm trying to create a map application but the examples I find describes a myMap.Children list that my myMap object does not have :-(

我已经创建了一张地图,非常简单:

I've created a map, pretty much straight forward:

<maps:Map Visibility="Collapsed" Name="MyMap" Height="670" Width="400" ZoomLevel="10" Pitch="0" CartographicMode="Hybrid" Margin="30,0" />

那么我如何在 C# 中添加 PushPins,这些是否可以有来自 Assets 的图像?

So how can I in C# add PushPins, and could these have a image from Assets?

推荐答案

请参阅诺基亚地图教程将图形添加到地图控件" 或查看 MSDN 的 "如何将 UIElements 添加到 Windows Phone 8 中的地图控件".

See Nokia's Maps tutorial on "Adding Graphics to a Map control" or see MSDN's "How to add UIElements to a Map control in Windows Phone 8".

主要是围绕添加您自己的 MapLayer 并在其上添加多个 MapOverlay:

It's mostly around adding you own MapLayer with multiple MapOverlay on top of it:

private void DrawMapMarkers()
{
    MyMap.Layers.Clear();
    MapLayer mapLayer = new MapLayer();

    // Draw marker for current position
    if (MyCoordinate != null)
    {
        DrawAccuracyRadius(mapLayer);
        DrawMapMarker(MyCoordinate, Colors.Red, mapLayer);
    }

    ...

    MyMap.Layers.Add(mapLayer);
}

private void DrawMapMarker(GeoCoordinate coordinate, Color color, MapLayer mapLayer)
{
    // Create a map marker
    Polygon polygon = new Polygon();
    polygon.Points.Add(new Point(0, 0));
    polygon.Points.Add(new Point(0, 75));
    polygon.Points.Add(new Point(25, 0));
    polygon.Fill = new SolidColorBrush(color);

    // Enable marker to be tapped for location information
    polygon.Tag = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
    polygon.MouseLeftButtonUp += new MouseButtonEventHandler(Marker_Click);

    // Create a MapOverlay and add marker
    MapOverlay overlay = new MapOverlay();
    overlay.Content = polygon;
    overlay.GeoCoordinate = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
    overlay.PositionOrigin = new Point(0.0, 1.0);
    mapLayer.Add(overlay);
}

为了对新的 WP8 诺基亚地图控件进行数据绑定,请使用新 Windows Phone 工具包 中的 MapExtensions.例如,这里是如何使用 MapExtensions 在特定地理坐标中创建 PushPin.

In order to databind the new WP8 Nokia Map control, use MapExtensions from the new Windows Phone Toolkit. For example here's how to create a PushPin in a specific GeoCoordinate using MapExtensions.

<maps:Map x:Name="Map" Grid.Row="1" Hold="OnMapHold">
    <maptk:MapExtensions.Children>
        <maptk:Pushpin x:Name="RouteDirectionsPushPin" Visibility="Collapsed"/>
        <maptk:MapItemsControl Name="StoresMapItemsControl">
            <maptk:MapItemsControl.ItemTemplate>
                <DataTemplate>
                    <maptk:Pushpin GeoCoordinate="{Binding GeoCoordinate}" Visibility="{Binding Visibility}" Content="{Binding Address}"/>
                </DataTemplate>
            </maptk:MapItemsControl.ItemTemplate>
        </maptk:MapItemsControl>
        <maptk:UserLocationMarker x:Name="UserLocationMarker" Visibility="Collapsed"/>
    </maptk:MapExtensions.Children>
</maps:Map>

这篇关于如何以编程方式添加 PushPin,我可以让它具有自定义图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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