<?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: WebMap add_layer for Map Service in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/webmap-add-layer-for-map-service/m-p/879505#M5028</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anyone know if there is a way to show only the main layer in the TOC so it looks like the webmap created in the online mapviewer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Feb 2018 15:17:10 GMT</pubDate>
    <dc:creator>René_Ténière</dc:creator>
    <dc:date>2018-02-14T15:17:10Z</dc:date>
    <item>
      <title>WebMap add_layer for Map Service</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/webmap-add-layer-for-map-service/m-p/879504#M5027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to add a layer that I have created from a map service. The layer is easily added to a web map using the online MapViewer in my org account. The map layer consists of multiple service layers. The result is as seen below:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/396143_pastedImage_1.png" style="width: 234px; height: 247px;" /&gt;&lt;/P&gt;&lt;P&gt;When I try to programatically add it to the web map using add_layer, I get the following:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/396144_pastedImage_2.png" style="width: 242px; height: 452px;" /&gt;&lt;/P&gt;&lt;P&gt;It breaks out all the layers individually from the service itself. Code is below for creating the layer from the service and creating the webmap and adding the layer to it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;STRONG&gt;# Internal modules go here&lt;/STRONG&gt;
def createLayer(layerProperties, thumbnailPath, itemType='Map Service', layerOwner=None, layerFolder=None):
&amp;nbsp;&amp;nbsp;&amp;nbsp;layer = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;sr = gis.content.search("title:"+layerProperties['title'],item_type=itemType)

&amp;nbsp;&amp;nbsp;&amp;nbsp;if (len(sr) &amp;gt; 1):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print("Multiple Layers Found!")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return False
&amp;nbsp;&amp;nbsp;&amp;nbsp;else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (len(sr) == 1):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print("Layer Exists!")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;item = gis.content.get(sr[0].id)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;item.delete()

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print("Creating Layer...")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;layer = gis.content.add(item_properties=layerProperties, thumbnail=thumbnailPath, owner=layerOwner, folder=layerFolder)
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;return layer

layerError = False

&lt;STRONG&gt;# Create Wildlife layer from service&lt;/STRONG&gt;
svcName_Wildlife = "WLD_ProvLandScapeViewer_WM84"
thumbnail_Wildlife = os.path.join(thumbURL,svcName_Wildlife+'.jpg')

layerProperties_Wildlife = {
'title':'Wildlife Areas',
'description':'This layer contains data for moose and deer management zones, Significant Habitats, Wetlands, and Special Management Practices for Atlantic Coastal Plain Flora Buffers, Marten, Lynx, and Mainland Moose.',
'snippet':'Wildlife Areas layer',
'tags':'wildlife,wetlands,moose,deer,habitat,marten,lynx,moose,NSGI,GeoNOVA',
'licenseInfo':licInfo,
'accessInformation':'Nova Scotia Department of Natural Resources',
'type':'Map Service',
'access':'org',
'url':os.path.join(devURL,'BIO/'+svcName_Wildlife+'/MapServer')
}

layer_Wildlife = createLayer(layerProperties_Wildlife, thumbnail_Wildlife)
if layer_Wildlife == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp;layerError = True
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;print("Wildlife Layer Created Successfully!")&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;STRONG&gt;# Create an empty web map with a default basemap&lt;/STRONG&gt;
from arcgis.mapping import WebMap
wm = WebMap()

svcName_WM_PLV = "ProvincialLandscapeViewer_WM"
thumbnail_WM_PLV = os.path.join(thumbURL,svcName_WM_PLV+'.jpg')

webMapProperties_PLV = {
'title':'Provincial Landscape Viewer Web Map',
'description':'Web map for the Provincial Landscape Viewer web application',
'snippet':'Map to hold Provincial Landscape Viewer data',
'tags':'PLV, crown, wildlife, property, protected, provincial, landscape, viewer, forestry, elc, roads',
'licenseInfo':licInfo,
'accessInformation':'NS Internal Services, NS Department of Natural Resources, Service NS, Land Services Branch, Surveys Division, GIS Cartography Section',
'access':'org',
'extent':'-7474460,5356290,-6600165,5966315'
}

if layerError ==False:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;# Update the BaseMap&lt;/STRONG&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;wm.basemap.update({'title':layerProperties_Base['title']})
&amp;nbsp;&amp;nbsp;&amp;nbsp;wm.basemap.baseMapLayers[0].update({'url':layerProperties_Base['url'], 'title':layerProperties_Base['title']})
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;wm.add_layer(layer=layer_Wildlife)
&amp;nbsp;&amp;nbsp;&amp;nbsp;wm.save(item_properties=webMapProperties_PLV, thumbnail=thumbnail_WM_PLV)

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 17:02:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/webmap-add-layer-for-map-service/m-p/879504#M5027</guid>
      <dc:creator>René_Ténière</dc:creator>
      <dc:date>2021-12-12T17:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: WebMap add_layer for Map Service</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/webmap-add-layer-for-map-service/m-p/879505#M5028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anyone know if there is a way to show only the main layer in the TOC so it looks like the webmap created in the online mapviewer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Feb 2018 15:17:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/webmap-add-layer-for-map-service/m-p/879505#M5028</guid>
      <dc:creator>René_Ténière</dc:creator>
      <dc:date>2018-02-14T15:17:10Z</dc:date>
    </item>
  </channel>
</rss>

