How to toggle visibility of item/layer in a feature service using ArcGIS API for Python (ver. 1.2.5)

1563
1
08-07-2018 12:40 PM
PhilipFrancis
New Contributor II

Question:

With the ArcGIS API for Python (ver. 1.2.5), how can I turn on items/layers (i.e., toggle visibility or make visible) on my org account ***.maps.arcgis.com (in feature services that I am have sufficient privilege for)? Do I use the something included in the ContentManager or in some other module/package/etc.? It appears this is possible with the Javascript API, possibly with SDKs, and I can not tell if this is already possible with other types of content via the API.

Problem:

I am using ArcGIS python API (ver. 1.2.5 implies py3) to create feature layers on my arcgis.com org account (from layers of Map Images on hosted one of our own enterprise Arc Servers) and I can not determine how to enable/disable visibility of the feature layers that I am creating.

Backstory:

Some of the Map Images that I work with on our enterprise Arc Server (from which I am creating feature layers with aforementioned visibility issue) hve sufficient quantity of layers to warrant turning all the (Map Image) layers off by default (done with the arcpy code that created them). The subsequent/derived problem I face is that the feature layers I am creating on our org account on arcgis.com site has each layer/item also turned off (i.e., not visible) (except in mobile browsers, curiously, though not too surprisingly).

Preemptive:

For the curious few who are wondering why I don't just use similar code to that which created the Map Images, I would state that the code that created the original Map Images used Arcpy (py2) and uses a line of code, as follows:

        for lyr in arcpy.mapping.ListLayers(mxd, "", df):
            # Turn off layer (make non-visible)
            lyr.visible = False

I am looking for a Python API solution, not an arcpy solution.

Cultural Considerations:

I am a programmer who reads API documentation and I tend work with to the sad neglect of my mouse, a GUI and point-and-click methods (though I welcome all comments). Please consider me slightly new to GIS and my knowledge/exposure has tended to be 99.42% code-based and thus slightly illiterate in ArcMap terminology  (terminology which is often different in each of this multitude of APIS/languages).

1 Reply
DavinWalker2
Esri Contributor
Hi Philip, I know this is an old thread but I thought I'd respond anyway so at least a possible solution is posted. I'm using ArcGIS Python API ver 1.8.1 The process to do it is: #Get the list of layers from a web map from arcgis.mapping import WebMap wm = WebMap(wm_item) #List Layers wm.layers #Turn Layer visibility off for lyr in wm.layers: lyr.visibility = False