Solved! Go to Solution.
//make a flag so that we only pull out the second basemap layer the first time its changed var isFirst = true; ... basemapGallery.on("selection-change", function() { if (isFirst) { //check to make sure that the first basemap shown actually displayed two different tiled layers if (basemapGallery.getSelected().title == "Imagery with Labels" || basemapGallery.getSelected().title != "Light Gray Canvas" || basemapGallery.getSelected().title != "Terrain with Labels") { map.removeLayer(map.getLayer(map.layerIds[1])); //set the flag to false so none of this code fires again isFirst = false; } } });
//make a flag so that we only pull out the second basemap layer the first time its changed var isFirst = true; ... basemapGallery.on("selection-change", function() { if (isFirst) { //check to make sure that the first basemap shown actually displayed two different tiled layers if (basemapGallery.getSelected().title == "Imagery with Labels" || basemapGallery.getSelected().title != "Light Gray Canvas" || basemapGallery.getSelected().title != "Terrain with Labels") { map.removeLayer(map.getLayer(map.layerIds[1])); //set the flag to false so none of this code fires again isFirst = false; } } });