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:
<SPAN class="keyword token">const</SPAN> baseMap <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'defaultBasemap'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN> baseMap <SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">removeLayer</SPAN><SPAN class="punctuation token">(</SPAN>baseMap<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setBasemap</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'streets'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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.
//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);
Hopefully you find the answers you seek; I wish I could be more helpful!
map1.setBasemap('topo');
var baseMapLayer = new ArcGISTiledMapServiceLayer("http://services.portlandmaps.com/ags/rest/services/Public/Basemap_Gray/MapServer"); map1.addLayer(baseMapLayer);
require(["esri/layers/ArcGISTiledMapServiceLayer", ... ], function(ArcGISTiledMapServiceLayer, ... ){ ... });
var mapDeferred = new esriUtils.createMap('ec7080edfb7c4197989dee3c6207264c', 'map1', { mapOptions:{ basemap:"streets" } });
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.