Select to view content in your preferred language

customize layer labels

2948
15
Jump to solution
01-16-2017 09:48 AM
EvonFranklin
Regular Contributor

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
Frequent Contributor

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
Regular Contributor

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
Regular Contributor

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
Frequent Contributor

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
Regular Contributor

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
Frequent Contributor

And it still doesn't work?

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

EvonFranklin
Regular Contributor

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

0 Kudos
thejuskambi
Frequent Contributor

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.