Select to view content in your preferred language

Map tip doesn't work

2595
19
02-09-2011 02:01 PM
DonFreeman
Emerging Contributor
In the sample shown at
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#GraphicsMapTip

what is supposed to trigger the MyMap_PropertyChanged event? I have reproduced this code in my project (using a different map) but this event does not fire with a mouseover. Can someone help me out here?

Thanks
0 Kudos
19 Replies
DonFreeman
Emerging Contributor
Dan - Thanks

Actually, I wanted the maptip to appear with a mouseover because I already have a full identify with a mouseclick. So, are you suggesting that there be a FeatureLayer on top of the DynamicMapServiceLayer? Or just that the Url be changed to refer to FeatureLayer at the end? This, it seems, creates an invalid Url error, which is probably because the service is a map service and not a feature service? Which begs a new question. Should I, as a matter of course, create FeatureServices rather than MapServices? (I can make this all work with a FeatureService.)

I have also tried using the simpler maptip shown at http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#MapTipWidget but also without success.

The codebehind you suggest doesn't like the reference to "_mapServiceLayer.Url". Seems like that is undefined. Also, you are using "identify" which is another function in my project so I don't think I can use it here? So I'm still pretty puzzled. 😞
0 Kudos
DanielWalton
Frequent Contributor
What is the difference in function between the maptip and the identify? And yes, if you want to use maptips, you have to use GraphicsLayer (i.e. FeatureLayer). FeatureLayer is easier to code against, but if your service returns a lot of features, the client will bog down significantly as Silverlight struggles to repaint the overgrown visual tree.
0 Kudos
DonFreeman
Emerging Contributor
The maptip will appear with a mouseover and will show only a couple of fields such as project number and name, and will close when mouseleave. The identify will operate with a mouseclick and will show all the fields (there are many). There are 3 samples that I can find on the esri site. Two use a TiledMapServiceLayer, and one uses a FeatureLayer. Does this suggest that the maptip cannot be done with a DynamicServiceLayer? I didn't quite follow your initial suggestion about the "buddy layer".

Also, in looking at this code from one of the samples
void Layers_LayersInitialized(object sender, EventArgs args)
   {
   ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query()
   {
    Geometry = MyMap.Extent,
    OutSpatialReference = MyMap.SpatialReference
   };
   query.OutFields.Add("*");

   QueryTask queryTask = new QueryTask("http://gismaps.pagnet.org/ArcGIS/rest/services/Interactive_TIP_2011/MapServer/1");
   queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
   queryTask.ExecuteAsync(query);
   }

  private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
   {
   FeatureSet featureSet = args.FeatureSet;

   GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
   MyMapTip.GraphicsLayer = graphicsLayer;
   
   if (featureSet != null && featureSet.Features.Count > 0)
    {
    foreach (Graphic feature in featureSet.Features)
     {
     feature.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
     graphicsLayer.Graphics.Add(feature);
     }
     
    }
   }

This is from the toolkit maptip.
As I try to understand this,  it appears that the graphics layer is initially empty but is populated with a symbol for each feature when it loads, and that each graphic symbol collects the data at that time. This then places all the maptip data in the page from the beginning so that it is instantly available without further query. Correct? As an aside, why don't we "see" the graphics on the graphics layer?

As I run the above code, it loops through the foreach appropriately so I think I am good to that point, but I still don't get anything to popup. It would be nice if I could view source to see what's actually on the page. 😞
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Try by initializing 'ReturnGeometry' to true (depending on the service, the defaut value can be true or false, so...).

 
.....
query.OutFields.Add("*");

query.ReturnGeometry = true;
.......
0 Kudos
DonFreeman
Emerging Contributor
dbroux -
Thanks, this does not help. Same result.
0 Kudos
JenniferNery
Esri Regular Contributor
This seems like a related thread: http://forums.arcgis.com/threads/25018-MapTips-widget-Vs-Graphic-MapTips-Vs-InfoWindow-(which-one-to....

If you do not need the maptip to show on mouse hover for the dynamic layer, you can use InfoWindow instead.

The fields displayed in a MapTip is dependent on the template you provided and the OutFields from your query. If the template and/or OutFields only include project number and name, then these will be the only fields displayed in your MapTip. The map tip is also expected to close immediately unless hovered by mouse or MapTipHideDelay is set.
0 Kudos
SergioGalindo
Deactivated User
Hi,

I've created a user control meant to be used as a custom maptip. I need to set up the binding for a textblock to an attribute in my graphicslayer graphics in the code behind at runtime (because sometimes i nedd to bind to attribute1, others to attribute2).

This is my code:

public CustomMaptip(LeyendaConsulta legend, string NameField, Graphic g)
{
InitializeComponent();
this._nombreCampoGeografia = nombreCampoGeografia;
Binding binding = new Binding(string.Format("Attributes[{0}]", NameField));
binding.Source = g;
this.TextBlockGeografia.SetBinding(TextBox.TextProperty, binding);
this.Legend.Content = legend;
}

I 've tried setting binding.source to the graphic, graphicslayer, the attribute collection... but it always raise an exception at the SetBinding call. I'm lost!!!!

Thanks in advance


0 Kudos
DominiqueBroux
Esri Frequent Contributor
The datacontext of a maptip is set to the attributes dictionary by the framework.

So I think  your code should be:
Binding binding = newBinding(string.Format("[{0}]", NameField));
// binding.Source = g; 


i.e bind to [<attributeName>] instead of Attributes[<attributeName>] and dont set the source of the binding.

That being said I am not sure this explains the exception. In your code, where is coming your TextBlockGeographia from?

0 Kudos
SergioGalindo
Deactivated User
Hi dominique,

I just realized I was making a really dumb mistake at:

this.TextBlockGeografia.SetBinding(TextBox.TextProperty, binding);

Of course, it should be: TextBlock.TextProperty

Oops!!!

I omitted the binding's source setting as you sugestted and it worked fine.

1000 thanks for your help.
0 Kudos
Matrix_Solutions_Inc_Geomatics
Regular Contributor
was this ever resolved? I created a class inheriting the MapTip so that i can customize it but it doesnt show when i hover over the graphic, im pretty sure it has something to do with making a custom class of the map tip.


Imports System
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Ink
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows.Data
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Controls.Primitives
Imports ESRI.ArcGIS.Client.Toolkit

Namespace UserControls
    ' <summary>
    ' </summary>
    <TemplateVisualState(Name:="Collapsed", GroupName:="ViewStates"), _
    TemplateVisualState(Name:="Expand", GroupName:="ViewStates"), _
    TemplatePart(Name:="MaptTipImage", Type:=typeof(Image))>
    Public Class ExtendedMapTip
        Inherits MapTip
        ' <summary>
        ' </summary>
#Region "Private fields"
        Private MaptTipImage As Image
#End Region

        Public Sub New()
            DefaultStyleKey = GetType(ExtendedMapTip)
        End Sub

#Region "Dependency Properties"

        ' <summary>
        ' Gets or sets a value indicating whether this control is expanded.
        ' </summary>
        ' <value>
        '  <c>true</c> if this instance is expanded; otherwise, <c>false</c>.
        ' </value>

#End Region

        ' <summary>
        ' </summary>

        Public Overrides Sub OnApplyTemplate()

            MyBase.OnApplyTemplate()
            MaptTipImage = TryCast(Me.GetTemplateChild("MaptTipImage"), Image)
            If MaptTipImage IsNot Nothing Then
                AddHandler MaptTipImage.MouseLeftButtonUp, AddressOf Image_Click
            End If

        End Sub

        Public Sub Image_Click(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonUp
            Try

                Dim MapTipImage As Image = TryCast(sender, Image)

                If MapTipImage Is DBNull.Value Then
                    Return
                End If

                Dim Maptip As Grid = TryCast(MapTipImage.Parent, Grid)

                Me.HorizontalAlignment = HorizontalAlignment.Stretch
                Me.VerticalAlignment = VerticalAlignment.Stretch

            Catch generatedExceptionName As System.Exception
            End Try
        End Sub

    End Class
End Namespace

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
    xmlns:local="clr-namespace:MatrixWebMap.UserControls"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:converters="clr-namespace:MatrixWebMap.Converter"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009" 
    xmlns:esriToolkit="clr-namespace:ESRI.ArcGIS.Client.Toolkit;assembly=ESRI.ArcGIS.Client.Toolkit"
    >
     <!-- Map Tip Style -->
    <Style x:Key="MapTipSkin" TargetType="esri:MapTip">
        <Setter Property="Background" Value="#000000"/>
        <Setter Property="Foreground" Value="#FFFFFF"/>
        <Setter Property="Height" Value="Auto" />
        <Setter Property="Opacity" Value="1"/>
        <Setter Property="BorderThickness" Value="2"/>
        <Setter Property="BorderBrush" Value="#FFFFFF"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="esri:MapTip">
                    <Grid x:Name="MapTipContents" MinWidth="50" Background="Black" Opacity="1" Width="Auto" Height="Auto">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Collapsed">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MapTipData" Storyboard.TargetProperty="Height">
                                            <SplineDoubleKeyFrame KeySpline="0.3,0 0,1" KeyTime="00:00:00.5" Value="0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MapTipData" Storyboard.TargetProperty="Width">
                                            <SplineDoubleKeyFrame KeySpline="0.3,0 0,1" KeyTime="00:00:00.5" Value="0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Expanded">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MapTipData" Storyboard.TargetProperty="Height">
                                            <SplineDoubleKeyFrame KeySpline="0.3,0 0,1" KeyTime="00:00:00.5" Value="240"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MapTipData" Storyboard.TargetProperty="Width">
                                            <SplineDoubleKeyFrame KeySpline="0.3,0 0,1" KeyTime="00:00:00.5" Value="360"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name="MapTip" MinWidth="50" Background="Black" Opacity="0.8" Width="Auto" Height="Auto">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="20"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Border Grid.RowSpan="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="5"/>
                            <Polyline Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}" Points="0,10 -10,-10 10,0"/>
                            <ContentPresenter Margin="5,5,5,0" Content="{TemplateBinding Title}"/>
                            <data:DataGrid x:Name="MapTipData" Height="0" Margin="5,5,5,5" Width="0" Grid.Column="0" Grid.Row="12" Foreground="White" RowBackground="#555555" AlternatingRowBackground="Black" AutoGenerateColumns="True" HeadersVisibility="None" ItemsSource="{TemplateBinding ItemsSource}" RowStyle="{StaticResource DataGridRowStyle}" />
                        </Grid>
                        <Image x:Name="MapTipImage" Source="{Binding [FileLink]}" Margin="5,5,5,5" HorizontalAlignment="Center" Opacity="1" VerticalAlignment="Bottom" Width="Auto" Height="Auto" MaxHeight="{Binding ElementName=MapTipData, Path=Height}" MaxWidth="{Binding ElementName=MapTipData, Path=Width}" >
                            <Image.Triggers>
                                <EventTrigger RoutedEvent="Image.Loaded">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="MapTipContents" Storyboard.TargetProperty="Height" To="600"/>
                                            <DoubleAnimation Storyboard.TargetName="MapTipContents" Storyboard.TargetProperty="Width" To="800"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Image.Triggers>
                        </Image>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
0 Kudos