Yes you can remove all the layers using map.removeAllLayers() . You can remove individual layers using:function removeMe()
{
map.removeLayer(referenceLayer);
map.removeLayer(basemap);
}
All layers at once using:function removeMe()
{
map.removeAllLayers();
}
Or else you can remove all layers in a loop using:function removeMe()
{
var count = map.layerIds.length;
var array = [];
for(var i=0;i<count;i++)
{
array = map.layerIds;
}
for(var j=0; j<count; j++){
var layer = map.getLayer(array);
map.removeLayer(layer);
}
}