//get title of basemap var currentBasemapName = webmapResponse.itemInfo.itemData.baseMap.title var bmNameEqiv = bmDict[currentBasemapName ]; esriMap.removeLayer(webmapResponse.itemInfo.itemData.baseMap.baseMapLayers[0].layerObject); //just reset the base map so we can use setBaseMap later esriMap.setBasemap(bmNameEqiv);
Thanks for the answer, which is still helpful three more years later. This solution fixed the problem that setBaseMap cannot recognize the basemap from web map.
I think the possible mechanism of setBaseMap() might be: Delete the basemap of map.basemapLayerIds, and then import the new one.
I had a similar problem setting the basemap using map.setBasemap and stumbled on this thread. After a bit of investigation I discovered that when using a webmap the map object holds a reference to the initial basemap as 'defaultBasemap'. You can see that by examining map.layerIds. As long as that layer remains in the map, setting a new basemap with `map.setBasemap('topo')` will not work properly. The new layer gets added, but the 'defaultBasemap' layer remains. The easiest solution is removing the 'defaultBasemap' layer just before setting a new basemap. Here's how I achieved it:
const baseMap = map.getLayer('defaultBasemap');
if( baseMap ) {
map.removeLayer(baseMap);
}
map.setBasemap('streets');