Feature service layer default visibility not transferred to the layers on Map

507
6
Jump to solution
07-13-2021 03:53 PM
ShiminCai
Occasional Contributor II

Hi there,

We are on ArcGIS Runtime SDK for iOS 100.10. We set the default layer visibility to false for some of the layers in our feature services by unticking the layers in the TOC of publishing map documents. We can confirm that the default layer visibilities of those layers are false in service directory. But when we add the service layers or downloaded offline database layers to map those layer's isVisibles have become true and the layers are drawn on the map. Basically we don't want the map to draw those layers we untick in the publishing document. However, it works fine with SDK 10.2.5 for the same feature service.

Does anybody have any idea please?

Thanks,

Shimin

 

0 Kudos
1 Solution

Accepted Solutions
MarkDostal
Esri Contributor

@ShiminCai It turns out that the defaultVisibility of the service is ignored when creating the layer from a service URL or AGSServiceFeatureTable. This is by design and behaves the same way the AGOL MapViewer does.  The reasoning behind the design is that it would be odd and potentially confusing if you added a map layer and it didn't immediately draw.  However, I understand that your use case is different.

The SDK does capture the service info correctly in the AGSServiceFeatureTable.layerInfo.isVisibleByDefault property, so a solution would be to set the initial visibility of the freshly created layer to that value.  Note that the AGSServiceFeatureTable needs to be loaded before accessing the layerInfo property.

Hope that helps.  If you have more questions, please let me know.

Mark

View solution in original post

0 Kudos
6 Replies
MarkDostal
Esri Contributor

I have a couple of questions about your workflow.  How are you consuming the layers in the Runtime?  Are they part of a web map loaded from ArcGIS Online (AGOL), are you creating the map and adding the layers programmatically or some other way?

How are you setting the default layer visibility in the Feature Service?  Is it through AGOL?

Thank you,

Mark

0 Kudos
ShiminCai
Occasional Contributor II

Hi Mark,

Thanks a lot for your reply.

We are creating the map and adding the layers programmatically. Here is the func adding the feature service layers:

func loadOnlineModuleLayers() {

        mapView.map?.operationalLayers.removeAllObjects()

        if let url = URL(string: AppState.shared.currentModule!.featureServiceURL!) {

            let gdbSyncTask = AGSGeodatabaseSyncTask(url: url)

            gdbSyncTask.load { (error) -> Void in

                guard error == nil else {

                    print("Failed loading GDB task with error: \(error!.localizedDescription)")

                    return

                }

 

                let featureServiceInfo = gdbSyncTask.featureServiceInfo

                let layerInfos = featureServiceInfo?.layerInfos

 

                let groupLayer = AGSGroupLayer()

                groupLayer.name = AppState.shared.currentModule!.moduleName

                

                for layerInfo in layerInfos! {

                    let url = gdbSyncTask.url!.appendingPathComponent("\(layerInfo.id)")

                    let featureTable = AGSServiceFeatureTable(url: url)

                    let featureLayer = AGSFeatureLayer(featureTable: featureTable)

                    print("\(layerInfo.name) isVisible = \(featureLayer.isVisible)")

                    groupLayer.layers.addObjects(from: [featureLayer])

                }

                self.mapView.map!.operationalLayers.add(groupLayer)

            }

        } else {

            Alert.showAlert("Feature Service URL", message: "Module feature service URL is not accessible.")

        }

    }

We did not manipulate the layer visibility while adding the layers to the map. Here is the printout of layer visibilities:

Screen Shot 2021-07-28 at 8.43.10 am.png

As you can see the BAHS Traverse layer's isVisible = true, but in the service directory the default visibility for the layer is false:

Screen Shot 2021-07-28 at 8.50.06 am.png

We are expecting this layer on map has a false isVisible but it is true. As mentioned before, this works as expected with SDK 10.2.5  for the same feature service.

Many thanks for your help.

 

Cheers,

Shimin 

 

 

 

0 Kudos
ShiminCai
Occasional Contributor II

Sorry did not answer your last question. I did not publish the feature service but I think the layer default visibility is set by unticking the layer in the TOC of publishing mxd or ArcGIS Pro document.

0 Kudos
MarkDostal
Esri Contributor

@ShiminCai - Thank you for the additional information.  I'm going to reach out to some of my colleagues and get back to you.

0 Kudos
MarkDostal
Esri Contributor

@ShiminCai It turns out that the defaultVisibility of the service is ignored when creating the layer from a service URL or AGSServiceFeatureTable. This is by design and behaves the same way the AGOL MapViewer does.  The reasoning behind the design is that it would be odd and potentially confusing if you added a map layer and it didn't immediately draw.  However, I understand that your use case is different.

The SDK does capture the service info correctly in the AGSServiceFeatureTable.layerInfo.isVisibleByDefault property, so a solution would be to set the initial visibility of the freshly created layer to that value.  Note that the AGSServiceFeatureTable needs to be loaded before accessing the layerInfo property.

Hope that helps.  If you have more questions, please let me know.

Mark

View solution in original post

0 Kudos
ShiminCai
Occasional Contributor II

Hi Mark,

It worked. Thank you so much for your help.

Cheers,

Shimin

0 Kudos