FeatureLayer:DefinitionExpression not honored on sync

262
4
03-22-2018 08:12 AM
JoeHershman
MVP Regular Contributor

We have noticed that when a FeatureLayer has a DefinitionExpression assigned and a feature gets synced from the server the display does not honor the DefinitionExpression.

As example.  A FeatureLayer.DefinitionExpression = "STATUS = 'Active'".  When the STATUS value is changed at the server to something other than Active the attribute update does sync across as expected and the STATUS field is changed in the offline database.  However, the feature is still visible even though it no longer meets the DefinitionExpression.  If the application is closed and re-opened the feature is no longer visible as expected.

We have tried moving the map, thinking maybe a redraw would refresh the layer but this does not work either.

Is there a way to reapply the DefinitionExpression.  I was going to try to toggle the expression off then back on but that seems more of a hack then I want to do. 

Thanks

0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor

Thank you for reporting this bug. We have logged the issue and I had just verified core fix. Please try again in the next release of ArcGIS Runtime SDK for .NET.

I also could not find an elegant workaround for this. I don't know if it's an option for you to temporarily remove the layer from the map until SyncGeodatabaseJob completes.

MyMapView.Map.OperationalLayers.Remove(layer);
var result = await job.GetResultAsync();
MyMapView.Map.OperationalLayers.Add(layer);

Should you decide to reset `FeatureLayer.DefinitionExpression`, you might also want to set the visibility of the features that do not satisfy definition expression.

// Reset `DefinitionExpression`
layer.DefinitionExpression = "1=1";
var table = layer.FeatureTable as ArcGISFeatureTable;
// Change visibility of features that do not satisfy `DefinitionExpression`
var features = await table.QueryFeaturesAsync(new QueryParameters() { WhereClause = "type <> 2" });
layer.SetFeaturesVisible(features, false);
var result = await job.GetResultAsync();
// Set `DefinitionExpression` back
layer.DefinitionExpression = "type = 2";

Thanks again.

0 Kudos
JoeHershman
MVP Regular Contributor

I was able to just toggle the DefinitionExpression off/on and have it work to refresh the view.  If you are really paying attention you do see a bit of a flash, but so far the users have not complained.

I loop through all the layers in the Geodatabase at the end of a sync and reset the DefinitionExpression like below

string expression = layer.DefinitionExpression;
layer.DefinitionExpression = "";
layer.DefinitionExpression = expression;
0 Kudos
JenniferNery
Esri Regular Contributor

Cool thanks for sharing your workaround. That doesn't sound so bad then.

0 Kudos
JoeHershman
MVP Regular Contributor

I am seeing another issue I think related but not the same.  Although the workaround is the same.

We have a background sync service that runs outside the map application.  When a change comes to the client through the service the map does not refresh to show that change.  I found in this case also that toggling the DefinitionExpression will get the new feature to draw.

What would be really nice is if the API provided some method to force a full redraw of an area as must be getting done by the reset of the definition expression

Jennifer Nery

0 Kudos