What is the recommended best practice for adding PortalItem to MapView?

703
7
04-21-2022 09:25 AM
KevinCheriyan
Occasional Contributor

I am trying to add an item from Enterprise Portal to MapView. I'm trying to add the item, which is a FeatureLayer using its itemID. See code below.

        MapView {
            id:mapView
            anchors.fill: parent
            Map {
                    BasemapDarkGrayCanvasVector{}
                    initialViewpoint:
                        ViewpointCenter {
                        id:viewpoint
                        targetScale: 1.5e7
                            Point {
                                id: initPos
                                x: -11099972.04
                                y: 4014041.26
                                spatialReference: SpatialReference {
                                wkid: 102100
                            }
                        }
                    }

            }
            FeatureLayer {
                id: structuresInspectionStatusFS
                name:"Structures"
                visible: true
                Component.onCompleted: {
                    mapView.map.operationalLayers.append(structuresInspectionStatusFS)
                }

                ServiceFeatureTable {
                    initItem: inspectionsStatusPortalItem
                    initLayerId: inspectionsStatusPortalItem.itemId
                    onLoadStatusChanged: {
                    }
                    onLoadErrorChanged: {
                        console.log(layer.name)
                        console.log("Error changed:", loadError.message)
                    }
                    onErrorChanged: {
                        console.log(layer.name)
                        console.log("Error2 changed:", error.message)
                    }
                }
            }

            PortalItem {
                id: inspectionsStatusPortalItem
                itemId: //itemID
                portal: portalMain
                onLoadStatusChanged: {
                    if (loadStatus === Enums.LoadStatusLoaded){
                        structuresInspectionStatusFS.item = inspectionsStatusPortalItem
                    }
                }
            }

            Portal {
                id: portalMain
                credential: portalCredential
                url: "Portal URL"
                Component.onCompleted: {
                    portalMain.load();
                }
                onLoadStatusChanged: {
                    if (portalMain.loadStatus === Enums.LoadStatusLoaded) {
                        inspectionsStatusPortalItem.load()
                    } else {
                    }
                }
            }
            Credential {
                id:portalCredential
                username: "username"
                password: "password"
            }
            Connections {
                target: AuthenticationManager
                onAuthenticationChallenge: {
                    if (challenge.authenticationChallengeType === Enums.AuthenticationChallengeTypeUsernamePassword) {
                        challenge.continueWithCredential(portalCredential);
                    }
                }

            }
        }

This used to work in AppStudio 4 and its Runtime, but now that I've upgraded to AppStudio 5 and latest Runtime, it doesn't work anymore. I get an "Invalid Argument" Error from the error signals on ServiceFeatureTable. 

I know it's not an authentication issue, because I have other FeatureLayers that I'm adding to the map and they work fine. The difference is that those FeatureLayer items don't get added as PortalItem. 

Any help is appreciated!


--------------------------------------------------
Application Developer, GeoMarvel
0 Kudos
7 Replies
JamesBallard1
Esri Regular Contributor

Hi @KevinCheriyan. Thanks for reaching out to us.

Your code looks valid. Is it possible to provide a contrived, but working example that I can run to debug what's going on? You can use any public layers or services on ArcGIS online that don't need any credentials.

I was able to get this working, but it's not quite what you have.

Portal {
    id: portal
}

MapView {
    id:mapView
    anchors.fill: parent
    Map {
        id: map
        BasemapImagery{}
    }
}

FeatureLayer {
    id: featureLayer
    serviceLayerIdAsInt: 0
    PortalItem {
        id: portalItem
        portal: portal
        itemId: "b8f4033069f141729ffb298b7418b653"
    }
    Component.onCompleted: { map.operationalLayers.append(featureLayer); }
}

 

Also it's worth noting that you should be able to nest the FeatureLayer within the Map component, but that's not working. I've logged a bug for that internally.

KevinCheriyan
Occasional Contributor

Thanks for your response @JamesBallard1 

I actually used the itemID you provided in your example, and turns out it renders fine on my map. So do other Feature Layer items in my Enterprise Portal. So it's just the one Feature Layer I was using that doesn't render. 

The Feature Layer in question was created from a separate reference layer (probably published from Pro) that renders symbology based on values from a field. The reference layer exists separately in Enterprise. 

I'm trying to bring this original reference layer in and apply UniqueValueRenderer to it, hoping to replicate how the original FeatureLayer used to look. Again, no clue why this used to work in AppStudio 4 but not AppStudio 5.


--------------------------------------------------
Application Developer, GeoMarvel
0 Kudos
JamesBallard1
Esri Regular Contributor

@KevinCheriyan, ok sounds good. If you do get a working (or non-working) example you can share, let me know so I can see what's going on and reproduce it on our end. If it used to work it sounds like a regression so I'm keen to get to the bottom of it.

KevinCheriyan
Occasional Contributor

Thanks @JamesBallard1 , if I can figure out a way to create a Feature Layer from a reference MapServer layer (that's public) as is the case with the item in question, I will share that itemID in this thread. Can't seem to figure out how to do that yet. It really does seem like the issue is with FeatureLayer items created like this. 

Thank you for your help! Also, UniqueValueRenderer works great if I bring in the original service layer URL and change the symbology client-side. I could see it getting pretty annoying for more complicated symbologies that I can only create in Portal or ArcGIS Pro though.


--------------------------------------------------
Application Developer, GeoMarvel
0 Kudos
KevinCheriyan
Occasional Contributor

Hello @JamesBallard1 , I had to revisit this problem due to a situation in which my team could not use Renderer (see here for issue from colleague) and I have narrowed down when PortalItem does and doesn't work. Basically, if the item being used is a hosted feature layer, it works. If the feature layer is not hosted, then it doesn't. Again, this used to work in AppStudio 4 and earlier Runtime Qt versions. 

I do not have an example to share with you, but hopefully you can try this with 2 different feature layer items, one of them hosted?

Looking forward to hearing what you think


--------------------------------------------------
Application Developer, GeoMarvel
0 Kudos
JamesBallard1
Esri Regular Contributor

Hi @KevinCheriyan, thanks for the update. I'll check to see if we have a similar setup so I can try this locally.

0 Kudos
JamesBallard1
Esri Regular Contributor

@KevinCheriyan we've not been able to track down any similar scenarios on our end. Please consider logging an official support request so we can look into this one further.

0 Kudos