Adding runtime content to map

381
2
Jump to solution
04-13-2018 12:38 AM
ShiminCai
Occasional Contributor III

Hi all,

I'm using SDK100.2.1 and adding runtime content layers (*.geodatabase file created in ArcMap and stored locally on device) to the map as shown in the code below. I found that the geodatabaseFeatureTables.count is always zero and as a result no layers are added to the map. Is this the correct way adding the runtime content layers to the map in 100.2.1? I'm able to do this in SDK 10.2.5.

I'm using the free license level Lite.

Thanks in advance.

Shimin

let baseMap = AGSBasemap(baseLayer: self.baseLayer) 

let map = AGSMap(basemap: baseMap)

let gdb = AGSGeodatabase(fileURL: URL(fileURLWithPath: gdbFilePath)

                print(gdb.geodatabaseFeatureTables.count)

                

                for gdbFeatureTable: AGSGeodatabaseFeatureTable in gdb.geodatabaseFeatureTables

                {

                    if gdbFeatureTable.hasGeometry

                    {

                        let gdbFeatureLayer = AGSFeatureLayer(featureTable: gdbFeatureTable)

                        map.operationalLayers.add(gdbFeatureLayer)

                    }

                }

self.mapView.map = map

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

Hey Shimin,

You're nearly there. You just need to make sure the gdb is loaded.

gdb.load(completion: { (error) in
    guard error == nil else {
        print("Error loading the geodatabase! \(error!.localizedDescription)")
        return
    }

    for table in gdb.geodatabaseFeatureTables {
        let layer = AGSFeatureLayer(featureTable: table)
        map.operationalLayers.add(layer)
    }
})‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

But note that the tables won't have loaded either at this point, so to read hasGeometry, you might want to do this:

gdb.load(completion: { (error) in
    guard error == nil else {
        print("Error loading the geodatabase! \(error!.localizedDescription)")
        return
    }

    AGSLoadObjects(gdb.geodatabaseFeatureTables, { (allLoaded) in
        if !allLoaded {
            for table in gdb.geodatabaseFeatureTables where table.loadError != nil {
                print("Error loading \(table.tableName): \(table.loadError!.localizedDescription)")
            }
        }

        for table in gdb.geodatabaseFeatureTables where table.hasGeometry {
            let layer = AGSFeatureLayer(featureTable: table)
            map.operationalLayers.add(layer)
        }
    })
})‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

If you know your geodatabase only has featuretables with geometry, you can just add them to the operational layers without first loading them.

View solution in original post

2 Replies
Nicholas-Furness
Esri Regular Contributor

Hey Shimin,

You're nearly there. You just need to make sure the gdb is loaded.

gdb.load(completion: { (error) in
    guard error == nil else {
        print("Error loading the geodatabase! \(error!.localizedDescription)")
        return
    }

    for table in gdb.geodatabaseFeatureTables {
        let layer = AGSFeatureLayer(featureTable: table)
        map.operationalLayers.add(layer)
    }
})‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

But note that the tables won't have loaded either at this point, so to read hasGeometry, you might want to do this:

gdb.load(completion: { (error) in
    guard error == nil else {
        print("Error loading the geodatabase! \(error!.localizedDescription)")
        return
    }

    AGSLoadObjects(gdb.geodatabaseFeatureTables, { (allLoaded) in
        if !allLoaded {
            for table in gdb.geodatabaseFeatureTables where table.loadError != nil {
                print("Error loading \(table.tableName): \(table.loadError!.localizedDescription)")
            }
        }

        for table in gdb.geodatabaseFeatureTables where table.hasGeometry {
            let layer = AGSFeatureLayer(featureTable: table)
            map.operationalLayers.add(layer)
        }
    })
})‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

If you know your geodatabase only has featuretables with geometry, you can just add them to the operational layers without first loading them.

ShiminCai
Occasional Contributor III

Hi Nicholas,

It worked !!! Thank you very much.

Cheers,

Shimin

0 Kudos