Select to view content in your preferred language

dynamically enable showLabels

1902
9
03-07-2017 01:47 PM
sapnas
by
Frequent Contributor

I want to dynamically set showLabels to display featurelayer labels. using

FeatureLayer.setShowLabels(true); logic is not working. Is there a sample code to dynamically enable showLabels? Any help is greatly appreciated.

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus

Sapna,

   Did you set your map object constructor to enable showing labels?

https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#map1 

showLabel = true

0 Kudos
sapnas
by
Frequent Contributor

I want to enable it in custom webapp builder widget . I'm not sure if I can reinstantiate the map object in the widget.

0 Kudos
sapnas
by
Frequent Contributor

Unfortunately I cannot make changes to MapManager as I have to deploy  the widget only and not the web application

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Sapna,

  No you can not from inside a widget as it needs to be in the map constructor.

You would have to change the apps main config.json:

"map": {
        ...
        "mapOptions": {
            "showLabels":true,
            "extent": {
              ...
            }
        }
    }
sapnas
by
Frequent Contributor

Robert,

Is there an option to enable this from web app builder when user creates the web app? I want to refrain from editing config.json file of webappbuilder client as far as possible.

Thanks,

Sapna

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Sapna,


  There is not. The JS API does not have an option to change this at runtime (you only have the option to set that in the map constructor), so that is the main issue. The WAB does not have an option beside the main config.json for setting this or editing the MapManager.js which you are not wanting to do either.

sapnas
by
Frequent Contributor

Thanks for your help Robert. I will just use some workaround

Thanks,

Sapna

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

It looks like in version 2.4 of WAB you will be able to do this. So just wait a couple of weeks when 2.4 Dev edition comes out.

0 Kudos
sapnas
by
Frequent Contributor

I'm not sure if we are ready for 2.4 yet but that gives us an excuse to upgrade it . Thanks for the information.  I agree that JS API does not have an option to change this so as a work around I may have to create http handler and invoke it from JS API . 

0 Kudos