1). Can we put Map Tips on a dynamic map layer (we want to use the symbology from the map service)? If not then we need to use a Feautre Layer or Graphics layer and then define the symbology which would be very painful, correct??
If you require your map tip to open on mouse hover, you can only do so by using a GraphicsLayer (FeatureLayer inherits from GraphicsLayer). If you want to use the symbology defined by the map service, you should use FeatureLayer. The optimal way is to open map tip on mouse click so you would not need to use GraphicsLayer. You can perform an IdentifyTask and use the IdentifyResults to display in your InfoWindow.2). Assuming we need to create a Graphics/Feature layer for the Map Tips how do we define a standard map Tip / Info Window template that can be used for all Graphics/Feature Layers added to the map given that each Graphics/Feature Layer will have a different set of attribtutes to display? Is the Binding for this straight forward.
The choice is up to you. I would recommend InfoWindow if you don't mind opening the map tip on MouseClick. You can define your template this way:
<DataTemplate x:Key="MyDynamicMapInfoWindowTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ItemsControl ItemsSource="{Binding Keys}" Grid.Column="0" />
<ItemsControl ItemsSource="{Binding Values}" Grid.Column="1" />
</Grid>
</DataTemplate>
You can use this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#InfoWindowSimple.You can use ArcGISDynamicMapServiceLayer instead
<esri:Map x:Name="MyMap" MouseClick="MyMap_MouseClick">
<esri:ArcGISDynamicMapServiceLayer ID="MyLayer"
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" />
</esri:Map>
<esri:InfoWindow x:Name="MyInfoWindow"
Map="{Binding ElementName=MyMap}"
ContentTemplate="{StaticResource MyDynamicMapInfoWindowTemplate}"
MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp" />
Code-behind:
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
ArcGISDynamicMapServiceLayer layer = MyMap.Layers["MyLayer"] as ArcGISDynamicMapServiceLayer;
IdentifyParameters identifyParams = new IdentifyParameters()
{
Geometry = e.MapPoint,
MapExtent = MyMap.Extent,
Width = (int)MyMap.ActualWidth,
Height = (int)MyMap.ActualHeight,
LayerOption = LayerOption.visible,
SpatialReference = MyMap.SpatialReference
};
IdentifyTask identifyTask = new IdentifyTask(layer.Url);
identifyTask.ExecuteCompleted += identifyTask_ExecuteCompleted;
identifyTask.ExecuteAsync(identifyParams, e.MapPoint);
}
void identifyTask_ExecuteCompleted(object sender, IdentifyEventArgs e)
{
if (e.IdentifyResults != null && e.IdentifyResults.Count > 0)
{
MapPoint clickPoint = e.UserState as MapPoint;
foreach (var result in e.IdentifyResults)
{
MyInfoWindow.Anchor = clickPoint;
MyInfoWindow.IsOpen = true;
//Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
MyInfoWindow.Content = result.Feature.Attributes;
return;
}
}
}