2010-03-10 101 views

回答

6

你有2種方式去:

(1)創建任何的UIElement通入PushPinLayer.AddChild。該方法的AddChild將接受和任何的UIElement,如在這種情況下的圖像:

MapLayer m_PushpinLayer = new MapLayer(); 
Your_Map.Children.Add(m_PushpinLayer); 
Image image = new Image(); 
image.Source = ResourceFile.GetBitmap("Images/Me.png", From.This); 
image.Width = 40; 
image.Height = 40; 
m_PushpinLayer.AddChild(image, 
    new Microsoft.Maps.MapControl.Location(42.658, -71.137), 
     PositionOrigin.Center); 

(2)創建原生對象圖釘通入PushpinLayer.AddChild,但首先設置它的模板屬性。請注意,圖釘的是ContentControls,並且具有可以在XAML中定義的資源設置模板屬性:

MapLayer m_PushpinLayer = new MapLayer(); 
Your_Map.Children.Add(m_PushpinLayer); 
Pushpin pushpin = new Pushpin(); 
pushpin.Template = Application.Current.Resources["PushPinTemplate"] 
    as (ControlTemplate); 
m_PushpinLayer.AddChild(pushpin, 
    new Microsoft.Maps.MapControl.Location(42.658, -71.137), 
     PositionOrigin.Center); 


<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <ControlTemplate x:Key="PushPinTemplate"> 
     <Grid> 
      <Ellipse Fill="Green" Width="15" Height="15" /> 
     </Grid> 
    </ControlTemplate> 
</ResourceDictionary> 
+0

user70192,這個回答你的問題?如果是這樣,你能將它標記爲已回答嗎? – 2010-04-15 05:15:22

1

我將通過創建一個圖層,然後加入我的圖釘到該層做到這一點。

// during initial load 
MapLayer lay = new MapLayer(); 
MapControl.Children.Add(lay); 


// for each pushpin you want to add 
Image image = new Image(); 
// this assumes you have an "Images" folder on the root of your host web application 
image.Source = new BitmapImage(new Uri(App.Current.Host.Source, "../Images/PushPin.png")); 
var lat = 40.4d; 
var long = -81.8d; 
Location location = new Location(lat, long, 0d); 

//Define the image display properties 
image.Opacity = 1.0; 
image.Stretch = Stretch.None; 

// Center the image around the location specified 
PositionOrigin position = PositionOrigin.Center; 

//Add the image to the defined map layer 
lay.AddChild(image, location, position); 
1
Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded 
    Dim pushpin As Microsoft.Maps.MapControl.Pushpin = New Microsoft.Maps.MapControl.Pushpin 
    pushpin.Template = Application.Current.Resources("PushPinTemplate") 
End Sub 

給我任何錯誤......