I am attempting to replicate this sample code (showing the attributes upon clicking within a feature layer) with this database I created and hosted as a feature service however I noticed that while the sample code is referencing a single layer in the feature service, my feature service is referencing a database with two layers. How can I be sure to populate a feature layer with all of my features in each layer using this method? Should I create a feature layer for each layer in my feature service instead of for the database itself? Right now I am implementing this and my map is not even displaying.
Solved! Go to Solution.
Hey Cora Coleman,
I believe that when you use the ServiceFeatureTable class, you want to only reference one of the sublayers whereas if you used the root service, it wouldn't know which to turn into a feature table. Here is the code that I used:
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setMap(new ArcGISMap(Basemap.Type.DARK_GRAY_CANVAS_VECTOR, 48.7596, -113.7870, 4));
ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable("https://services8.arcgis.com/UT5WPtsyyxzDrV2P/ArcGIS/rest/services/GNP_gdb/FeatureServer/1");
FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
mMapView.getMap().getOperationalLayers().add(featureLayer);
serviceFeatureTable = new ServiceFeatureTable("https://services8.arcgis.com/UT5WPtsyyxzDrV2P/ArcGIS/rest/services/GNP_gdb/FeatureServer/0");
featureLayer = new FeatureLayer(serviceFeatureTable);
mMapView.getMap().getOperationalLayers().add(featureLayer);
Additionally, since you it looks like you are storing this data on ArcGIS Online, it might be easier to create a webmap that stores this service within it and then load that webmap into the MapView rather than load the individual layers into the MapView itself.
Is the feature service not displaying at all? Is it a secured service? Are you providing authentication to that service?
What happens if you do something like this before you call any other ArcGIS Runtime code in your app:
new AuthenticationManager.setAuthenticationChallengeHandler(new DefaultAuthenticationChallengeHandler(context));
Do you have the internet permission enabled in your Manifest file?
Do you see any prompts to log in?
Thanks,
Alexander
Thank you for your response! My feature service will not display whatsoever. What do you mean by secured (it is only public and hosted currently)? I haven't tested the API calls to the service. I do have internet permissions and do not see any prompts to log in. Also, I'm trying to add that bit of code in my app but what would I pass as my context? Just the service?
Hi Cora Coleman,
Context in this sense refers to your application context. Do you have a link to the service so I can test on my end?
Thanks,
Alexander
Hello, okay thank you for explaining this, I will try and return the context I am setting to understand this more. Here is the link to the feature service I created. It is a geodatabase composed of two layers. I'm thinking I would have to host the individual layers themselves as when I do this, line 12 will result in only my basemap displaying and not the feature service I reference in my strings.xml file (the link I included above to my feature service):
0 // create an ArcGISMap with BasemapType topo 1 aMap = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 48.7596, 113.7870, 4); 2 // set the ArcGISMap to the MapView 3 aMapView.setMap(aMap); 5 // get the callout that shows attributes 6 aCallout = aMapView.getCallout(); 7 // create the service feature table 8 aServiceFeatureTable = new ServiceFeatureTable(getResources().getString(R.string.sample_service_url)); 9 // create the feature layer using the service feature table 10 final FeatureLayer featureLayer = new FeatureLayer(aServiceFeatureTable); 11 // add the layer to the map 12 aMap.getOperationalLayers().add(featureLayer);
Hey Cora Coleman,
I believe that when you use the ServiceFeatureTable class, you want to only reference one of the sublayers whereas if you used the root service, it wouldn't know which to turn into a feature table. Here is the code that I used:
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setMap(new ArcGISMap(Basemap.Type.DARK_GRAY_CANVAS_VECTOR, 48.7596, -113.7870, 4));
ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable("https://services8.arcgis.com/UT5WPtsyyxzDrV2P/ArcGIS/rest/services/GNP_gdb/FeatureServer/1");
FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
mMapView.getMap().getOperationalLayers().add(featureLayer);
serviceFeatureTable = new ServiceFeatureTable("https://services8.arcgis.com/UT5WPtsyyxzDrV2P/ArcGIS/rest/services/GNP_gdb/FeatureServer/0");
featureLayer = new FeatureLayer(serviceFeatureTable);
mMapView.getMap().getOperationalLayers().add(featureLayer);
Additionally, since you it looks like you are storing this data on ArcGIS Online, it might be easier to create a webmap that stores this service within it and then load that webmap into the MapView rather than load the individual layers into the MapView itself.
Hi, thank you so much for this response. I was able to finally view these feature service layers in my app! The reason I am doing it like this is in order to be able to tap on the points of the map and view the attributes associated with them. I am following some sample code where this is done with a feature service however I agree about importing my map from ArcGIS Online. This is what I was initially doing, but I also want to be able to query/show the attributes associated with each feature and so now I am trying this. Thank you so much for your help!
Hi coracoleman14,
What sample are you using? Maybe we can work on modifying it to work with webmaps rather than making you change your data to work with it?
Thanks,
Alexander
Hi, thanks for this suggestion. Here is the sample code I am currently using (feature-layer-show-attributes). I have been trying to do this myself through creating a webmap and making sure to enable popups within the map on ArcGIS Online but realize I also need to define how to view popups/callouts within some on-tap listener in my code. This sample code imports a feature service and uses the table created from the layers there to return query results. Is there a way to simply grab the attribute table to be displayed in a popup for the corresponding feature you tap on without using a feature service?
Ahh.. Yes. There is quite a bit that goes into showing popups in a android application. It might be best to stick with this sample for the time being.
I did work on this sample which shows popups in a webmap but it again, takes a lot of work on the implementers part to get it working correctly:
GitHub - nohe427/KtPopup: Kotlin Popups
Recently, the SDK documentation team has asked for feedback regarding the SDK documentation.
Would you be interested in emailing me some feedback about the Android SDK documentation and using it to accomplish your goals? (include level of development experience, how easy or difficult was it to find what you were looking for, etc...)