如何添加编程方式添加一个图钉,我可以使其具有自定义图像? [英] How can I add programmatically add a PushPin, and could I make it have a custom image?
问题描述
我试图创建一个地图应用程序,但我发现的例子描述了一个 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#中添加图钉,并能这些都从资产
?
So how can I in C# add PushPins, and could these have a image from Assets
?
推荐答案
请参阅诺基亚的地图教程上的图像添加图形到地图控件 还是请参阅MSDN的如何UI元素添加到地图。控制的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诺基亚地图控件,从新使用MapExtensions 的Windows Phone工具包。例如,以下是如何在一个特定会有地理座标使用MapExtensions创建一个图钉。
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>
这篇关于如何添加编程方式添加一个图钉,我可以使其具有自定义图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!