Feature layer labeling in v100.0

1336
2
01-04-2017 01:59 PM
olivierdev
New Contributor III

Is there any sample showing how to use new classes dedicated to labeling (for example AGSLabelingInfo or AGSViewLabelProperties)?

Or could someone please explain me how it's supposed to work? 

I have a hosted feature layer with labels. The rest API shows that the labelling info is well described (in the drawing info section of the layer). But no label is displayed on the map.

Also the labelingInfo property is null. Even if the feature layer has detailed labeling info on the rest service endpoint.

Did I miss something?

How does those labeling properties work? Are labels displayed the way they are defined in the feature service? Or can we edit the label properties on client side (label placement, label expression, etc..)?

Thanks in advance for any clarification.

olivier

0 Kudos
2 Replies
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi olivier,

After I did some tests with the new Class AGSViewLabelProperties 

Here I share with you a snippet of code that shows what I did:

//load a feature service URL into a featureTable
let featureTable = AGSServiceFeatureTable(URL: NSURL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0")!)
        
        //create a feature layer
        let featureLayer = AGSFeatureLayer(featureTable: featureTable)
        
        //You can using this line to control the label shows or not show on mapview
        //By default this labelsEnabled is false, and that's why if you not define
        //this property you will not able to see the labels
        //featureLayer.labelsEnabled = true
        
        //This is another way to control the label related to layers
        //when animationEnabled is true, the label will gradually disappear
        //when labelingEnabled is true, the label will shows 
        let viewLabel = AGSViewLabelProperties(animationEnabled: false, labelingEnabled: false)
        
        //Then you need to assign this AGSViewLabelProperties Object to mapView.labeling
        //based on this documentation: https://developers.arcgis.com/ios/latest/api-reference/interface_a_g_s_map_view_common.html#a41a20aa...
        self.mapView.labeling = viewLabel
        
        //add the feature layer to the operational layers
        map.operationalLayers.addObject(featureLayer)
    }
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Also, here is a video clip shows the steps: How to use AGSViewLabelProperties 

For the AGSLabelingInfo Class Reference, I found that this class is read only. Therefore, I am not sure this can be dynamically change rather than just read the existing layerinfo

Hope this can help.

0 Kudos
DiveshGoyal
Esri Regular Contributor

Currently, there is no way to set up your own labeling properties on the client, although we do plan on supporting that workflow in the future. At this time, the runtime only honors the labelling setting on the service or in a local package. I would expect the labellingInfo object to be populated accordingly. Can you point me to your service so that we can take a look at what might be going wrong?

Having said that, labels on feature layers aren't enabled by default, even if labels are defined on the service. You have to explicitly enable them on the client using the `AGSFeatureLayer#labelIsEnabled` property 

0 Kudos