Loading Feature Layer in a map

889
5
Jump to solution
08-26-2022 02:52 AM
VineetMenon
New Contributor II

I have two feature layers, one which I got from an authorized publisher (in the form of a shapefile), and the other which I created from scratch (using ArcMap).

I'm able to load the former using the following snippet,

ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(<service_url>);

serviceFeatureTable.addDoneLoadingListener(() -> {
    if (serviceFeatureTable.getLoadStatus() == LoadStatus.LOADED) {
        System.err.println("loaded layer");
        featureLayer = new FeatureLayer(serviceFeatureTable);
        map.getOperationalLayers().add(featureLayer);
    } else {
        System.err.println("cannot load");
        throw serviceFeatureTable.getLoadError();
    }

});

while, in the second one, addDoneLoadingListener isn't being called at all.

In the second feature layer, I'm using REST addFeatures to populate/update entries.

What could cause the second layer to not load? What all things should I check for in the portal/server?

0 Kudos
2 Solutions

Accepted Solutions
MarkBaird
Esri Regular Contributor

For the serviceFeatureTable to load something needs to trigger it.  If you are using it to create a FeatureLayer and then add it to the operational layers list of your map this will happen automatically.

However if you are not adding it to an ArcGISMap instance then you will need to trigger the load event yourself using this line of code:

serviceFeatureTable.loadAsync();

Does this make the event fire?

View solution in original post

0 Kudos
MarkBaird
Esri Regular Contributor

If that doesn't work then take a look at your service endpoint in a browser.  It should look something like this one which I know works fine:

https://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/9

 

View solution in original post

0 Kudos
5 Replies
MarkBaird
Esri Regular Contributor

Whenever I see a DoneLoadingListener not firing, I would confirm that you are not being hit by the JVM garbage collection cleaning up your service feature table class before you had chance to use it.

In the code snippet above your ServiceFeatureTable class instance is a local variable, but the event fires on a separate thread when possibly the variable has gone out of scope and is vulnerable to garbage collection.

Can you try making the variable for the ServiceFeatureTable a class member and see if it improves things?

If this fixes the issue, there is a blog post I wrote which explain this in more detail here.  

Let me know if that helps - can look at other things if this isn't the problem.

0 Kudos
VineetMenon
New Contributor II

Hi Mark,

Thanks for the quick reply.

Unfortunately, making the serviceFeatureTable a member variable doesn't help.

I'm thinking the issue is related to my layer, because as I said, another feature layer published from a shapefile can be loaded onto the map.

0 Kudos
MarkBaird
Esri Regular Contributor

For the serviceFeatureTable to load something needs to trigger it.  If you are using it to create a FeatureLayer and then add it to the operational layers list of your map this will happen automatically.

However if you are not adding it to an ArcGISMap instance then you will need to trigger the load event yourself using this line of code:

serviceFeatureTable.loadAsync();

Does this make the event fire?

0 Kudos
MarkBaird
Esri Regular Contributor

If that doesn't work then take a look at your service endpoint in a browser.  It should look something like this one which I know works fine:

https://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/9

 

0 Kudos
VineetMenon
New Contributor II

Hi Mark,

 

Yes. The layer loading wasn't getting triggered.

Thanks a lot for your help.

0 Kudos