MapTips widget Vs Graphic MapTips Vs InfoWindow (which one to use?)

4244
17
03-03-2011 08:12 AM
CameronBlandy
Occasional Contributor
Hello all,

I am trying to determine which Map Tip / Info Window I should use for my application. My application will have similiar functionality to the ESRI ShowCase template in VS 2010. Instead of different BaseMaps to choose I will have different Themes to choose. When I click on a theme a dynamic map layer will be created and displayed.

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??

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.

I'd appreciate some help on this topic and some answers to my question as I am a little confused.

Cameron
0 Kudos
17 Replies
JenniferNery
Esri Regular Contributor
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;
  }
 }
}
0 Kudos
CameronBlandy
Occasional Contributor
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 FeatureLayer default symbology (for polygons) is opaque red fill. How do I get it to read the symbology defined in the MapService (it is a regular 9.3.1 MapService not a FeatureService)?

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.



The IdentifyTask would return all attributes from the Layer in question. What if I only wanted a subset of attributes. In a FeatureLayer I can specify the OutFields??
0 Kudos
JenniferNery
Esri Regular Contributor
The FeatureLayer default symbology (for polygons) is opaque red fill. How do I get it to read the symbology defined in the MapService (it is a regular 9.3.1 MapService not a FeatureService)?


DrawingInfo that defines the Rendering is new to ArcGIS Server 10. http://help.arcgis.com/en/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#//00930000000m... (See "Map services expose symbology information" section).

The IdentifyTask would return all attributes from the Layer in question. What if I only wanted a subset of attributes. In a FeatureLayer I can specify the OutFields??


That is correct, IdentifyTask will return all attributes. If you need to exclude some fields you need to do so when you get the results. You can define what is contained in outfields here.
IDictionary<string, object> attributes = new Dictionary<string, object>();
foreach (var item in result.Feature.Attributes)
 if (outfields.Contains(item.Key))
  attributes.Add(item.Key, item.Value);
MyInfoWindow.Content = attributes;
0 Kudos
CameronBlandy
Occasional Contributor
Thanks Jennifer,

I am still experimenting with the various Map Tips/Info Windows. I'd like to know how I can get the Toolkit map tip to default expanded. I tried MyMapTip.Expand(false) (see below) but it only showed the title which I have to click to get the content.

Secondly how can I customize the look and feel of the widget; there does not seem to be a ContentTemplate property like in the InfoWindow.

Here is my XAML and C# code.

<Canvas HorizontalAlignment="Left" VerticalAlignment="Top" >
                <esri:MapTip x:Name="MyMapTip"   BorderBrush="#99000000" 
                BorderThickness="1" VerticalOffset="10" Opacity="0.7"
                HorizontalOffset="10" Background="#DDFFFFFF" />
            </Canvas>


..snippet
            MyMapTip.GraphicsLayer = _foodFeatureLayer;
            MyMapTip.Expand(false);
            MyMapTip.Title = _foodFeatureLayer.ID;
            Map.Layers.Add(_foodFeatureLayer);
0 Kudos
JenniferNery
Esri Regular Contributor
To customize the look and feel of the Toolkit.MapTip, you can follow the same instruction in this blog post: http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/05/20/Use-control-templates-to-customize....

If you need to change the behavior of the Toolkit.MapTip, you can download source from here: http://esrisilverlight.codeplex.com/.
0 Kudos
CameronBlandy
Occasional Contributor
If you need to change the behavior of the Toolkit.MapTip, you can download source from here: http://esrisilverlight.codeplex.com/.


Of course I can go and get the source code for the Widget and figure a way to override the default behaviour but my question is why doesnt MapTip.Expand(false) work? That would seem to be the easiest solution.
0 Kudos
JenniferNery
Esri Regular Contributor
I think you can subscribe to MapTip.SizeChanged event and call Expand().
void MyMapTip_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
 if (e.NewSize != null && e.NewSize.Height > 0 && e.NewSize.Width > 0)
  MyMapTip.Expand(true);
}
0 Kudos
karenvolarich
New Contributor III
I tried the code above for the map tip with a click...does not work.  When you click nothing happens...

<Grid.Resources>
<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>

        </Grid.Resources>

<esri:Map x:Name="Map" Background="White" Extent="-15349000,2810000,-6514000,6553000" ExtentChanged="MyMap_ExtentChanged" IsLogoVisible="False" MouseClick="QueryPoint_MouseClick">

<!--Map Tip-->
        <esri:InfoWindow x:Name="MyInfoWindow"
                         Map="{Binding ElementName=Map}"
                         ContentTemplate="{StaticResource MyDynamicMapInfoWindowTemplate}"
                         MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp"/>

private void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
                        ArcGISDynamicMapServiceLayer dynamicLayer = Map.Layers["Borders"] as ArcGISDynamicMapServiceLayer;
                      IdentifyParameters identifyParams = new IdentifyParameters()
                                                    {
                                                        Geometry = e.MapPoint,
                                                        //Tolerance = 4,
                                                        MapExtent = Map.Extent,
                                                        Width = (int) Map.ActualWidth,
                                                        Height = (int) Map.ActualHeight,
                                                        LayerOption = LayerOption.visible,
                                                        //set to .visible, if set to .all -- BUGS
                                                        //SpatialReference = map.SpatialReference
                                                    };

                    IdentifyTask identifyTask = new IdentifyTask(dynamicLayer.Url);
                    identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
                    identifyTask.ExecuteAsync(identifyParams, e.MapPoint);

                          }

void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
        {
            //IdentifyDetailsDataGrid.ItemsSource = null;

            if (args.IdentifyResults != null && args.IdentifyResults.Count > 0)
            {
                MapPoint clickPoint = args.UserState as MapPoint;
                foreach (var result in args.IdentifyResults)
                {
                    MyInfoWindow.Anchor = clickPoint;
                    MyInfoWindow.IsOpen = true;
                    MyInfoWindow.Content = result.Feature.Attributes;
                    return;
                 
                }
            }
           
        }


        private void MyInfoWindow_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            MyInfoWindow.IsOpen = false;
        }



What is missing?
0 Kudos
karenvolarich
New Contributor III
Is there a way to add a Title or label to info window?  I'm looking to make it the layer name.
0 Kudos