Select to view content in your preferred language

How to Turn On Labels and Enable Offline for a Web Map?

77
1
Friday
Labels (3)
SH_DH
by
Emerging Contributor

With the new Python API update I'm having trouble seeing how to turn on labels for a layer. I'm not seeing a parameter in layer properties. How can I turn these on?


Also, the recent update requires you to manually turn on Offline Enabled for a map. Is there a parameter for this?

0 Kudos
1 Reply
Clubdebambos
MVP Regular Contributor

Hi @SH_DH,

To turn on/off labels you can use the following...

from arcgis.gis import GIS
from arcgis.map import Map

## Access AGOL
agol = GIS("home")

## get the WebMap as an Item Object
wm_item = agol.content.get("WM_ITEM_ID")

## create the Map object from the Item Object
webmap = Map(wm_item)

## the dictionary for the options parameter in update_layer()
options_dict = {
    "showLabels" : True # or False
}

## Map object > MapContent > update_layer()
webmap.content.update_layer(
    index = 0, # index of the layer in the WebMap
    options = options_dict
)

## commit the change
webmap.update()

 

This assumes that you have label classes already set in the WebMap that will be used once the labels are turned on. 

All the best,

Glen

~ learn.finaldraftmapping.com
0 Kudos