customize layer labels

2471
15
Jump to solution
01-16-2017 09:48 AM
EvonFranklin
New Contributor III

How do i customize layer labels from a MapImageLayer? current layer code below

 var resultsLabelLayer = new MapImageLayer({
                  url: url,
                   sublayers: [{
                                id: 1,
                                labelsVisible: true,
                                visible: true,
                                labelingInfo: [{
                                              labelExpression: "[CONST]",
                                              labelPlacement: "always-horizontal",
                                              symbol: new TextSymbol({
                                                color: [ 255,255,255,1 ],
                                                font: {
                                                  size: 16,
                                                  weight: "bolder"
                                                }
                                              })
                                            }]
                              }]
           });  ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
map.add(resultsLabelLayer);

Using this and adding the layer to the map yields no labels or the layer being drawn

0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Occasional Contributor III

And it still doesn't work?

Have you enabled the Supports Dynamic Layers for the map service?

View solution in original post

15 Replies
RobertScheitlin__GISP
MVP Emeritus

Evon,

  This sample shows some of the parameters that can be customized:

MapImageLayer - label sublayer features | ArcGIS API for JavaScript 4.2 

0 Kudos
EvonFranklin
New Contributor III

That is exactly the document I was following, still to no success to display any labels. There may be more to this but I get no error in console.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Evon,

   Strange it works fine for me.

0 Kudos
EvonFranklin
New Contributor III

I updated my question with the code I am using, I tried a hard refresh on the browser still no use. I do have a layer on my service that is not enabled however I am not sure if that is causing an issue. i disabled the other layers and only have visible set to the layer i want to label.

0 Kudos
thejuskambi
Occasional Contributor III

Hello Evon,

You snippet does not have the id property in it. All the sample snippet has the id value, which will provide the information on which sublayer, the changes needs to be applied to.

Have you tried adding the "id" property?

Warm Regards

0 Kudos
EvonFranklin
New Contributor III

thanks for your observation, I have left it out while testing something but I have added it in my code snippet above.

0 Kudos
thejuskambi
Occasional Contributor III

And it still doesn't work?

Have you enabled the Supports Dynamic Layers for the map service?

EvonFranklin
New Contributor III

Is this mandatory in order to change the labels client side?

0 Kudos
thejuskambi
Occasional Contributor III

I think that MapImageLayer is using the functionality provided by Dynamic Layer of the Map Service. Because of which you are able to change the symbology, label and other details of a MapService. It is similar to LayerDrawingOptions in 3.x version. I couldn't find any documentation though. I checked the service used in the sample and they have the Dynamic Layer support enabled.

Its worth a try.