I need a convenient function within the SDK to enable an app to discover the type of layer dynamically

496
2
04-08-2019 10:47 AM
SimonCantrell
New Contributor

I am working on an app using the ArcGIS iOS SDK.

I am reading in Maps from the ArcGIS Online portal. These maps often contain a variety of layers, i.e. Image Layers, FeatureCollections layers, WMS layers, etc. I need a convenient function within the SDK to enable the app to discover the type of layer dynamically, and I then want to go on to operate in various functions on a selected layer, e.g. display its sublayers.

I have been scouring the SDK reference but I cannot determine how to do this yet. Has anyone else managed this?

I did locate the function to determine the portal type: ArcGIS Runtime SDK for iOS: AGSPortalItem Class Reference 

However, I want to go down to the next level and determine the type of layer contained within the operational layers after they have been loaded into a map when using an portal identifier to identify the particular map.

I'd like to be able to write the following Swift code:

            var layerType:String!

            ...

            //loop over the operational layers and save into an array

            ..

           //save the object present in the operational layers array

            let layer = self.layers?[index] as! AGSLayer!

            layerType = layer?.<what can be used to capture the layer type as a string here?>

            ...

            if (layerType == "AGSArcGISMapImageLayer") {

                self.mapImageLayer = self.layers?[index] as! AGSArcGISMapImageLayer!

            }

            if (layerType == "AGSFeatureCollectionLayer") {

                self.mapFeatureCollectionLayer = self.layers?[index] as! AGSFeatureCollectionLayer!

            }

            if (layerType == "AGSWMSLayer") {

                self.mapWMSLayer = self.layers?[index] as! AGSWMSLayer!

            }

            if (layerType == "AGSTiledMapServiceLayer") {

                     //Do something else

            }

            if (layerType == "AGSDynamicMapServiceLayer") {

                     //Do something else

            }

            if (layerType == "AGSImageServiceLayer") {

                     //Do something else

            }

etc.

However, unless I'm missing something, when I load all the operational layers in the map into an array of layers, the layer type is not offered in the AGSLayer class.

I can get the name, description, attribution, layerID, extent, etc. but no layer type.

Any help you guys can give will be appreciated.

Thanks!

Tags (1)
0 Kudos
2 Replies
RyanOlson1
Esri Contributor

you can check types of layers like so using swift's as operator, etc:

        let map = AGSMap()
        for case layer as AGSLayer in map.operationalLayers{
            switch layer{
            case let fl as AGSFeatureLayer:
                print("is feature layer")
            case let mil as AGSArcGISMapImageLayer:
                print("is AGSArcGISMapImageLayer")
            // etc...
            }
        }
0 Kudos
SimonCantrell
New Contributor

Perfect! That works just fine. Thank you so much.

0 Kudos