Hello - I'm just getting started with the Silverlight DV suite and was wondering if there's a way, using the xamMap control, to select multiple areas on a map? In other words, using the world map as a example, say I wanted to select the US, Canada and Mexico then show Grid data for North America. Perhaps the user could either hold the control key down or "lasso" the regions they wanted to select. I haven't seen an example that demonstrates this functionality and was just curious if it's possible. Thanks in advance.
Matt
Hi Matt,
Yes it is possible to use XamMap in this scenario. Please try the following code:
XAML:
<Maps:XamMap x:Name="xamMap" MapMouseLeftButtonDown="xamMap_MapMouseLeftButtonDown"> <Maps:MapNavigationPane igControls:XamDock.Edge="InsideRight" /> <Maps:XamMap.Layers> <Maps:MapLayer> <Maps:MapLayer.Reader> <Maps:ShapeFileReader Uri="Shapefiles/world/world" DataMapping="Caption=CNTRY_NAME" /> </Maps:MapLayer.Reader> </Maps:MapLayer> </Maps:XamMap.Layers></Maps:XamMap>
Code behind:
private void xamMap_MapMouseLeftButtonDown(object sender, MapMouseButtonEventArgs e){ if (e.Element != null) { if (Keyboard.Modifiers == ModifierKeys.Control) { var mapElement = _selectedElements.FirstOrDefault(element => element == e.Element);
if (mapElement != null) { mapElement.Fill = null; _selectedElements.Remove(mapElement); } else { e.Element.Fill = new SolidColorBrush(Colors.Orange); _selectedElements.Add(e.Element); } } else { _selectedElements.ForEach(element => element.Fill = null); _selectedElements.Clear();
e.Element.Fill = new SolidColorBrush(Colors.Orange); _selectedElements.Add(e.Element); } } }
In the above sample control key is used to select multiple map elements.
Regards,
Ivan Kotev