Saturday, December 8, 2012

Create selectable pushpin in Bing maps (XAML)

Create selectable pushpin in Bing maps (XAML)

This is more of XAML question for silverlight.

<Mobile:DevicePushpinTemplateSelector                              m:MapLayer.Position="{Binding Location}"                              ZoomLevel="{Binding ZoomLevel, ElementName=MainMap}"                              Content="{Binding}">                             <Mobile:DevicePushpinTemplateSelector.DotTemplate>                                 <DataTemplate>                                     <Ellipse Width="8" Height="8" Stroke="Black" Fill="{Binding IsGPSDataRecent, Converter={StaticResource BoolToGreenRedBrushConverter}}" StrokeThickness="1">                                         <ToolTipService.ToolTip>                                             <TextBlock Text="{Binding DisplayId}" />                                         </ToolTipService.ToolTip>                                     </Ellipse>                                 </DataTemplate>                             </Mobile:DevicePushpinTemplateSelector.DotTemplate>                             <Mobile:DevicePushpinTemplateSelector.NumberedTemplate>                                 <DataTemplate>                                     <Border x:Name="border" Background="{Binding IsGPSDataRecent, Converter={StaticResource BoolToGreenRedBrushConverter}}" BorderBrush="Black" BorderThickness="2" Padding="2" Height="20" CornerRadius="8">                                         <TextBlock  VerticalAlignment="Center" Text="{Binding DisplayId}" />                                     </Border>                                 </DataTemplate>                             </Mobile:DevicePushpinTemplateSelector.NumberedTemplate>                         </Mobile:DevicePushpinTemplateSelector> 

On XAML above I have 2 different templates based on map zoom level. When it is zoomed out - it shows smaller ellipse, when user zooms closer - I increase size of pushpin.

2 issues:

  1. WIth a lot of pushpins it get's really slow, I beleive it's due to template selection.

  2. I want it to be different. I want to create "IsSelected" property so all pushpins will be the same on all zoom levels but when user clicks on pushpin - it expands in size.

I wonder how do I code "selection" part. I want only one pushpin to be selected at time. I can bind to property and make pushpin parts visible/invisible but I'm not sure how to code "selection" piece. Should it be Button?

Answers & Comments...

Answer: 1

When doing a windows phone app I had the issue of many pins causing "lag" the easiest way around that is to only show pins within a certain radius of the centre of the map and remove the others until they come into the radius.

Cheers Mark

by : markblue777http://stackoverflow.com/users/102324




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog