AnsweredAssumed Answered

WebMap add_layer for Map Service

Question asked by rteniere on Feb 8, 2018
Latest reply on Dec 20, 2018 by

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:

When I try to programatically add it to the web map using add_layer, I get the following:

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.


# Internal modules go here
def createLayer(layerProperties, thumbnailPath, itemType='Map Service', layerOwner=None, layerFolder=None):
   layer = False
   sr ="title:"+layerProperties['title'],item_type=itemType)

   if (len(sr) > 1):
      print("Multiple Layers Found!")
      return False
      if (len(sr) == 1):
         print("Layer Exists!")
         item = gis.content.get(sr[0].id)

      print("Creating Layer...")
      layer = gis.content.add(item_properties=layerProperties, thumbnail=thumbnailPath, owner=layerOwner, folder=layerFolder)

   return layer

layerError = False

# Create Wildlife layer from service
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',
'accessInformation':'Nova Scotia Department of Natural Resources',
'type':'Map Service',

layer_Wildlife = createLayer(layerProperties_Wildlife, thumbnail_Wildlife)
if layer_Wildlife == False:
   layerError = True
   print("Wildlife Layer Created Successfully!")
# Create an empty web map with a default basemap
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',
'accessInformation':'NS Internal Services, NS Department of Natural Resources, Service NS, Land Services Branch, Surveys Division, GIS Cartography Section',

if layerError ==False:
   # Update the BaseMap
   wm.basemap.baseMapLayers[0].update({'url':layerProperties_Base['url'], 'title':layerProperties_Base['title']})

   wm.add_layer(layer=layer_Wildlife), thumbnail=thumbnail_WM_PLV)