FeatureLayer Selection Mode in ArcGIS for Android 100.0.0

1278
2
04-20-2017 10:57 AM
LageplanGöttingen
New Contributor III

Hi,

prior to 100.0.0 I used to load my feature services as follows:

ArcGISFeatureLayer buildings = new ArcGISFeatureLayer(getResources().getString(
R.string.buildingsURL), ArcGISFeatureLayer.MODE.SELECTION);
map.addLayer(buildings);
map.addLayer(rooms);
...

I.e., my building and room features would not be displayed by default, 
but only when they were selected.
There also used to be the modes "ONDEMAND" and "SNAPSHOT",  
but the SELECTION mode is most important for my app.

For 100.0.0 I changed the code to this:
ServiceFeatureTable buildingsTable = 
new ServiceFeatureTable(getResources().getString(
        R.string.buildingsURL));
buildings = new FeatureLayer(buildingsTable);
map.getOperationalLayers().add(buildings);
map.getOperationalLayers().add(rooms);
...

I could not find a "SELECTION" mode and all buildings (or rooms) are displayed 
at the same time. 
Moreover, I realized that only the first layer is displayed (in this case, buildings; 
if I add rooms as the first layer, then all rooms are shown).
But this is a different problem...

So first of all, could someone please tell me how I can add feature layers 
so that features are loaded from the server only when they are selected?

Thank you!



0 Kudos
2 Replies
AlexanderNohe1
Occasional Contributor III

I don't see this mode currently available.  Someone from the Runtime team might be able to comment on this.

What  you could do though, is load the layer but set the visibility to none.  Then as the user queries for a feature or selects a feature, you can at that point change the visibility of the selected feature using this method. While this may not be ideal for your workflow, I believe that this may be a reasonable alternative.

Hopefully, we will be able to get some feedback from a member of the runtime team regarding that method / feature you are looking for.

LageplanGöttingen
New Contributor III

Thanks for your reply!

I tried your suggestion, but setting buildings.setFeatureVisible(feature, true); after initially setting visible to "none" didn't work. So in my buildings.selectFeatureAsync task, I added:

buildings.setVisible(true);
Map<String, Object> attr = feature.getAttributes();
Object value = (String) attr.get("piz");
buildings.setDefinitionExpression("piz LIKE '"+value+"'");

where "piz" is the name for the unique ID of the building. At first this did not work either, since my feature service contains many fields and only the first couple of fields were actually returned; I also couldn't specify outfields as I used to do in the old API. So I tried this:

ServiceFeatureTable table = (ServiceFeatureTable) buildings.getFeatureTable();
final ListenableFuture<FeatureQueryResult> future = 
table.queryFeaturesAsync(query, ServiceFeatureTable.QueryFeatureFields.LOAD_ALL);

and now the definition query works because the piz field value is returned.
However, I do hope that there is an easier way of doing this (or maybe will be added to the API in the future)