如何自定義Bing地圖Silverlight控件上的圖釘樣式?我已閱讀此處顯示的文檔(http://www.microsoft.com/maps/isdk/silverlightbeta/#MapControlInteractiveSdk.Tutorials.TutorialCustomPushpin)。但是,我正在編程添加可變數量的圖釘。理想情況下,我希望能夠設定每個pushin的風格,但我不知道如何。Silverlight - Bing地圖 - 自定義圖釘樣式
4
A
回答
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>
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
給我任何錯誤......
相關問題
- 1. Bing地圖Silverlight控件自定義圖釘
- 2. Silverlight - Bing地圖控件 - 圖釘集羣
- 3. 如何在Bing地圖上創建自定義圖釘v7
- 4. 嵌入bing地圖 - 圖釘
- 5. Bing地圖Silverlight控件圖釘結垢問題
- 6. 從Bing獲取帶圖釘的地圖[silverlight]
- 7. Silverlight bing地圖中的可拖動AND可點擊圖釘
- 8. 更新Silverlight的Bing地圖圖釘的位置控制
- 9. 使用Storyboard(Silverlight)在Bing地圖內部製作圖釘動畫
- 10. Silverlight - 通過C#將圖釘添加到Bing地圖
- 11. 在Bing地圖中添加圖釘
- 12. 的AddHandler用於Bing地圖圖釘
- 13. Bing地圖圖釘和信息框
- 14. 用Bing地圖突出顯示圖釘
- 15. 綁定在ObservableCollection圖釘Bing地圖控制WP7
- 16. Angular 2/4 Bing Map圖釘自定義模板函數調用
- 17. Bing地圖自定義NavBar文本框?
- 18. bing地圖中的自定義顏色?
- 19. Bing地圖與C#和MVVM信息框和圖釘綁定
- 20. bing地圖中的可點擊/定製圖釘
- 21. Silverlight樣式:基於自定義樣式的自定義樣式
- 22. Impresspages 4 Google地圖自定義樣式
- 23. ggmap的自定義地圖樣式
- 24. Android中的自定義地圖樣式
- 25. Appcelerator地圖自定義樣式
- 26. 爲什麼Bing地圖圖釘圖標有平鋪圖像? WP7
- 27. Silverlight Bing地圖問題
- 28. Bing地圖圖釘可視化(圖釘剪輯)與AJAX SDK 7.0和HTML
- 29. 谷歌地圖在Windows手機中的自定義圖釘
- 30. 將多個圖標添加到Bing地圖API的圖釘v8
user70192,這個回答你的問題?如果是這樣,你能將它標記爲已回答嗎? – 2010-04-15 05:15:22