Map tip doesn't work

1626
19
02-09-2011 02:01 PM
DonFreeman
New 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
DanielWalton
Occasional Contributor
That event is triggered when the first layer is initialized, which sets the map's spatial reference.
0 Kudos
DonFreeman
New Contributor
That event is triggered when the first layer is initialized, which sets the map's spatial reference.


Dan -
Yes, that would seem to agree with what I am seeing. However, looking at the esri sample code it looks like it should trigger again when the mouse hovers over a map feature. Or am I missing something? What is supposed to trigger the maptip?
Thanks
0 Kudos
DanielWalton
Occasional Contributor
What is supposed to trigger the maptip?


In that sample, layer's maptip is defined in XAML and adds a behind-the-scenes event handler for GraphicsLayer.MouseEnter at startup. If your problem is that the maptips aren't showing, there might be a problem with the template for the Maptip. Silverlight doesn't always do the best job of notifying you of problems with templates.
0 Kudos
JenniferNery
Esri Regular Contributor
Map PropertyChanged event is fired whenever a property of the map changes. In that specific sample, we are only concerned if the property that got changed is its SpatialReference. Dan is correct, when the first layer is added to your map, it should trigger SpatialReference property to change and since we unsubscribe to it after this, it would never be hit again. This is not the event that opens the maptip though.

GraphicsLayer MapTip opens when mouse enters a graphic. You can listen to GraphicsLayer MouseEnter event, if you want but opening and closing the MapTip is handled by the API.

When you say Map tip does not work.. what do you mean by that exactly? 😛 Map tip does not open or opens without content? Since you modified the services, you must have also updated the Binding statements since the attribute keys here are specific to the services in the sample. Also check that your graphics geometry and a symbol that is appropriate for this geometry type. Check also that if you used a symbol template, none of the elements here have IsHitTestVisible to false.
0 Kudos
DonFreeman
New Contributor
Map PropertyChanged event is fired whenever a property of the map changes. In that specific sample, we are only concerned if the property that got changed is its SpatialReference. Dan is correct, when the first layer is added to your map, it should trigger SpatialReference property to change and since we unsubscribe to it after this, it would never be hit again. This is not the event that opens the maptip though.

GraphicsLayer MapTip opens when mouse enters a graphic. You can listen to GraphicsLayer MouseEnter event, if you want but opening and closing the MapTip is handled by the API.

When you say Map tip does not work.. what do you mean by that exactly? 😛 Map tip does not open or opens without content? Since you modified the services, you must have also updated the Binding statements since the attribute keys here are specific to the services in the sample. Also check that your graphics geometry and a symbol that is appropriate for this geometry type. Check also that if you used a symbol template, none of the elements here have IsHitTestVisible to false.


Thanks Jenn. When I say map tip doesn't work, I mean apsolutely nothing happens when I mouseover the point feature. No code fires, no visible indication that anything happened. As I looked at the code it seemed that something should fire the query task so I was trying to trace it back and it seemed like maybe the MapPropertyChanged was it, but now I see that is not how it works.

That said, there are several examples of maptips on the samples site and I was able to get the one under FeatureLayers to work. So my problem is solved for the moment. Is there anything about the graphics maptip that would make it not work with a FeatureLayer? (Just a question from someone new to the game.)
Thanks
0 Kudos
DanielWalton
Occasional Contributor
Any of a number of things could cause the maptip to not show up. As a test, comment out all the bound controls from your maptip template. You should at least see a small border show up when you hover. Then you can start adding controls back in to see what the funky binding expression is that's causing problems.

Also, in SL 4, there seems to be some discrepancies on how the binding to attributes can be referenced (Inline maptip template: use {Binding [attributename]}, Static resource template, use {Binding Attributes[attributename]}).
0 Kudos
JenniferNery
Esri Regular Contributor
Try to see if the Query ExecuteCompleted event is raised, subscribe to Failed event too if that gets raised instead. If the graphic symbol has IsHitTestVisible=false, none of the mouse events will be raised. Like Dan mentioned, try very simple symbol just to see that the features are present and that they accept mouse events. Then maybe display hard-coded text for now and fix the Binding later just to see if a maptip can be displayed. You can also subscribe to the layer's MouseEnter to check that it is hit when you enter the graphic.
0 Kudos
DonFreeman
New Contributor
OK, here is my symbol.
<esri2:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="Aqua" Style="Circle" />
and here is my map and layer with the bindings commented out.

<esri:ArcGISDynamicMapServiceLayer ID="ConstructionProjects" 
      Url="http://gismaps.pagnet.org/ArcGIS/rest/services/Interactive_TIP_2011/MapServer"
      VisibleLayers="1,2" >
      </esri:ArcGISDynamicMapServiceLayer>
      <esri:GraphicsLayer ID="MapTipGraphicsLayer">
       <esri:GraphicsLayer.MapTip>
        <Border esri:GraphicsLayer.MapTipHideDelay="00:00:01.5" CornerRadius="10" BorderBrush="#FF222957" BorderThickness="3" Margin="0,0,15,15">
         <Border.Background>
          <LinearGradientBrush EndPoint="1.038,1.136" StartPoint="0.015,0.188">
           <GradientStop Color="#FFD1DFF2"/>
           <GradientStop Color="#FF092959" Offset="0.946"/>
          </LinearGradientBrush>
         </Border.Background>
         <Border.Effect>
          <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" />
         </Border.Effect>
         <StackPanel Orientation="Vertical" Margin="20,15,20,15">
          <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
           <TextBlock Text="TIP ID: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="12" />
           <!--<TextBlock Text="{Binding [TIP_ID]}" Foreground="#FFFFFFFF" FontSize="12" FontStyle="Italic" FontFamily="Portable User Interface" />-->
          </StackPanel>
          <StackPanel Orientation="Horizontal">
           <TextBlock Text="Name: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="12" />
           <!--<TextBlock Text="{Binding [ST_NAME]}" Foreground="#FFFFFFFF" FontSize="12" FontStyle="Italic" FontFamily="Portable User Interface" />-->
          </StackPanel>
         </StackPanel>
        </Border>
       </esri:GraphicsLayer.MapTip> 
      </esri:GraphicsLayer>
Here is the code behind.
#region MapTip

  void MyMap_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
   {
   if (e.PropertyName == "SpatialReference")
    {
    MapTipGraphicsLayerLoad();
    MyMap.PropertyChanged -= MyMap_PropertyChanged;
    }
   }

  void MapTipGraphicsLayerLoad()
   {
   ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query()
   {
    Geometry = new ESRI.ArcGIS.Client.Geometry.Envelope(-180, 0, 0, 90),
    OutSpatialReference = MyMap.SpatialReference
   };
   query.OutFields.Add("*");

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

  void MapTipGraphicsLayerQueryTask_Failed(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs queryArgs)
  {
  MessageBox.Show("Failed") ;
  }

  void MapTipGraphicsLayerQueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs queryArgs)
   {
   
   if (queryArgs.FeatureSet == null)
    return;

   FeatureSet resultFeatureSet = queryArgs.FeatureSet;
   ESRI.ArcGIS.Client.GraphicsLayer graphicsLayer =
   MyMap.Layers["MapTipGraphicsLayer"] as ESRI.ArcGIS.Client.GraphicsLayer;

   if (resultFeatureSet != null && resultFeatureSet.Features.Count > 0)
    {
    foreach (ESRI.ArcGIS.Client.Graphic graphicFeature in resultFeatureSet.Features)
     {
     graphicFeature.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
     graphicsLayer.Graphics.Add(graphicFeature);
     }
    }
   }
#endregion
I know the attempt to catch the failed query is wrong. I couldn't figure out how to "subscribe" to the query failed or mouse enter events. I suspect the problem may be the geometry envelope since I don't know how or what values belong in there. I am not able to get any of the code to fire for the query, nothing pops up etc. Hopefully this will help someone spot my problem. 🙂
0 Kudos
DanielWalton
Occasional Contributor
Your main problem is that you've set up a maptip on a Dynamic map service layer. Maptips only work for layers that inherit from GraphicsLayer. My guess is that you want to pop up a maptip on a point where the user clicks, but don't want the expensive and sluggish FeatureLayer. No problem, just set up a FeatureLayer to buddy up with the DynamicMapServiceLayer (replace "/MapServer" with "FeatureServer/n" where n is the sublayer you want), and set the Mode=QueryMode.OnDemand and use the Where attribute to select one feature at a time. Your maptip XAML will belong in this new layer (since FeatureLayer inherits from GraphicsLayer). You can set the Where attribute after running an identify task on the MapServiceLayer. Some dummy code to illustrate:


       void Map_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            var it = new IdentifyTask(_mapServiceLayer.Url);
            it.ExecuteCompleted += it_ExecuteCompleted;
            var ip = new IdentifyParameters
            {
                LayerOption = LayerOption.all,
                Height = (int)Map.RenderSize.Height,
                Width = (int)Map.RenderSize.Width,
                DPI = (int)Map.Resolution,
                Tolerance = 1,
                Geometry = Map.ScreenToMap(e.GetPosition(Map)),
                MapExtent = Map.Extent,
                SpatialReference = Map.SpatialReference
            };
            it.ExecuteAsync(ip, null);
            IsBusy = true;
        }

        void it_ExecuteCompleted(object sender, IdentifyEventArgs e)
        {
            if (e.IdentifyResults.Count < 1)
            {
                IsBusy = false;
                ErrorMsg("No feature was found at that location");
                return; 
            }

            foreach (var res in e.IdentifyResults)
            {
                if (res.Feature == null || !res.Feature.Attributes.ContainsKey("OBJECTID"))
                    continue;
                var objectid = (string) res.Feature.Attributes["OBJECTID"];
                _featureLayer.Where = "OBJECTID = " + objectid;
                _featureLayer.Update();
                return;
            }
        }
0 Kudos