When you query a map service end point, the result is one image. That is what ArcGIS will consider as your layer.
From a WMS standpoint, you can generate that image using one or more layer from your WMS Service.
When referring to the doc on https://developers.arcgis.com/javascript/3/jsapi/wmslayer-amd.html#wmslayer1, this is what you see at the definition of the constructor: new WMSLayer(url, options?)
In the following example: https://developers.arcgis.com/javascript/3/jssamples/layers_wmsresourceinfo.html
The following is the info (options parameter)from your WMS Service you choose to display:
var layer1 = new WMSLayerInfo({
name: '1',
title: 'Rivers'
});
var layer2 = new WMSLayerInfo({
name: '2',
title: 'Cities'
});
var resourceInfo = {
extent: new Extent(-126.40869140625, 31.025390625, -109.66552734375, 41.5283203125, {
wkid: 4326
}),
layerInfos: [layer1, layer2]
};
Then you use your WMS Service URL and your options to add the view of your WMS endpoint to ArcGIS JS API:
var wmsLayer = new WMSLayer('https://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer', {
resourceInfo: resourceInfo,
visibleLayers: ['1', '2']
});
map.addLayers([wmsLayer]);
After a few weeks getting up to speed on the ArcGIS Python API, I have come up with work flow that works quite well. My original understanding of scripting using JSON dictionaries was a bit off as well as the structure of FeatureLayerCollection, FeatureLayer, FeaturesSet, and Feature objects from the new API. My process thus far involves manually publishing layers I need in the AGOL portal and then updating them through a process of truncation and then adding all of the updated local features to the hosted layers. Here is a simplified process that gives python access to the content of an AGOL portal, allows for truncating the layers, and adding features back to the layer from a local source.
import arcpy
import arcgis
from arcgis.gis import GIS
def TruncateWebLayer(gis=None, target=None):
try:
lyr = arcgis.features.FeatureLayer(target, gis)
lyr.manager.truncate()
print ("Successfully truncated layer: " + str(target))
except:
print("Failed truncating: " + str(target))
sys.exit()
#create connection to AGOL portal GIS
mygis = arcgis.gis.GIS(r"https://aportal.maps.arcgis.com", "someUser", "somePassword")
#the URL of a single feature layer within a collection in an AGOL portal
publishedWebLayer = r"https://services6.arcgis.com/XXXXXXXXXXXX/arcgis/rest/services/XXXX/FeatureServer/0"
#a feature class on the local system with the same schema as the portal layer
updateFeatures = r"G:\DataData\Data.gdb\Data"
#remove all features from the already published feature layer
TruncateWebLayer(mygis, publishedWebLayer)
#reference the empty layer as FeatureLayer object from the ArcGIS Python API
fl = arcgis.features.FeatureLayer(publishedWebLayer, mygis)
#create a JSON object from the local features
jSON = arcpy.FeaturesToJSON_conversion(updateFeatures, localJSON)
#create a FeatureSet object from the JSON
fs = arcgis.features.FeatureSet.from_json(open(localJSON).read())
#add/append the local features to the hosted feature layer.
fl.edit_features(adds = fs)
This is a simplified example of how this can be achieved. A few things to note. I have not been able to get this process to work on more complicated geometries like curve rings, rings, etc. For polygons and lines I typically add an arcpy.Generalize_edit() before creating the JSON. This converts the curves into approximated line segments.
Best Answer
I don't see any methods in the API that allow you to add / modify the basemap of a webmap.
You might be able to take the long-way-approach to solving this. You'll need have a webmap with your layers ready to be used (or create it using Python API). Then you could create a new webmap and pass in the previous webmap. It'll be added to the basemap of this new webmap. Once you have this created, you can call add (more operational layers) / save to finish the webmap. Yes, unfortunately in the end you're making new items instead of updating existing ones.
reference: https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.mapping.html#webmap and https://developers.arcgis.com/python/sample-notebooks/using-and-updating-gis-content/