<?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: How do you use ArcGIS API for python to specify a layer based on title in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1038564#M39029</link>
    <description>&lt;P&gt;There is a method &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.mapping.toc.html#arcgis.mapping.WebMap.get_layer" target="_self"&gt;&lt;STRONG&gt;get_layer()&lt;/STRONG&gt;&lt;/A&gt; on the WebMap class, according to the API docs. Testing it, however, I can't get it to return anything.&lt;/P&gt;&lt;P&gt;There is also the &lt;STRONG&gt;layers&lt;/STRONG&gt; property, which returns all the layers in a map as a dict. Iterating over that isn't too hard.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;web_map = arcgis.mapping.WebMap(gis.content.get('webmap-itemID'))

for l in web_map.layers:
    if l.title == 'Layer title you want':
        # do your layer edits here&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Mar 2021 12:17:50 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2021-03-19T12:17:50Z</dc:date>
    <item>
      <title>How do you use ArcGIS API for python to specify a layer based on title</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1038536#M39027</link>
      <description>&lt;P&gt;Dear ESRI community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do you use ArcGIS API for python to specify a layer in a web map based on the layers title? All of the samples I've seen just use the layer at index 0. I can't find any samples that search for a particular layer.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;my_webmap = gis.content.search(query="title:Trees",item_type="Web Map")
my_item = my_content[0]
wm = WebMap(my_item)
Taxon_layer = wm.layers[0] #I want to select the layer where "Title" = "Taxon"
Taxon_layer
===============================================
Out:
{
  "id": "Markup_X_3074",
  "layerType": "ArcGISFeatureLayer",
  "url": "https://services5.arcgis.com/wkEdAXzuNvKdAtLV/arcgis/rest/services/Markup_X/FeatureServer/0",
  "visibility": true,
  "opacity": 1,
  "title": "Taxon",
  "itemId": "b022f56ae0c347019ca2c9aae60c450c"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ultimately, I want to iterate through several web maps and modify a particular layer in each web map . The title is always the same but the index number will change each time. I know how to iterate, but I don't know how to select a layer based on title.&lt;/P&gt;&lt;P&gt;Any assistance greatly appreciated&lt;/P&gt;&lt;P&gt;Regards, Damian&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 11:14:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1038536#M39027</guid>
      <dc:creator>Damian</dc:creator>
      <dc:date>2021-03-19T11:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use ArcGIS API for python to specify a layer based on title</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1038564#M39029</link>
      <description>&lt;P&gt;There is a method &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.mapping.toc.html#arcgis.mapping.WebMap.get_layer" target="_self"&gt;&lt;STRONG&gt;get_layer()&lt;/STRONG&gt;&lt;/A&gt; on the WebMap class, according to the API docs. Testing it, however, I can't get it to return anything.&lt;/P&gt;&lt;P&gt;There is also the &lt;STRONG&gt;layers&lt;/STRONG&gt; property, which returns all the layers in a map as a dict. Iterating over that isn't too hard.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;web_map = arcgis.mapping.WebMap(gis.content.get('webmap-itemID'))

for l in web_map.layers:
    if l.title == 'Layer title you want':
        # do your layer edits here&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 12:17:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1038564#M39029</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-03-19T12:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use ArcGIS API for python to specify a layer based on title</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1038934#M39064</link>
      <description>&lt;P&gt;Great, thank you Josh, that did the trick. I wonder if I could impose on you for one more question please (if you know the answer).?&lt;/P&gt;&lt;P&gt;Not only am I trying to specify a particular layer within a webmap (achieved above), I am also trying to specify a particular field within that layer. Example below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;my_webmap = gis.content.search(query="title:Trees",item_type="Web Map")
my_item = my_webmap[0]
my_itemID = my_item.id

wm = WebMap(gis.content.get(my_itemID))
# Thank you Josh...
for l in wm.layers:
    if l.title=="Gum Trees":
        l.popupInfo.fieldInfos[0].visible = True  
        #I want to turn on the visibility for a field called "Species", 
        #not just the first field in my layer.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want to run the command "l.popupInfo.fieldInfos[0].visible = True", for a field called "Species", not the first field at index '0' in my layer. As before, I want to iterate several layers and the index number may vary each time.&lt;/P&gt;&lt;P&gt;Regards, Damian&lt;/P&gt;</description>
      <pubDate>Sun, 21 Mar 2021 23:27:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1038934#M39064</guid>
      <dc:creator>Damian</dc:creator>
      <dc:date>2021-03-21T23:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use ArcGIS API for python to specify a layer based on title</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1407632#M58545</link>
      <description>&lt;P&gt;Thanks all for posting here. I spent a couple of days trying to do this exact same thing and was pulling my hair out. But now all issues are resolved. *Zen*&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 17:32:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1407632#M58545</guid>
      <dc:creator>AdamGaudet</dc:creator>
      <dc:date>2024-04-09T17:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do you use ArcGIS API for python to specify a layer based on title</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1407649#M58547</link>
      <description>&lt;P&gt;It's a few years after the fact, but did you ever solve for this issue? I might need to do something similar for another operation.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 18:06:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-do-you-use-arcgis-api-for-python-to-specify-a/m-p/1407649#M58547</guid>
      <dc:creator>AdamGaudet</dc:creator>
      <dc:date>2024-04-09T18:06:42Z</dc:date>
    </item>
  </channel>
</rss>

