Select to view content in your preferred language

maptip is not updated

974
8
03-28-2011 09:11 AM
ThaoNguyen
Emerging Contributor
I create maptip for my map. Everything is working fine except that when I update data that are associated with my map, the first time I mouse over a region, the maptip value is not updated, it still shows the old data until I mouse over another region then come back to the first one, it is updated.  What can I do?  Is this a bug from Arcgis?
0 Kudos
8 Replies
JenniferNery
Esri Regular Contributor
I cannot replicate the issue with the following code:
In this sample, I update the number of households and print in the OutputWindow its old value so I can compare the result displayed in my map tip.
   <esri:FeatureLayer ID="MyStateLayer" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" OutFields="*" 
          MouseEnter="FeatureLayer_MouseEnter">
    <esri:FeatureLayer.MapTip>
     <TextBlock Text="{Binding [HOUSEHOLDS]}"/>
    </esri:FeatureLayer.MapTip>
   </esri:FeatureLayer>


  private void FeatureLayer_MouseEnter(object sender, GraphicMouseEventArgs e)
  {
   var oldVal = (int)e.Graphic.Attributes["HOUSEHOLDS"];
   System.Diagnostics.Debug.WriteLine(oldVal);
   e.Graphic.Attributes["HOUSEHOLDS"] = oldVal + 1;
  }
0 Kudos
ThaoNguyen
Emerging Contributor
I cannot replicate the issue with the following code:
In this sample, I update the number of households and print in the OutputWindow its old value so I can compare the result displayed in my map tip.
   <esri:FeatureLayer ID="MyStateLayer" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" OutFields="*" 
          MouseEnter="FeatureLayer_MouseEnter">
    <esri:FeatureLayer.MapTip>
     <TextBlock Text="{Binding [HOUSEHOLDS]}"/>
    </esri:FeatureLayer.MapTip>
   </esri:FeatureLayer>


  private void FeatureLayer_MouseEnter(object sender, GraphicMouseEventArgs e)
  {
   var oldVal = (int)e.Graphic.Attributes["HOUSEHOLDS"];
   System.Diagnostics.Debug.WriteLine(oldVal);
   e.Graphic.Attributes["HOUSEHOLDS"] = oldVal + 1;
  }


the way we update data is different.  We query the map, add graphics to map and associate our data to map.  The data we have are NOT graphic attribute values.  There are cases that we update our data and we do update the map graphics again by clear the graphics and readd them with new data.  In this case, the maptip doesn't behave right.
0 Kudos
JenniferNery
Esri Regular Contributor
Can you share with us your code? The MapTip displays values from graphic attributes, even when these graphics come as a result of a Query.

I am using the following SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#GraphicsMapTip with the following code-change.

In this sample, I have 2 attributes that I display in my MapTip. One is from the service and the other is a made up attribute that I modify in my code. You can see in the Output window its previous value and in the Maptip its new value. I see that the map tip is updated. If you have some code to share or steps to reproduce, that will be great.
  <Grid.Resources>
   <esri:SimpleRenderer x:Key="MyRenderer">
    <esri:SimpleRenderer.Symbol>
     <esri:SimpleFillSymbol Fill="Red"/>
    </esri:SimpleRenderer.Symbol>
   </esri:SimpleRenderer>
  </Grid.Resources>

   <esri:GraphicsLayer ID="MyGraphicsLayer" Renderer="{StaticResource MyRenderer}" MouseEnter="GraphicsLayer_MouseEnter">
    <esri:GraphicsLayer.MapTip>
     <StackPanel>
      <TextBlock Text="{Binding [MyAttribute]}"/>
     <TextBlock Text="{Binding [HOUSEHOLDS]}"/>
     </StackPanel>
    </esri:GraphicsLayer.MapTip>
   </esri:GraphicsLayer>


void StatesGraphicsLayerQueryTask_ExecuteCompleted(object sender, QueryEventArgs e)
{
 GraphicsLayer layer = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
 foreach (var g in e.FeatureSet.Features)
 {
  Random r = new Random();
  g.Attributes["MyAttribute"] = r.Next(0, 10);
  layer.Graphics.Add(g);
 }
}

private void GraphicsLayer_MouseEnter(object sender, GraphicMouseEventArgs e)
{
 var oldVal = (int)e.Graphic.Attributes["MyAttribute"];
 System.Diagnostics.Debug.WriteLine(oldVal);
 e.Graphic.Attributes["MyAttribute"] = oldVal + 1;
}
0 Kudos
ThaoNguyen
Emerging Contributor
Can you share with us your code? The MapTip displays values from graphic attributes, even when these graphics come as a result of a Query.

I am using the following SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#GraphicsMapTip with the following code-change.

In this sample, I have 2 attributes that I display in my MapTip. One is from the service and the other is a made up attribute that I modify in my code. You can see in the Output window its previous value and in the Maptip its new value. I see that the map tip is updated. If you have some code to share or steps to reproduce, that will be great.
  <Grid.Resources>
   <esri:SimpleRenderer x:Key="MyRenderer">
    <esri:SimpleRenderer.Symbol>
     <esri:SimpleFillSymbol Fill="Red"/>
    </esri:SimpleRenderer.Symbol>
   </esri:SimpleRenderer>
  </Grid.Resources>

   <esri:GraphicsLayer ID="MyGraphicsLayer" Renderer="{StaticResource MyRenderer}" MouseEnter="GraphicsLayer_MouseEnter">
    <esri:GraphicsLayer.MapTip>
     <StackPanel>
      <TextBlock Text="{Binding [MyAttribute]}"/>
     <TextBlock Text="{Binding [HOUSEHOLDS]}"/>
     </StackPanel>
    </esri:GraphicsLayer.MapTip>
   </esri:GraphicsLayer>


void StatesGraphicsLayerQueryTask_ExecuteCompleted(object sender, QueryEventArgs e)
{
 GraphicsLayer layer = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
 foreach (var g in e.FeatureSet.Features)
 {
  Random r = new Random();
  g.Attributes["MyAttribute"] = r.Next(0, 10);
  layer.Graphics.Add(g);
 }
}

private void GraphicsLayer_MouseEnter(object sender, GraphicMouseEventArgs e)
{
 var oldVal = (int)e.Graphic.Attributes["MyAttribute"];
 System.Diagnostics.Debug.WriteLine(oldVal);
 e.Graphic.Attributes["MyAttribute"] = oldVal + 1;
}


I wish I could share the code...
Anyway, the difference between your sample and mine is that I do not implement  GraphicsLayer_MouseEnter event handler.  I did a DictionaryConverter and bind maptip value to a graphic attribute (like you did).  Am I supposed to implement the mouserEnter event handler in addition to MapTip???
0 Kudos
ThaoNguyen
Emerging Contributor
I wish I could share the code...
Anyway, the difference between your sample and mine is that I do not implement  GraphicsLayer_MouseEnter event handler.  I did a DictionaryConverter and bind maptip value to a graphic attribute (like you did).  Am I supposed to implement the mouserEnter event handler in addition to MapTip???


By the way, I'm using MapTip for graphic layer like below:
<esri:GraphicsLayer x:Name="GraphicLayer" ID="ResultMap" Opacity="0.85">
                    <!-- map tip -->
                    <esri:GraphicsLayer.MapTip>   <maptip content here></esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
0 Kudos
ThaoNguyen
Emerging Contributor
Can you share with us your code? The MapTip displays values from graphic attributes, even when these graphics come as a result of a Query.

I am using the following SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#GraphicsMapTip with the following code-change.

In this sample, I have 2 attributes that I display in my MapTip. One is from the service and the other is a made up attribute that I modify in my code. You can see in the Output window its previous value and in the Maptip its new value. I see that the map tip is updated. If you have some code to share or steps to reproduce, that will be great.
  <Grid.Resources>
   <esri:SimpleRenderer x:Key="MyRenderer">
    <esri:SimpleRenderer.Symbol>
     <esri:SimpleFillSymbol Fill="Red"/>
    </esri:SimpleRenderer.Symbol>
   </esri:SimpleRenderer>
  </Grid.Resources>

   <esri:GraphicsLayer ID="MyGraphicsLayer" Renderer="{StaticResource MyRenderer}" MouseEnter="GraphicsLayer_MouseEnter">
    <esri:GraphicsLayer.MapTip>
     <StackPanel>
      <TextBlock Text="{Binding [MyAttribute]}"/>
     <TextBlock Text="{Binding [HOUSEHOLDS]}"/>
     </StackPanel>
    </esri:GraphicsLayer.MapTip>
   </esri:GraphicsLayer>


void StatesGraphicsLayerQueryTask_ExecuteCompleted(object sender, QueryEventArgs e)
{
 GraphicsLayer layer = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
 foreach (var g in e.FeatureSet.Features)
 {
  Random r = new Random();
  g.Attributes["MyAttribute"] = r.Next(0, 10);
  layer.Graphics.Add(g);
 }
}

private void GraphicsLayer_MouseEnter(object sender, GraphicMouseEventArgs e)
{
 var oldVal = (int)e.Graphic.Attributes["MyAttribute"];
 System.Diagnostics.Debug.WriteLine(oldVal);
 e.Graphic.Attributes["MyAttribute"] = oldVal + 1;
}


With your code, instead of updating value from GraphicsLayer_MouseEnter(), please try to add a separate button on your map panel, clicking on it will fire an event which clears the graphics added, then add new ones with new data.  Now, go to map and mouse over, I think this may recreate the problem I'm having. The first graphic tip will be the old data, move the mouse to another feature will get the updated data.
0 Kudos
JenniferNery
Esri Regular Contributor
I removed GraphicsLayer.MouseEnter and updated the graphic on a button click event my map tip still shows the new value. Please try the attached sample.
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
 GraphicsLayer layer = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
 var graphic = layer.Graphics.FirstOrDefault(g => (int)g.Attributes["ObjectID"] == 24);
 if (graphic != null)
 {
  var oldVal = (int)graphic.Attributes["MyAttribute"];
  System.Diagnostics.Debug.WriteLine(oldVal);
  graphic.Attributes["MyAttribute"] = oldVal + 1;
 }
}


If you can tweak this sample and let me know the steps to reproduce the issue you are seeing with Maptip, that would be great.
0 Kudos
ThaoNguyen
Emerging Contributor
I removed GraphicsLayer.MouseEnter and updated the graphic on a button click event my map tip still shows the new value. Please try the attached sample.
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
 GraphicsLayer layer = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
 var graphic = layer.Graphics.FirstOrDefault(g => (int)g.Attributes["ObjectID"] == 24);
 if (graphic != null)
 {
  var oldVal = (int)graphic.Attributes["MyAttribute"];
  System.Diagnostics.Debug.WriteLine(oldVal);
  graphic.Attributes["MyAttribute"] = oldVal + 1;
 }
}


If you can tweak this sample and let me know the steps to reproduce the issue you are seeing with Maptip, that would be great.


Thanks Jennifer for your effort!  I cannot recreate the problem with your code either.  I guess maybe something else that causes the problem.
0 Kudos