Select to view content in your preferred language

Bug with Editor Selection when toggling Feature layer from Snapshot to SelectionOnly

3013
11
12-07-2010 08:44 AM
MikeKaufman
Emerging Contributor
I think I have found a bug when toggling between SelectionOnly and Snapshot on a feature layer to select graphics.  I am using the editor to make spatial selections but also need the capability to make a selection by querying the attributes.  Once this toggle happens you can no long remove graphics spatially from the a set of selected graphics anymore

I have attached a WPF project using FW 4.0 and the WPF API 2.1 to demonstrate the bug

Here a the steps to repo
1. Implement the Editor to perform spatial selections
2. Toggle Selection Feature Layer to Snap shot, provide a query, and call update
3. Handle update completed and toggle Selection Feature Layer back to SelectionOnly and  where to nothing (null)
4. Try to spatially remove a graphic from the selection return from the snapshot query
5. All graphics are removed.
6. Try making new selection spatially
7. Remove a selection spatially (notice all selected graphics are removed.
Thanks in advance to anyone how can help me find a solution or workaround to this issue.
0 Kudos
11 Replies
JenniferNery
Esri Regular Contributor
I tried your code and came across the following issues:
1 - Button1_Click is never going to be hit unless you add Click="Button1_Click" in xaml
2 - SelectionLayer_UpdateCompleted is never going to be hit unless you make the following changes
3 - Since Where property is modified, Update() on the layer needs to be invoked again

(Not sure how correct VB conversion is but hopefully you get the idea).
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim SelectionLayer As FeatureLayer = CType(Me.MyMap.Layers("CensusDemographics"),FeatureLayer)
        SelectionLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.Snapshot
        SelectionLayer.Where = "POP2000 < 100"
        SelectionLayer.UpdateCompleted = (SelectionLayer.UpdateCompleted + SelectionLayer_UpdateCompleted)
        SelectionLayer.Update
    End Sub

 Private Sub SelectionLayer_UpdateCompleted(ByVal sender As Object, ByVal e As System.EventArgs)
        SelectionLayer = CType(sender,ESRI.ArcGIS.Client.FeatureLayer)
        SelectionLayer.UpdateCompleted = (SelectionLayer.UpdateCompleted - SelectionLayer_UpdateCompleted)
        SelectionLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.SelectionOnly
        SelectionLayer.Where = "1=1"
        SelectionLayer.Update
    End Sub


Notice that if you check value for SelectionLayer before code for Button1_Click is executed, it is null. Map layers are accessible by their ID not by their Name. Which is probably why you felt you needed to type cast the sender to FeatureLayer in the UpdateCompleted event handler.

Also, I'm not sure why you would want to switch the mode of FeatureLayer at run-time. Using the layer for dual purpose does not sound like a good approach(just my opinion).
0 Kudos
MikeKaufman
Emerging Contributor
Did you run the project that I attached, everything is working as far as I can tell.

Button1_Click does get handled because that Method Handles Button1.Click in code behind. (The VB way of adding an Address Of).  So the same goes for SelectionLayer_UpdateCompleted it handles SelectionLayer.UpdateCompleted.

To address your comment
Also, I'm not sure why you would want to switch the mode of FeatureLayer at run-time. Using the layer for dual purpose does not sound like a good approach(just my opinion).


I mentioned why i need to do this at the beggining of this post
I am using the editor to make spatial selections but also need the capability to make a selection by querying the attributes.


I am confused as to why calling update on the selection layer in the event handler method of updateCompleted could solve this issue.  Calling update clears all graphics from the layer. 
        SelectionLayer.Where = "1=1"
        SelectionLayer.Update()


Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
Ah okay. I was not able to run the project directly. I had to copy VB code and translate to C#.

At any case, Update() is essential when the parameters of the Query changes. Since Where part changed, you need to run the Query again.
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...
0 Kudos
MikeKaufman
Emerging Contributor
Ah okay. I was not able to run the project directly. I had to copy VB code and translate to C#.

At any case, Update() is essential when the parameters of the Query changes. Since Where part changed, you need to run the Query again.
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...


This is exactly why I am confused.  here is the order of events that ultimatly make calling the update not work.
1.  Swtich layer from Selection Only to snapshot and set where 'Field = x'
2.  call update
3.  handle the updatedCompleted event, switching my selection mode back to SelectionOnly and where to 1=1. 
You are proposing that I need to call update inside of step 3 which is the event that tells me my snapshot query is finished.  If I call update inside of this it clears the selection that was return from the snapshot query.

I am trying some things and one test I am doing is to store off the return graphics before calling update.  Once I call update I add those graphics back to the selection layer.  However when I do that I can no longer remove those graphics in SelectionOnly mode.

Thank you for any suggestions on how I might work around this.
0 Kudos
MikeKaufman
Emerging Contributor
Ok, I think I almost have my work around working ;P.

I am storing off the graphcis returned from the snap shot query, then I call update, last I add the graphics back to the selection layer.  The reason it was not work before was I had set my out fields to one field name.  Once I set it to the wildcard '*' things started working.  I am guessing the reason it started working is when the layer in snapshot mode and ourfields are defined to return a limited number of attributes the graphics are not fully returned?

My question now is how do I set the layer to returnGeometry=true in snapshot mode.

Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
I'm sorry that I am also confused with what you are trying to achieve with your code. It seems that the only time the layer is in Snapshot mode is when you click the button, right? At which time, you call update(), once update is complete, you change the layer back to SelectionOnly mode. While switching modes, you also update Where clause. If you do not need to update Where clause then Update() does not need to be called.

I think that it's better to have two FeatureLayers one for each mode to avoid confusion. The use case you described here is not supported and I am not sure what other issues you may encounter when toggling modes without calling Update().

If you wish to continue with your current code. A workaround is to also include ObjectID in your OutFields.
0 Kudos
JenniferNery
Esri Regular Contributor
The reason it did not work before is because ObjectID field is missing and is only injected in the query if specified in OutFields or Update() is called for SelectionOnly mode.

ReturnGeometry is already set to True for FeatureLayer regardless of the Mode. There is no public property in FeatureLayer that can change this property.
0 Kudos
MikeKaufman
Emerging Contributor
I'm sorry that I am also confused with what you are trying to achieve with your code. It seems that the only time the layer is in Snapshot mode is when you click the button, right? At which time, you call update(), once update is complete, you change the layer back to SelectionOnly mode. While switching modes, you also update Where clause. If you do not need to update Where clause then Update() does not need to be called.

I think that it's better to have two FeatureLayers one for each mode to avoid confusion. The use case you described here is not supported and I am not sure what other issues you may encounter when toggling modes without calling Update().

If you wish to continue with your current code. A workaround is to also include ObjectID in your OutFields.


The button in the example solution is to quickly simulate an atribute query.  The reason I need to set the where proptery back to 1=1 is so my SelectionOnly spatial query is not filtered.

My ultimate goal is to be able to do selection on the map with both the a spatail query and attribute query.  Example:  I want to select 10 graphics with a query (snapshot mode) Field in (1,2,3,4,5,6,7,8,9,10) then I decide (spatialy) that I do not want 6 as part of my selection.  So I ativate the Select with "Remove" as my Command Parameter to remove 6 my clicking on the map.

I have the funcationality I want working now, it is just a lot of ugly work around management of graphics returned from the snapshot mode.  I am still finding that I am forced to add '*' to my output fields to make everything work.

Thanks for your time.
0 Kudos
JenniferNery
Esri Regular Contributor
As long as OutFields include the ObjectId field you should be fine, you don't need to force it to "*".
0 Kudos