Select to view content in your preferred language

Utilize FeatureDataForm via Query not Mouse Event

958
7
04-29-2011 01:01 PM
PaulVepraskas
Frequent Contributor
I would like to utilize the FeatureDataForm for editing point data's attribute information, Since many of my points fall on top of each other I would like to be able to activate and populate the FeatureDataFrom with a query instead of a mouse click?  How can I accomplish this?

Thanks in advance for any help!

Paul
0 Kudos
7 Replies
ThaoLe
by
Regular Contributor
The FeatureDataForm takes a Graphic object as the GraphicSource:
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client.Toolkit~ESRI.ArcGIS.Client.To...

In the sample below:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataForm

The MyFeatureDataForm.GraphicSource is populated by the mouse up event. You can perform a regular query and get the graphics back from the results and pass that to the FeatureDataForm::GraphicSource

Hope this helps!
0 Kudos
PaulVepraskas
Frequent Contributor
Thank you for your help, Im new to Silverlight, Could I get a little bit more direction?

private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            QueryTask queryTask =
            new QueryTask("http://localhost/ArcGIS/rest/services/Caledonia/CaledoniaEDIT/FeatureServer/1");
            queryTask.ExecuteCompleted += editAttribute_data;
            queryTask.Failed += QueryTask_Failed;

            ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
            query.Where = string.Format("id = " + _pointID);
            query.OutFields.Add("*");
            query.ReturnGeometry = true;
            

            queryTask.ExecuteAsync(query);
        }


The point is graphically selected in the folowing code I cannot seem to pass the GraphicSource to the FeatureDataForm I have tried dozens of things, and help would be appreaciated...

private void editAttribute_data(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;

            GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();
                        
            Graphic selectedFeature = featureSet.Features[0];

            selectedFeature.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
            graphicsLayer.Graphics.Add(selectedFeature);

            MyFeatureDataForm.GraphicSource = ?????;


        }
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You have to initialize the GraphicSource property with the graphic you want to see in the dataform.
So in your case:
    MyFeatureDataForm.GraphicSource = SelectedGraphic;


I am also thinking that the FeatureDataform is only working with FeatureLayers (not with GraphicsLayer).
So I would suggest you to use a Featurelayer instead of a graphics layer, the additional advantage is that the query will be managed for you. You have just to initialize the Where clause of the feature layer.

Then you have to initialize the FeatureLayer property of the FeatureDataForm. For exmple in XAML like in the sample:
            <esri:FeatureDataForm x:Name="MyFeatureDataForm"   
                                         FeatureLayer="{Binding Path=Layers[PointLayer], ElementName=MyMap}" 
                                         IsReadOnly="False" LabelPosition="Left" />
0 Kudos
PaulVepraskas
Frequent Contributor
I worked at it all day today with no results, can you give me any more information?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I worked at it all day today with no results, can you give me any more information?


Difficult to guess what is not working with so few infos.
As Thang mentionned, the closest sample of what you have to do is this one : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataForm

It could be a good idea to make first working this sample in your context and then try to adapt it to your exact need.
0 Kudos
MattPratap
Deactivated User
As Thang mentionned, the closest sample of what you have to do is this one : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataForm

It could be a good idea to make first working this sample in your context and then try to adapt it to your exact need.


I also have the same problem, and did as Thang said: to set the FeatureDataForm.GraphicSource to the graphic that came back from the query.  That did not work.
But using the graphic from the MouseLeftButtonUp event does work.

This example works:
private void MyFeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args)
{
            FeatureLayer featureLayer = sender as FeatureLayer;   //references MyFeatureLayer defined in Map Layers in xaml
            featureDataForm.FeatureLayer = featureLayer;
            featureDataForm.GraphicSource = args.Graphic;
}


But this example does not:
        private void MyFeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args)
        {
            FeatureLayer featureLayer = sender as FeatureLayer;
            //perform query instead on the objectid, to demonstrate query
            int objectId = (int) args.Graphic.Attributes["OBJECTID"];
            QueryTask queryTask = new QueryTask(featureLayer.Url);
            queryTask.ExecuteCompleted += MS4QueryTask_ExecuteCompleted;
            queryTask.Failed += MS4QueryTask_Failed;

            Query query = new ESRI.ArcGIS.Client.Tasks.Query();
            query.ObjectIDs = new int[1] { objectId };
            query.OutFields.Add("*");
            query.ReturnGeometry = true;

            //If query is sucessful fire off AQueryTask_ExecuteCompleted
            queryTask.ExecuteAsync(query);
       }

        private void MS4QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;

            if (featureSet != null && featureSet.Features.Count > 0)
            {
                foreach (Graphic feature in featureSet.Features)
                {  //should only be 1 since we searched on objectid
                     featureDataForm.FeatureLayer = MyFeatureLayer;
                     featureDataForm.GraphicSource = args.Graphic;
                }
           }
       }



Maybe I overlooked something obvious, but it seems that the Graphic coming back from the query is substantially different from the graphic coming from the GraphicMouseButtonEventArgs. maybe the graphic coming back from the query doesnt have the required association to the feature layer. Since everything else to do with the featureDataForm is essentially the same.
0 Kudos
MattPratap
Deactivated User
I found what the problem is.  This forum post explains:

http://forums.arcgis.com/threads/18708-Problem-selecting-features-from-a-Feature-Layer?p=59570&viewf...


When you edit a feature returned by QueryTask, you are not affecting the same instance contained in your FeatureLayer. You need to edit features from your FeatureLayer.Graphics.


So Thang was incorrect.
After you get your result graphic from the query you cannot use that as the  featureDataForm.GraphicSource.  You need to find that same feature from your feature layer and use that as the featureDataForm.GraphicSource.  That post shows an example of that.

After do as suggested in that post, I was able to edit the feature in the FeatureDataForm.
0 Kudos