AnsweredAssumed Answered

WebMap add_layer for Map Service

Question asked by rteniere on Feb 8, 2018
Latest reply on Feb 14, 2018 by rteniere

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 = gis.content.search("title:"+layerProperties['title'],item_type=itemType)

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

      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',
'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:
   layerError = True
else:
   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',
'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:
   # Update the BaseMap
   wm.basemap.update({'title':layerProperties_Base['title']})
   wm.basemap.baseMapLayers[0].update({'url':layerProperties_Base['url'], 'title':layerProperties_Base['title']})

   wm.add_layer(layer=layer_Wildlife)
   wm.save(item_properties=webMapProperties_PLV, thumbnail=thumbnail_WM_PLV)

Outcomes