Select to view content in your preferred language

SpatialQueryAction & dataGrid

2298
27
06-21-2012 05:58 AM
MiriEshel
Esri Contributor
Hi,

Is there a way to show a DataGrid of the selected features using SpatialQueryAction.

There is a sample called: http://resourcesbeta.arcgis.com/en/help/silverlight-api/samples/start.htm#GraphicsActions
I want to extend this sample to show also the dataGrid of the selection's result.

Thanks a lot,
Miri
0 Kudos
27 Replies
JoeHershman
MVP Alum
Hi,

Is there a way to show a DataGrid of the selected features using SpatialQueryAction.

There is a sample called: http://resourcesbeta.arcgis.com/en/help/silverlight-api/samples/start.htm#GraphicsActions
I want to extend this sample to show also the dataGrid of the selection's result.

Thanks a lot,
Miri


Have you looked at the FeatureDataGrid sample http://resourcesbeta.arcgis.com/en/help/silverlight-api/samples/start.htm#FeatureDataGrid?

With the SpatialQueryAction you are passing in the LayerId of the graphics layer that you want the results to be displayed on.  I think that if you bind a FeatureDataGrid to that Graphics layer it should display the results like you want (disclaimer: I have not tried this yet :))


        <esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid" Map="{Binding ElementName=MyMap}"
                GraphicsLayer="{Binding ElementName=MyMap, Path=Layers[LayerIDPassedToAction]}" />



Good Luck
Thanks,
-Joe
0 Kudos
MiriEshel
Esri Contributor
Hi Joe,

It looks promising. I will try it soon and let you know.

Thanks a lot,
Miri
0 Kudos
MiriEshel
Esri Contributor
Hi Joe,

Thanks. it works. So nice and simple to developers that are familiar with the code...

Anyway...Now I have two other questions regarding SpatialQueryAction:
1. I try to set the Url of the SpatialQueryAction by binding it to an object that I defined: _ActiveLayer.URL.
Here is the code:
                   <Button Content="Spatial Query" Name="selRectangle" >
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                              <esri:SpatialQueryAction
                                    DrawMode="Rectangle"
                                    LayerID="MyQueryResultsGraphicsLayer"
                                    Symbol="{StaticResource DefaultLineSymbol}"
                                    TargetName="Map" />
                                            <actions:SetLayerUrlAction Url="{Binding _ActiveLayer.URL}"/>
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Button>

It gives me the error attached although I check _ActiveLayer.URL and it has a good value.
I need also to take care of cases that _ActiveLayer.URL is null and give a message in that case.

2. I have a toolbar where I keep always the selected tool. After using the  SpatialQueryAction, I don't know how to restore the selected tool that was used before SpatialQueryAction. It always give me Pan functionality after using SpatialQueryAction. Is there a way to run a chunk of code after the operation is finished?
I can use the queryTask but I think it's less elegant than SpatialQueryAction.

Thanks so much, I really appreciate it.

Thanks again,
Miri
0 Kudos
JoeHershman
MVP Alum
Miri,

I think you forgot to attach the error message :eek:

As for question 2, from what I can see (thanks to .net reflecter) all the Action does is populate the Graphics layer in the ExecuteComplete handler of the QueryTask.  It does not seem to throw off any other notification.  I think you are probably just as well off doing your own Query, you could even write it as a TriggerAction that fires an event on completion.

As strange as this sounds, in many ways I think they most complicated aspect to writing a large application with an ESRI Web Client API (flex also) is handling interactions of tools and buttons with features and the map.  I have spent considerable amounts of time developing infrastructure that manages this interaction with notifications between tools so everything knows how the next mouse click should be handled.

In this case one quick and dirty way (as opposed to simple and elegant ;)) might be to add a CollectionChanged handler to your GraphicsLayer:Graphics collection.  So when the points are added to the GraphicsLayer as a result of the query you will catch it and can flip the tool back on.  Of course if the query returns nada well then.....?

Good luck
-Joe
Thanks,
-Joe
0 Kudos
MiriEshel
Esri Contributor
Hi Joe,

Thank you for your quick reply. You are all so quick & helpful.

Yes, I guess: if the query returns nada well then.....? is a problem so I think I will withdraw (or progress, depends how you look at it) to the queryTask option. The SpatialQueryAction looks
tempting because it is very short but it is limited for what I need.
Anyway I attach the error message due to the binding: <actions:SetLayerUrlAction Url="{Binding _ActiveLayer.URL}"/>
(When I put ahard coded url it works fine).

Another question regards binding to symbol. The symbol is chaned from lineSymbol to MarkerSymbol to FillSymbol depends on the type of active layer (line, point or polygon).
How can I know which symbol to bind?
In all the samples, the layer is hard coded so i guess I muss this part.

Thanks a lot,
Miri
0 Kudos
JoeHershman
MVP Alum
It's pretty hard to say without understanding how the DataContext is being set. but are you implementing the INotifyPropertyChanged in your _activeLayer object?  This is required to notify the object bound in Xaml that something changed in the bound object.

As for the symbol, if you have a Url being bound you could also bind a Symbol.


   Symbol="{Binding _activeLayer.Symbol}"


When you set the Url you know the type of layer it is (point, line, polygon) and can set the appropriate symbol type at that time.
Thanks,
-Joe
0 Kudos
MiriEshel
Esri Contributor
Hi Joe,

I do implement INotifyPropertyChanged. Here is the code:

    public  abstract class EventBase : INotifyPropertyChanged  
     { 
         public event PropertyChangedEventHandler PropertyChanged; 
         protected void PropertyChangedHandler(string propertyName)  
         {  
             var handler = PropertyChanged;  
             if (handler != null)  
             {  

                 handler(this, new PropertyChangedEventArgs(propertyName));  
             }  
         }  
     }  

  public class ActiveLayer : EventBase
    {
        private string name;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
                PropertyChangedHandler("Name");
            }
        }

        private string url;
        public string URL
        {
            get
            {
                return url;
            }
            set
            {
                url = value;
                PropertyChangedHandler("URL");
            }
        }
       
    }

Thanks,
Miri
0 Kudos
JoeHershman
MVP Alum
I guess the follow-up question is where/how are you setting the DataContext of your Control?
Thanks,
-Joe
0 Kudos
MiriEshel
Esri Contributor
Joe,

Do you mean the Button control? Here it is (with or without dataContext it gives me an error):

                              <Button DataContext="{Binding ElementName=Map}" Content="Spatial Query" Name="selRectangle" >
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                                <esri:SpatialQueryAction
                                    DrawMode="Rectangle"
                                    LayerID="MyQueryResultsGraphicsLayer"
                                    Symbol="{StaticResource DefaultLineSymbol}"
                                    TargetName="Map" />
                                            <actions:SetLayerUrlAction Url="{Binding _ActiveLayer.URL}"/>
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Button>

I admire your patience....

Thanks,
Miri
0 Kudos