Select to view content in your preferred language

Retrieve Legend Info from TPK File

669
3
02-23-2018 12:51 PM
ArthurWu
New Contributor

I was trying to load the data back from the tpk file.

This is what I what I wrote

let layer = AGSArcGISTiledLayer.init(tileCache: AGSTileCache(fileURL: URL(fileURLWithPath: Globals.documentsDirectory.path + "/" + file)))

It can render the map perfectly

However, when I try to load the legend info with the function fetchLegendInfo, the result is empty.

here's my code:

 layer.fetchLegendInfos(completion: { (legends:[AGSLegendInfo]?, error:Error?)->Void in

                    

                    print(legends)

                    

                })

the variable legends will always be "Optional([])"

Am I doing it correctly?

Also to make sure there's actually data in the tpk file, i open it up with hex editor, which gives me this

Which shows there's data in it, but somehow it's not getting it back correctly.

0 Kudos
3 Replies
MarkDostal
Esri Contributor

Thank you for your question!  My guess is that all of the legend information is in the tiledSublayers

 property of layer.

        layer.tiledSublayers.forEach { (sublayer) in

            sublayer.fetchLegendInfos(completion: { (legendInfos, error) in

                if let error = error { print("*** Error in fetchLegendInfos for \(sublayer.name😞 \(error)"); return }

                //do something with the legendInfos array...

            })

        }

Note that each of the sublayers, which are AGSArcGISTiledSublayer objects, might also have a non-empty sublayers property, so you may want to check those as well if you're still not getting the information you expect.

To make things easier, we do provide a Legend component and example code in our ArcGIS Runtime Toolkit for iOS here:  GitHub - Esri/arcgis-runtime-toolkit-ios: Toolkit components that will simplify your iOS app develop... 

Let me know if you need further help!

Mark

0 Kudos
ArthurWu
New Contributor

Thanks for replying, however, I checked the sublayer.count, it is 0. I have also checked the toolkit, but the only thing it's showing is the layer title. Did I initialize the tiled layer from tpk file wrong?

0 Kudos
MarkDostal
Esri Contributor

I did some more digging on my end and found out that the sublayer content and legendInfo are not populated for layers created from a tile cache.  This is something that is under consideration for the next release.  So you are initializing the tiled layer correctly, especially since it is drawing successfully, it's just that the legend info functionality is not yet implemented.

Please let us know if you have more questions,

Mark

0 Kudos