In this sample, if a map is instantiated with the "hybrid" basemap (imagery and labels), the labels remain when the new basemap is selected from the gallery. If the map is instantiated with the "terrain" basemap (terrain, linework, and labels), the linework and labels remain.
See it in action here: Plunker
Solved! Go to Solution.
This was identified by Esri support as a bug: BUG-000089550
The initial workaround was to manually remove the reference overlay from the map's layer list the first time a new map is selected from the basemap gallery widget. However, since my application added the basemap through a configuration file, I couldn't always be sure a basemap with a reference layer would be used in the map construction.
Initially, support tried to use the map property basemapLayerIds, but this only works on the first change of the basemap. The property isn't changed when the basemap changes. Instead, the workaround uses the map's load event.
map.on("load", function(){ console.log(map); var basemaps = map.basemapLayerIds; setTimeout(function() { for(var index = 0; index < basemaps.length; index++) { var layer = map.getLayer(basemaps[index]); layer._basemapGalleryLayerType = "basemap"; console.log(layer); } }, 2000); });
This was identified by Esri support as a bug: BUG-000089550
The initial workaround was to manually remove the reference overlay from the map's layer list the first time a new map is selected from the basemap gallery widget. However, since my application added the basemap through a configuration file, I couldn't always be sure a basemap with a reference layer would be used in the map construction.
Initially, support tried to use the map property basemapLayerIds, but this only works on the first change of the basemap. The property isn't changed when the basemap changes. Instead, the workaround uses the map's load event.
map.on("load", function(){ console.log(map); var basemaps = map.basemapLayerIds; setTimeout(function() { for(var index = 0; index < basemaps.length; index++) { var layer = map.getLayer(basemaps[index]); layer._basemapGalleryLayerType = "basemap"; console.log(layer); } }, 2000); });
An update on this bug:
The status of Esri BUG-000089550 - When using the Basemap Gallery widget in the ArcGIS JavaScript API if the map is instantiated with a basemap that has a reference overlay the labels remain when the new basemap is selected. - that you have been associated with has been changed to Not in Current Product Plan.
Public Explanation: No plans to address for 3.x
That's a little disappointing.