AnsweredAssumed Answered

ArcGIS API for Python Update Layers Skips Some Maps

Question asked by guarnerij on Jul 31, 2019

I'm having some trouble with updating layers using the ArcGIS API for Python. I had updated a map image layer with some new sublayers, and wanted to make sure the new layers were applied everywhere the original MIL is used. I wrote a notebook to find and remove the instances of this MIL and re-add to the map. This worked for most of the maps, but enough didn't that I ended up having to check them all manually. I'll step through my code below if anyone can tell me if I'm missing something.


First, I listed all the web maps owned by our admin user and created an Item object for the MIL:

maps ="type: Web Map NOT Application owner: GeoNexusAdmin@PENNICHUCK", max_items = 100)

newLayer ='id:b8c15eb2b33b4c0bbb7dfa0011cb28be')[0]


Next, I iterated through the maps and looked for the MIL in question. If it was found, I removed and replaced the layer:

for m in maps:
    map = arcgis.mapping.WebMap(m)
    #loop through layers in each map
    layers = map.layers
    for l in layers:
        #store layer index number
        layerNum = map.layers.index(l)
        #if a matching itemid is found, remove layer and add it back in
        if 'itemId' in layers[layerNum]:
            if layers[layerNum]['itemId'] =='b8c15eb2b33b4c0bbb7dfa0011cb28be':
                #print map title to confirm


Almost every map that was printed in the output list updated the MIL succesfully, but about 3 did not. Is this a glitch in the system, or do I need to make some tweaks to my code? At the very least, it would be nice to be able to identify and list the maps that did not update successfully.