<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Can not add labels to layer using new ArcGIS API for python 2.4.0 by wmap.content.update_layer in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-not-add-labels-to-layer-using-new-arcgis-api/m-p/1598697#M11251</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/698797"&gt;@ShiyuDing&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Yes, I haven't got a direct example for labels but it would be similar to updating the popup via the item object as per this &lt;A href="https://learn.finaldraftmapping.com/copy-an-arcgis-online-webmap-popup-and-apply-to-another-layer-with-the-arcgis-api-for-python/" target="_blank" rel="noopener"&gt;example&lt;/A&gt;, except you would target the specific layers&amp;nbsp;"labelingInfo" instead.&lt;/P&gt;</description>
    <pubDate>Mon, 24 Mar 2025 19:01:58 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2025-03-24T19:01:58Z</dc:date>
    <item>
      <title>Can not add labels to layer using new ArcGIS API for python 2.4.0 by wmap.content.update_layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-not-add-labels-to-layer-using-new-arcgis-api/m-p/1598151#M11241</link>
      <description>&lt;P&gt;I have recently upgraded ArcGIS API for python from 2.3.0 to 2.4.0 and found out that Map.content.update_layer() doesn't work with the old labeling_info json. There's no error while running the code, but it just doesn't do anything at all to web map.&amp;nbsp; Here is the code for 2.3.0:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;target_map_item = gis.content.get(target_map_id)
webmap = WebMap(target_map_item)
labeling_info = [
      {
        "labelExpression": "[owner]",
        "labelExpressionInfo": {
          "expression": "$feature[\"owner\"]"
        },
        "labelPlacement": "esriServerPolygonPlacementAlwaysHorizontal",
        "maxScale": 0,
        "minScale": 10000,
        "repeatLabel": true,
        "symbol": {
          "type": "esriTS",
          "color": [
            255,
            255,
            255,
            255
          ],
          "font": {
            "family": "Arial",
            "size": 11
          },
          "horizontalAlignment": "center",
          "kerning": true,
          "haloColor": [
            0,
            0,
            0,
            255
          ],
          "haloSize": 1,
          "rotated": false,
          "text": "",
          "verticalAlignment": "baseline",
          "xoffset": 0,
          "yoffset": 0,
          "angle": 0
        },
        "where": "area&amp;gt;= 10"
      }
]
lyr = webmap.layers[0]
lyr['layerDefinition']['drawingInfo']['labelingInfo'] = labeling_info 
webmap.update()&lt;/LI-CODE&gt;&lt;P&gt;And here is the new code for 2.4.0:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;wmap_item = gis.content.get(wmap_item_id)
wmap = Map(wmap_item)
wmap.content.update_layer(index = 0,labeling_info=labeling_info)
wmap.update()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Does anyone have the same problem? Can anyone help me with this?&lt;/P&gt;&lt;P&gt;Very appreciate!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Mar 2025 18:29:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/can-not-add-labels-to-layer-using-new-arcgis-api/m-p/1598151#M11241</guid>
      <dc:creator>ShiyuDing</dc:creator>
      <dc:date>2025-03-21T18:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can not add labels to layer using new ArcGIS API for python 2.4.0 by wmap.content.update_layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-not-add-labels-to-layer-using-new-arcgis-api/m-p/1598327#M11243</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/698797"&gt;@ShiyuDing&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Try this...&lt;/P&gt;&lt;LI-CODE lang="python"&gt;labeling_info = [
      {
        "labelExpression": "[owner]",
        "labelExpressionInfo": {
          "expression": "$feature[\"owner\"]"
        },
        "labelPlacement": "esriServerPolygonPlacementAlwaysHorizontal",
        "maxScale": 0,
        "minScale": 10000,
        "repeatLabel": True,
        "symbol": {
          "type": "esriTS",
          "color": [
            255,
            255,
            255,
            255
          ],
          "font": {
            "family": "Arial",
            "size": 11
          },
          "horizontalAlignment": "center",
          "kerning": True,
          "haloColor": [
            0,
            0,
            0,
            255
          ],
          "haloSize": 1,
          "rotated": False,
          "text": "",
          "verticalAlignment": "baseline",
          "xoffset": 0,
          "yoffset": 0,
          "angle": 0
        },
        "where": "area&amp;gt;= 10"
      }
]

options_dict = {
    "showLabels" : True,
    "layerDefinition" : {
        "drawingInfo" : {
            "labelingInfo" : labeling_info
        }
    }
}

wmap.content.update_layer(
    index=lyr_index,
    options=options_dict
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just a heads up, using the Map update() method is prone to cause issues in version 2.4.0 (Esri have stated this is already fixed in the next version). You will get weird things happen, contained to the WebMap, like Table corruption or WebMap corruption.&amp;nbsp;&lt;/P&gt;&lt;P&gt;An option to overcome this is to access and update the JSON definition directly via the WebMap Item object item.get_data().&lt;/P&gt;&lt;P&gt;I hope that helps. Let us know if this worked with your labels.&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;</description>
      <pubDate>Sun, 23 Mar 2025 09:44:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/can-not-add-labels-to-layer-using-new-arcgis-api/m-p/1598327#M11243</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-03-23T09:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can not add labels to layer using new ArcGIS API for python 2.4.0 by wmap.content.update_layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-not-add-labels-to-layer-using-new-arcgis-api/m-p/1598595#M11249</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;&amp;nbsp;, thank you so much for the solution and that works! It also gave me a lot of insight about migrating the renderer from 2.3.0 to 2.4.0. About updating with JSON definition, do you mean using item.update() by specifying data parameters? Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 16:53:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/can-not-add-labels-to-layer-using-new-arcgis-api/m-p/1598595#M11249</guid>
      <dc:creator>ShiyuDing</dc:creator>
      <dc:date>2025-03-24T16:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Can not add labels to layer using new ArcGIS API for python 2.4.0 by wmap.content.update_layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-not-add-labels-to-layer-using-new-arcgis-api/m-p/1598697#M11251</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/698797"&gt;@ShiyuDing&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Yes, I haven't got a direct example for labels but it would be similar to updating the popup via the item object as per this &lt;A href="https://learn.finaldraftmapping.com/copy-an-arcgis-online-webmap-popup-and-apply-to-another-layer-with-the-arcgis-api-for-python/" target="_blank" rel="noopener"&gt;example&lt;/A&gt;, except you would target the specific layers&amp;nbsp;"labelingInfo" instead.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 19:01:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/can-not-add-labels-to-layer-using-new-arcgis-api/m-p/1598697#M11251</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-03-24T19:01:58Z</dc:date>
    </item>
  </channel>
</rss>

