【问题标题】:Silverlight - Bing Maps - Customize Pushpin StyleSilverlight - 必应地图 - 自定义图钉样式
【发布时间】:2010-03-10 05:03:49
【问题描述】:

如何自定义 Bing 地图 Silverlight 控件上图钉的样式?我已经查看了此处显示的文档 (http://www.microsoft.com/maps/isdk/silverlightbeta/#MapControlInteractiveSdk.Tutorials.TutorialCustomPushpin)。但是,我以编程方式添加可变数量的图钉。理想情况下,我希望能够设置每个 pushin 的样式,但我不知道如何。

【问题讨论】:

    标签: silverlight


    【解决方案1】:

    你有两条路可以走:

    (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) 创建一个原生 PushPin 对象以传递给 PushpinLayer.AddChild,但首先要设置它的 Template 属性。请注意,PushPin 是 ContentControls,并且具有可以从 XAML 中定义的资源设置的 Template 属性:

    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>
    

    【讨论】:

    • user70192,这是否回答了您的问题?如果是这样,您能否将其标记为已回答?
    【解决方案2】:

    我会通过创建一个图层然后将我的图钉添加到该图层来做到这一点。

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

    【讨论】:

      【解决方案3】:
      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
      

      别误会……

      【讨论】:

        猜你喜欢
        • 2011-01-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多