Select to view content in your preferred language

can't retrieve features on page load

2967
5
01-27-2012 03:49 PM
ForamParikh
Regular Contributor
Hello everything is working fine but if i write the same code in page load then everytime i am getting null graphic if the same code i write in button click event i get fetures.below is code
page load
public Home()
        {
            InitializeComponent();
            getprojects.projectsClient obj = new getprojects.projectsClient();
            obj.GetRegionalRFPCompleted += new EventHandler<getprojects.GetRegionalRFPCompletedEventArgs>(obj_GetRegionalRFPCompleted);
            obj.GetRegionalRFPAsync();
        }
and on button click
getprojects.projectsClient obj = new getprojects.projectsClient();
            obj.GetRegionalRFPCompleted += new EventHandler<getprojects.GetRegionalRFPCompletedEventArgs>(obj_GetRegionalRFPCompleted);
            obj.GetRegionalRFPAsync();

void obj_GetRegionalRFPCompleted(object sender, getprojects.GetRegionalRFPCompletedEventArgs e)
        {
            Graphic g;
            Graphic ggl;
            for (int i = 0; i < e.Result.Count; i++)
            {
                g = new Graphic();


                g.Symbol = LayoutRoot.Resources["DefaultpointSymbol"] as SimpleMarkerSymbol;
                FeatureLayer fl = MyMap.Layers["DynamicLayer"] as FeatureLayer;
                g = fl.Graphics.FirstOrDefault(g111 => (int)g111.Attributes["LOCATION_ID"] == int.Parse(e.Result.LOCATION_ID.ToString()));
               // g = fl.Graphics.FirstOrDefault(g111 => (int)g111.Attributes["LOCATION_ID"] == int.Parse("395"));
                if (g != null)
                {
                    GraphicsLayer gl = MyMap.Layers["glayer"] as GraphicsLayer;
                    ggl = new Graphic();
                    ggl.Geometry = g.Geometry;
                    if (e.Result.PROJSTAT.ToString() == "F" || e.Result.PROJSTAT.ToString() == "P")
                        ggl.Symbol = LayoutRoot.Resources["DefaultpointSymbol"] as SimpleMarkerSymbol;
                    else
                        ggl.Symbol = LayoutRoot.Resources["esriDefaultMarker_40"] as MarkerSymbol;
                    MyMap.PanTo(ggl.Geometry);
                    gl.Graphics.Add(ggl);
                }
            }
        }

please let me know i want to load the graphics on page load not on button click event..

Thanks
Foram
0 Kudos
5 Replies
DominiqueBroux
Esri Frequent Contributor
Do you mean that your 'obj_GetRegionalRFPCompleted' method is not called if you don't click on the button?

It should be called since you hooked up the handler in the constructor.

Sidenote : instead of setting a symbol depending on an attribute by code, I suggest you use an UniqueValue renderer, so the symbol will be set automatically and will be updated when the feature is updated.
0 Kudos
ForamParikh
Regular Contributor
Thanks Dbroux,

Do you mean that your 'obj_GetRegionalRFPCompleted' method is not called if you don't click on the button?

It should be called since you hooked up the handler in the constructor.

Yes I put break point also but eveytime it says 0 count on feature layer.and on button click its working fine and it gives me perfect count please help me i need it on page load.and also after page load if i zoom in with mouse then i can see features.

Sidenote : instead of setting a symbol depending on an attribute by code, I suggest you use an UniqueValue renderer, so the symbol will be set automatically and will be updated when the feature is updated.
but I am using multiple tables and i can't use join because it is having one to many relationship.so i am not sure how i can implement unique value renderer?i will appritiate if you can explain me in detail.my one table is spacial table named point having fields as location_id second table is tabular table project having column as location_id in point there will be unique location_id and in project there are multiple projects with same location_id so if i do join then i can't retrieve all records.

Please help,
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I put break point also but eveytime it says 0 count on feature layer.and on button click its working fine and it gives me perfect count


That seems to mean that your code 'getprojects.projectsClient obj = new getprojects.projectsClient();' needs a specific state to work.

I have no idea about your code, but if it needs another feature layer to be initialized --> call it on event Layer_Intialized.


but I am using multiple tables and i can't use join because it is having one to many relationship.so i am not sure how i can implement unique value renderer?


Your code :
if (e.Result.PROJSTAT.ToString() == "F" || e.Result.PROJSTAT.ToString() == "P")
ggl.Symbol = LayoutRoot.Resources["DefaultpointSymbol"] as SimpleMarkerSymbol;
else
ggl.Symbol = LayoutRoot.Resources["esriDefaultMarker_40"] as MarkerSymbol;


seems to define the symbol from a simple attribute value.
Nothing prevent you to add this attribute to your graphic :
g.Attributes["PROJSTAT"] = e.Result.PROJSTAT.ToString();

That being said, it's not a major point. Just my 2cts.
0 Kudos
ForamParikh
Regular Contributor
I don't know why but i write everything again and check everything again now i am using query and everything is working fine on button click event but on page load I am not getting any features below is my xmal code
<esri:Map x:Name="MyMap"  WrapAround="True"  Extent="-13249239.0000,3982263.0000,-13087512.0000,4087355.0000" ExtentChanged="MyMap_ExtentChanged">
            <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
                />
          
            <esri:FeatureLayer ID="DynamicLayer" Opacity="0.01"
                Url="http://pipelineforthefuture.org/ArcGIS/rest/services/GIC4/Point/MapServer/0"
                />
            <esri:FeatureLayer ID="polygonlayer"
                               AutoSave="False"  Opacity="1.0"  Initialized="FeatureLayer_Initialized"
                               Url="http://pipelineforthefuture.org/ArcGIS/rest/services/GIC4/Poly1/MapServer/0"  
                               OutFields="*"    Visible="True" Where="FLAG='Y'"
                                />
            <esri:GraphicsLayer ID="glayer" Renderer="{StaticResource MyUniqueValueRenderer}"></esri:GraphicsLayer>

        </esri:Map>

on -------------------------------
  private void FeatureLayer_Initialized(object sender, EventArgs e)
        {
            MessageBox.Show((sender as FeatureLayer).Graphics.Count.ToString());
            QueryTask queryTask =
                new QueryTask("http://pipelineforthefuture.org/ArcGIS/rest/services/GIC4/polyjoint/MapServer/1");
            queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
            queryTask.Failed += QueryTask_Failed;

            ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
            //query.Where = "GIC4.DBO.PROJECT_INFO.PROJECT_ID > 275";
            query.Where = "1=1";
            query.OutFields.Add("*");
            queryTask.ExecuteAsync(query);


        }
-----------------------------------------------

FeatureSet featureSet = args.FeatureSet;
            Graphic g;
            Graphic ggl;
            if (featureSet != null && featureSet.Features.Count > 0)
            {
                //QueryDetailsDataGrid.ItemsSource = featureSet.Features;
                //_pagedProductsView = new PagedCollectionView(featureSet.Features.ToList());
                //_pagedProductsView.GroupDescriptions.Add(new PropertyGroupDescription("GIC4.DBO.PROJECT_INFO.PROJSTAT"));
            
                //QueryDetailsDataGrid.ItemsSource = _pagedProductsView;


                PagedCollectionView itemListView = new PagedCollectionView(featureSet);
               
               
               
              
                itemListView.SortDescriptions.Add(new System.ComponentModel.SortDescription("Attributes[GIC4.DBO.PROJECT_INFO.PROJ_NAME]", System.ComponentModel.ListSortDirection.Ascending));
                //itemListView.GroupDescriptions.Add(new PropertyGroupDescription("Attributes[GIC4.DBO.PROJECT_INFO.PROJSTAT]"));
                QueryDetailsDataGrid.ItemsSource = itemListView;
           
                IList<Graphic> gsort = featureSet.Features.OrderBy(x => x.Attributes["GIC4.DBO.PROJECT_INFO.PROJ_NAME"]).ToList();
                featureSet.Features.Clear();
                foreach (var g11 in gsort)
                {
                    featureSet.Features.Add(g11);
                }
              
                GraphicsLayer gl = MyMap.Layers["glayer"] as GraphicsLayer;
               
                foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    g = new Graphic();

                   
                    g.Symbol = LayoutRoot.Resources["DefaultpointSymbol"] as SimpleMarkerSymbol;
                    FeatureLayer fl = MyMap.Layers["polygonlayer"] as FeatureLayer;
                    string a = graphic.Attributes["GIC4.DBO.PROJECT_LOCATION_POLY.LOCATION_ID"].ToString();
                    int k = featureSet.Features.Count(gtt => gtt.Attributes["GIC4.DBO.PROJECT_LOCATION_POLY.LOCATION_ID"] != null && (int)gtt.Attributes["GIC4.DBO.PROJECT_LOCATION_POLY.LOCATION_ID"] == int.Parse(graphic.Attributes["GIC4.DBO.PROJECT_LOCATION_POLY.LOCATION_ID"].ToString()));
                    k = featureSet.Features.Count(gtt => gtt.Attributes["GIC4.dbo.RFP.Project_Id"] != null && (int)gtt.Attributes["GIC4.dbo.RFP.Project_Id"] == 291);
                    g = fl.Graphics.FirstOrDefault(gtt => gtt.Attributes["LOCATION_ID"] != null && (int)gtt.Attributes["LOCATION_ID"] == int.Parse(graphic.Attributes["GIC4.DBO.PROJECT_LOCATION_POLY.LOCATION_ID"].ToString()));
                 
                    ggl = new Graphic();
                    if (g != null)
                    {
                        ggl.Geometry = g.Geometry;
                        if(k >1)
                            ggl.Attributes.Add("PROJSTAT", "M");                     
                            else

                        ggl.Attributes.Add("PROJSTAT", graphic.Attributes["GIC4.DBO.PROJECT_INFO.PROJSTAT"].ToString());                     
                        gl.Graphics.Add(ggl);
                    }
                  

                }
              

            }
            else
                MessageBox.Show("No features returned from query");

        }

Please help me,even on featurelayer_initialized i am getting 0 count.

where i am writing wrong?

Please help,
Foram
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You didn't hook up the Initialized handler to the right layer.

From your code:
FeatureLayer fl = MyMap.Layers["polygonlayer"] as FeatureLayer;

looks like your handler needs the "polygonlayer" to be initialized but you hook up your handler to "dynamiclayer" --> should be to "polygonlayer"

If your code needs more than one layer to be initialized, you can also hook up your handler to Map.Layers.LayersInitialized event. This event is fired when all layers of the map are initialized.
0 Kudos