Select to view content in your preferred language

Selected feature is not displaying in Graphics Layer

1034
3
10-03-2011 04:19 PM
GirishSomesh
Deactivated User
Hi All,

I have to display an Active hurricane on a Graphiclayer on change of dropdownlist.
Below is the code, I am not sure where i am going wrong can any one help me out.

private void ActiveCurentLocation()
         {
             string oAQUrl = "http://esrilabs1.esri.com/ArcGIS/rest/services/LiveFeeds/Hurricane_Active/MapServer/0";
             QueryTask AQExeQueryTaskActivelocation = new QueryTask(oAQUrl);
             AQExeQueryTaskActivelocation.ExecuteCompleted += AQExeQueryTaskActivelocation_ExecuteCompleted;
             ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
             string querytext = "STORMNAME='PHILLIPPE'";// + strActiveH + "'";// +"' AND FCSTPRD = 120";//PHILLIPPE' AND FCSTPRD = 120";//PHILLIPPE//HILARY
             query.Text = querytext;
             query.Where = querytext;
             query.OutFields.Add("*");
             query.ReturnGeometry = true;
             AQExeQueryTaskActivelocation.ExecuteAsync(query);
         }

void AQExeQueryTaskActivelocation_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
         {
             FeatureSet featureSet = args.FeatureSet;
             GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
    graphicsLayer.Visible=true;
             graphicsLayer.Initialized += new EventHandler<EventArgs>(MyGraphicsLayer_Initialized);
             if (featureSet != null && featureSet.Features.Count > 0)
             {
                int oCount = featureSet.Features.Count;
    Graphic selectedFeature = featureSet.Features[0];
    selectedFeature.Symbol=PushpinSymbol;
                graphicsLayer.Visible = true;
                selectedFeature.Selected = true;
                graphicsLayer.Refresh();
                graphicsLayer.Graphics.Add(selectedFeature);

             }
             else
             {

             }
         }

private void MyGraphicsLayer_Initialized(object sender, EventArgs args)
         {

         }

XMAL CODE:
<esriSymbols:PictureMarkerSymbol x:Name="PushpinSymbol" OffsetX="11" OffsetY="39" Height="30" Width="25" Source="Images/i_pushpin.png" />

<esri:GraphicsLayer ID="MyGraphicsLayer"  Visible="True"></esri:GraphicsLayer>


Thanks.
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
At first glance, I don't see anything wrong in your code.

Juts check that your query returns some features (i..e featureSet.Features.Count > 0) and that the image used by your symbol (i.e Images/i_pushpin.png) has been defined as resource in the Images directory of your project.
0 Kudos
GirishSomesh
Deactivated User
Dominique,

I cheked in my code query returns values and Pushpin image is also defined in Image folder of the project directory. I cheked in my page i am getting following js error...


Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GIL 3; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; GIL3)
Timestamp: Tue, 4 Oct 2011 13:27:28 UTC


Message: Unhandled Error in Silverlight Application Object reference not set to an instance of an object.   at POBESRISApp.MainPage.AQExeQueryTaskActivelocation_ExecuteCompleted(Object sender, QueryEventArgs args)
   at ESRI.ArcGIS.Client.Tasks.QueryTask.OnExecuteCompleted(QueryEventArgs args)
   at ESRI.ArcGIS.Client.Tasks.QueryTask.<>c__DisplayClass6.<request_Completed>b__4(FeatureSet fs, Exception ex)
   at ESRI.ArcGIS.Client.Tasks.FeatureSet.<>c__DisplayClass2.<FromJsonAsync>b__0(Object s, RunWorkerCompletedEventArgs e)
   at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
   at System.ComponentModel.BackgroundWorker.<OnRun>b__1(Object state)
Line: 1
Char: 1
Code: 0
URI: http://localhost:52847/Silverlight.js

0 Kudos
HugoCardenas
Emerging Contributor
This line in your "AQExeQueryTaskActivelocation_ExecuteCompleted" event handler would throw a similar exception if features are not returned:
FeatureSet featureSet = args.FeatureSet;


I would use (in this scenario):
if (args.FeatureSet== null) return;

Then, I would issue:
FeatureSet featureSet = args.FeatureSet;


Also, I would define the "Failed", besides ExecuteCompleted,  event handler as well to check if another cause is procducing the exception.

Hugo.
0 Kudos