How to show each points name as a label in the offline map?

11-21-2018 11:10 PM
New Contributor

Hello, I'm developing offline map for iOS using TPK package as a basemap and some local shape files for feature layers. Everything is working fine except labeling. I have a huge data more than thousand points in the map which is loading from table in shape file, I want to show each POI name as a text/label instead of dot or it could be placed next to dot in the map. I've tried to see documentation and I found only Label expression which is for online use only, but no luck for my case. Is there any other solution? I also tried clusters but it seems for symbols and online data only. May be I cannot getting there how to implement it in offline environment ? Thanks in advance.

0 Kudos
2 Replies
Esri Contributor

You can add labels to shapefile data. We do not have a comprehensive api for creating the label definition through properties, however one can be created with json like so:

            let map = AGSMap(basemapType: .lightGrayCanvas, latitude: 0, longitude: 0, levelOfDetail: 0)
            let shp1 = AGSShapefileFeatureTable(fileURL: URL.TestDataURL("Shapefile/FromArcMap/CapitalsFromAM.shp"))
            let fl1 = AGSFeatureLayer(featureTable: shp1)
            let jsonStr = """
            guard let jsonData = .utf8) else{
            let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: [])
            let labelDefinition = try AGSLabelDefinition.fromJSON(jsonObject)
            fl1.labelsEnabled = true
   = map‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

That code will give label the `CITY_NAME` field for each point in the shapefile. It will be a red (255,0,0,255) text symbol with a white halo.

0 Kudos
New Contributor

Thank you very much, it's a great approach!

But I see Arabic fonts doesn't support at all, only English for now and I got error "Errors thrown from here are not handled" for "try". Then it worked fine when I put it inside do { } catch handler. 

0 Kudos