Select to view content in your preferred language

Query a REST layer

770
4
04-15-2010 02:53 AM
AgatinoLa_Rosa
Emerging Contributor
Greetings

I have a Silverlight application with several services. One of these services is declared as ArcGISDynamicMapServiceLayer in xaml and contains 3 layers. I would like to filter features from one of these layers with ID=0 using a simple query string in C#. How should I structure the where instruction? Thanks
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
The LayerDefinitions property (ArcGISDynamicMapServiceLayer class) allows you to define queries by sublayer of your service.

Example :
layerDefinitions = new System.Collections.ObjectModel.ObservableCollection<LayerDefinition>();
LayerDefinition layerDefinition = new LayerDefinition();
layerDefinition.LayerID = 0;
layerDefinition.Definition = "subtype = 2";
layerDefinitions.Add(layerDefinition);
 
myMapServiceLayer.LayerDefinitions = layerDefinitions;


Dominique
0 Kudos
AgatinoLa_Rosa
Emerging Contributor
Could you please specify in which document I should add your code (in my Silverlight application I have used the xaml and the cs documents). Thanks
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Starting from a map application template, you can just add the code in MainPage.xaml.cs.

Example of code displaying the earthquakes in california since 1950 as DynamicMapServiceLayer:

public MainPage()
{
 InitializeComponent();

 System.Collections.ObjectModel.ObservableCollection<LayerDefinition> layerDefinitions;
 ArcGISDynamicMapServiceLayer myMapServiceLayer = Map.Layers["California"] as ArcGISDynamicMapServiceLayer;

 layerDefinitions = new System.Collections.ObjectModel.ObservableCollection<LayerDefinition>();
 LayerDefinition layerDefinition = new LayerDefinition();
 layerDefinition.LayerID = 2;
 layerDefinition.Definition = "YEAR > 1950";
 layerDefinitions.Add(layerDefinition);
 myMapServiceLayer.VisibleLayers = new int[] { 2 };

 myMapServiceLayer.LayerDefinitions = layerDefinitions;
}


The MainPage.xaml must also be completed with the declaration of the dynamic service:
<esri:ArcGISDynamicMapServiceLayer ID="California" Url="http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer" />



Note that this example is 'XAMLable'. Yo can get the same result without any C# code by modifying the .xaml file only:
<esri:ArcGISDynamicMapServiceLayer ID="California"
  Url="http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer"
  VisibleLayers="2" >
 <esri:ArcGISDynamicMapServiceLayer.LayerDefinitions>
  <esri:LayerDefinition LayerID="2" Definition="YEAR > 1950" />
 </esri:ArcGISDynamicMapServiceLayer.LayerDefinitions>   
</esri:ArcGISDynamicMapServiceLayer>


/Dominique
0 Kudos
AgatinoLa_Rosa
Emerging Contributor
Thanks Dominique

sorry I am replying this late. I have just tried your code and it works perfectly.

I appreciate your help.
0 Kudos