Skip to main content
1 of 2
Loren
  • 111
  • 3

Here's a function to remove the current basemap from the bottom layer, then add a new basemap and move it to the bottom layer.

function setBasemap(basemap) {
  if (currentBasemap) {
    map.removeLayer(currentBasemap);
  }
  currentBasemap = basemap;
  map.addLayer(basemap);
  basemap.bringToBack();
}
var currentBasemap = basemap1; // default map
setBasemap(currentBasemap); // Init

Then add the following within a click event to swap in another basemap:

   setBasemap(basemap2);
Loren
  • 111
  • 3