2010-03-10 5 views

Répondre

6

Vous avez 2 façons d'aller:

(1) CRÉE UNE QUELCONQUE UIElement passer dans PushPinLayer.AddChild. La méthode AddChild acceptera et tout UIElement, comme une image dans ce cas: la propriété

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) DEVENEZ objets Punaise natifs de passer dans PushpinLayer.AddChild, mais d'abord définir son modèle. Notez que Punaise de sont ContentControls, et ont une propriété de modèle qui peut être défini à partir d'une ressource définie dans 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, cette réponse à votre question? Si oui, pourriez-vous le marquer comme étant répondu? –

1

je referais ce en créant une couche, puis en ajoutant mes Punaises à cette couche.

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

me donne pas d'erreur ...

Questions connexes