Arcgis API 4.0 Unable to label feature layer with the labelClass

4882
7
05-27-2016 12:51 AM
Jean-MarcRoy
New Contributor II

Hi all,

I am trying to label a feature layer client side with the use of the labelClass, like it is show here : FeatureLayer | API Reference | ArcGIS API for JavaScript 4.0.

I use the same code in a scene view, but labels never showing up.

Can someone provide a short example that work with the JS API 4.0 ?

Thanks in advance for your help!

0 Kudos
7 Replies
KristianEkenes
Esri Regular Contributor

Here you go: https://jsbin.com/tesacarani/edit?html,output

I'm not sure what issue you were running into. Were you setting the labelsVisible property to true? Let me know so we can update the documentation accordingly if anything was unclear. We can also add a sample to clear this up.

Jean-MarcRoy
New Contributor II

Thank you very much!

My code was correct but I didn't set this properties on the feature layer construction, but with a function with a button. It is very weird, I can modify a lot of properties on my feature layer, that is immediately reflected in the view, however it doesn't work with the labelling info property. Only the labelsVisible property is reflected, when I change the value (true/false).

After few tests I figure out that, after the layer-view is created it is not possible to modify or set a labelingInfo property. Here is two demo that show this behavior :

- example with the labelingInfo and labelsVisible set on layerview-create event: "https://jsbin.com/qunewexuze/1/edit?html,output"

- example with the labelingInfo and labelsVisible set after a button is clicked : "https://jsbin.com/fuzuqilixe/1/edit?html,output"

I tried to remove the layer from the map, then set properties and then re-add the layer, it didn't work, I tried to first set the labelsVisible to true and the labelingInfo to a empty array on the feature layer construction, but have no effects too.

Any Ideas to achieve that?

Thanks!

0 Kudos
KristianEkenes
Esri Regular Contributor

Hmmmm...This behavior does look odd. Can you submit a bug report with these apps so we can get this in our system and fix it?

As you can probably tell, the labelling capabilities are not close to being finished. (We still need to support 2D labelling, for example). I imagine some of these issues will be ironed out once we start to finish up this part of the API. Having a record of this issue in the form of a bug report is helpful though so we can know to look out for this when testing.

Thanks for brining this up!

JadeFreeman
Occasional Contributor III

Is there a timeframe for when labels in 2D will be supported?  Is there an idea site where where this can be voted on??

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Jade,


  Why do you need to label on the client side so urgently? You do know you can use a MapImageLayer to have the server label a layer for you right?

0 Kudos
YueWu1
by
Regular Contributor

Hi Roy,

I did some extra test and found that the labelSymbol will renderer with view.on ("layerview-create") event. Here is a sample view to show the behavior: JS Bin - Collaborative JavaScript Debugging

In 3.x, labelSymbol can renderer with either featurelayer click, load or map click. This is sample in 3.x JS Bin - Collaborative JavaScript Debugging

We already logged a bug for this specific odd behavior:

[BUG-000096838 - LabelSymbol3D not work correctly with featureLayer event]

Jean-MarcRoy
New Contributor II

Hi,

Thanks to you both. I close this for the moment.

The only way I found to label my feature layer with a custom button is to reconstruct the layer when I change the labelingInfo property like that:

"function clickButton(map, featureLayer, myCustomLabelingInfo){

map.remove(featureLayer)

var featureLayer2 = new FeatureLayer ({url: featureLayer.url,

labelsVisible: true,

labelingInfo: [myCustomLabelingInfo]})

map.add(featureLayer2)

}".

Whith this trick I can label all my feature layers with a custom menu.

I will wait for the next release and hopefully the labeling capabilities will be finished.

Thanks again for your assistance.

0 Kudos