Select to view content in your preferred language

Adding Popups to a feature layer

1508
3
03-26-2012 02:13 PM
michaelsanchez
Emerging Contributor
Hi,
I have this layer: http://rmgsc.cr.usgs.gov/ArcGIS/rest/services/nhss_haz/MapServer/0/

I'm trying to configure the event of Mouse Over or Click on the feature to show the popup window.
I get nothing..

I think the service is not providing me the information I need for this, but everything else show up ok.

I'm adding the layer in code:
- create a feature layer
- set the url
- set the renderer
- add the layer to the map.

I'm missing something?
Can I add/create the "popup window" on my code based on attributes?

Thanks,
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
A feature layer has no default popup window automatically set.

Please look at this sample that demonstrates how to set an info window for a feature layer.
0 Kudos
HugoCardenas
Emerging Contributor
You can also try MapTips like in this sample.

This sample works fine for me, because all my feature layers are loaded at run-time (code-behind).

You would need to setup the XAML as follows (change the "{Binding [STANAME]}" to any of your columns):
<esri:Map x:Name="MyMap" WrapAround="True">
  <esri:FeatureLayer ID="MyMapTipsLayer" 
       OutFields="*"  Where="OBJECTID >= 0">
  </esri:FeatureLayer>
</esri:Map>

<Canvas HorizontalAlignment="Left" VerticalAlignment="Top" >
   <esri:MapTip x:Name="MyMapTip"  BorderBrush="CornflowerBlue" 
       BorderThickness="2" Title="{Binding [DcomId]}" VerticalOffset="10" 
       HorizontalOffset="10" Background="#C6ECFF" />
</Canvas>


Then, in code-behind (at page load) you assign the feature service to the "MyMapTip" control as follows:

public MainPage()
{
   InitializeComponent();
  
   FeatureLayer fl = MyMap.Layers["MyMapTipsLayer"] as FeatureLayer;
   fl.Url = "http://rmgsc.cr.usgs.gov/ArcGIS/rest/services/nhss_haz/MapServer/0/";
   MyMapTip.GraphicsLayer = fl;
}


Note: Make sure you reference the Systems.Windows.Data.DLL; otherwise, you will get all sort of parse errors.

That is!  You are done!

Hope this helps
Hugo.
0 Kudos
JenniferNery
Esri Regular Contributor
Another way is to set GraphicsLayer.MapTip. FeatureLayer inherits from GraphicsLayer. In this code, we are requesting for all fields and displaying the key-value pair (all attributes). This is triggered on mouse enter. Hovering a feature on your layer displays the maptip. You update the look and feel of your MapTip by adding border as in this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureLayerMapTips. So your options are: InfoWindow, Toolkit.MapTip, or GraphicsLayer.MapTip.

   <esri:FeatureLayer ID="MyLayer" OutFields="*"
          Url="yourServiceUrl">
    <esri:FeatureLayer.MapTip>
     <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>
    </esri:FeatureLayer.MapTip>
   </esri:FeatureLayer>
0 Kudos