Select to view content in your preferred language

Online layer from enterprise is not working

264
3
Jump to solution
11-14-2024 01:53 PM
MariaPaulaGomezP
New Contributor

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:

Screenshot 2024-11-14 at 4.27.18 PM.png

With any layer with an ID equal to 0, it works very well.

Screenshot 2024-11-14 at 4.46.35 PM.png

The URL is https://server.xyzxyzxyzxyzxy/FeatureServer, but we could see in the logs this:

Screenshot 2024-11-14 at 9.42.13 AM.png

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))
    }

 

0 Kudos
1 Solution

Accepted Solutions
Ting
by Esri Contributor
Esri Contributor

To add to the answer above, if you are trying to create a "layer browser" type of experience, another way is to create a ServiceGeodatabase from the portal item, then uses its connectedTables property to access each table of a feature service. You can also use the serviceInfo property to get additional information about he layers and layerIDs in the feature service.

View solution in original post

3 Replies
Ting
by Esri Contributor
Esri Contributor

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 ServiceFeatureTableServiceFeatureTable/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. 🙂

Ting
by Esri Contributor
Esri Contributor

To add to the answer above, if you are trying to create a "layer browser" type of experience, another way is to create a ServiceGeodatabase from the portal item, then uses its connectedTables property to access each table of a feature service. You can also use the serviceInfo property to get additional information about he layers and layerIDs in the feature service.

MariaPaulaGomezP
New Contributor

Thanks @Ting, that helped me.