When the user logs in to the enterprise portal and selects the layer he wants to see, that layer is not displaying.
This is happening with all the layers that have an ID different from 0.
for example in this case the ID layer is 2:
With any layer with an ID equal to 0, it works very well.
The URL is https://server.xyzxyzxyzxyzxy/FeatureServer, but we could see in the logs this:
So, it is like the "/0" was added, that's why the layer is not displaying, because the URL should be: https://server.xyzxyzxyzxyzxy/FeatureServer/2
As it is a private layer, the app is using the portal item ID instead of the URL to get the layer: ServiceFeatureTable(item: portalItem), but the layer is not displaying in the map, and the app doesn't have any error from the library.
var featureLayer: (PortalProtocol, String) -> LayerProtocol? = { portal, portalItemID in
guard let itemID = ArcGIS.Item.ID(portalItemID), let portal = portal as? Portal else { return nil }
let portalItem = PortalItem(portal: portal, id: itemID)
return FeatureLayer(featureTable: ServiceFeatureTable(item: portalItem))
}
Solved! Go to Solution.
To add to the answer above, if you are trying to create a "layer browser" type of experience, another way is to create a Service
from the portal item, then uses its connected
property to access each table of a feature service. You can also use the service
property to get additional information about he layers and layerIDs in the feature service.
Hi Maria, thanks for asking. This behavior is expected.
When you create a feature layer like the code shown above
let featureLayer = FeatureLayer(featureTable: ServiceFeatureTable(item: portalItem))
It is using the initializer of ServiceFeatureTable, ServiceFeatureTable/init(item:) here. It is a "shorthand" initializer that would attempt creating the table from the first layer on the service, with has layerID = 0.
This initializer is there to meet a popular demand which a hosted feature service only has 1 feature layer (layerID = 0) that is being used in a map.
To create a feature layer other than layerID = 0, consider either of these 2 initializers
Both allow you to specify the layerID of a layer on the feature service.
p.s., there should be a load error if the try await featureLayer.load() is called.
Let me know if you have further questions. 🙂
To add to the answer above, if you are trying to create a "layer browser" type of experience, another way is to create a Service
from the portal item, then uses its connected
property to access each table of a feature service. You can also use the service
property to get additional information about he layers and layerIDs in the feature service.
Thanks @Ting, that helped me.