Can you remove the basemap using BasemapGallery?

5783
4
09-30-2010 08:01 AM
BenSayers
New Contributor II
Hello,
I am trying compile my own basemap gallery, I have it all working, except I would like to provide users with the option to turn off all underlying Tiled Map layers as sometimes the imagery gets in the way of the features.
This is what I have:
function createBasemapGallery(){
       var basemaps= [];
        var imageryLayer = new esri.dijit.BasemapLayer({
          url:"http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
        });
        var imageryBasemap = new esri.dijit.Basemap({
          layers:[imageryLayer],
          title:"Imagery",
          thumbnailUrl:"images/imageryThumb.jpg"
        });
        basemaps.push(imageryBasemap);

  var boundariesLayer = new esri.dijit.BasemapLayer({
          url:"http://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer"
        });
        var imageryBoundariesBasemap = new esri.dijit.Basemap({
          layers:[boundariesLayer,imageryLayer],
          title:"Imagery (labels)",
          thumbnailUrl:"images/imagery_labelsThumb.jpg"
        });
        basemaps.push(imageryBoundariesBasemap);
  
  var topographicLayer = new esri.dijit.BasemapLayer({
          url:"http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"
        });
        var topographicBasemap = new esri.dijit.Basemap({
          layers:[topographicLayer],
          title:"Topographic",
          thumbnailUrl:"images/topographicThumb.jpg"
        });
        basemaps.push(topographicBasemap);
  
  var streetLayer = new esri.dijit.BasemapLayer({
          url:"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
        });
        var streetBasemap = new esri.dijit.Basemap({
          layers:[streetLayer],
          title:"Street Map",
          thumbnailUrl:"images/streetThumb.jpg"
        });
        basemaps.push(streetBasemap);  
  
  var terrainLayer = new esri.dijit.BasemapLayer({
          url:"http://services.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer"
        });
        var terrainBasemap = new esri.dijit.Basemap({
          layers:[terrainLayer],
          title:"Terrain Map",
          thumbnailUrl:"images/terrainThumb.jpg"
        });
        basemaps.push(terrainBasemap);   
  
  var noneLayer = new esri.dijit.BasemapLayer({
          url:"http://"
        });
        var noneBasemap = new esri.dijit.Basemap({
          layers:[noneLayer],
          title:"None",
          thumbnailUrl:"images/noneThumb.jpg"
        });
        basemaps.push(noneBasemap);  
  
        var basemapGallery = new esri.dijit.BasemapGallery({
         showArcGISBasemaps:false,
         basemaps:basemaps,
         map:map
        },"basemapGallery");
        basemapGallery.startup();
        dojo.connect(basemapGallery, "onError", function(error) {console.log(error)});
      }


When I click on None the map doesn't change and whichever was the previous selected basemap stays active.

Any ideas?
0 Kudos
4 Replies
BillDaigle
Occasional Contributor III
The following seems to work:

var noBaseMap = new esri.dijit.Basemap({
      layers:[],
      title:"None",
      thumbnailUrl:"images/none.jpg"
    });
  basemaps.push(noBaseMap);
0 Kudos
BillDaigle
Occasional Contributor III
One way to do this is to search all map layers and look for the "_basemapGalleryLayerType" property.  If it is set to "basemap", then you can simply hide the layer. 
It works in 2.2.  I haven't tried it with the other versions of the API, so I'm not sure if the "_basemapGalleryLayerType" property is always available or not.

Here's what my function looks like:

 hideBaseMap: function(){
    var _this = this;
    dojo.forEach(this.map.layerIds, function(id){
      var layer = _this.map.getLayer(id);
      if (layer._basemapGalleryLayerType === "basemap") {
        layer.hide()
      }
    });
  } 
0 Kudos
JayThakur
New Contributor

Hi,

I want to customize my basemap gallery. I want to remove streets and streets and openstreetmap from the gallery, all the remaining basemaps are still there in the gallery.

I tried using BasemapGallery | API Reference | ArcGIS API for JavaScript the function

function removeBasemap(id){
  basemapGallery
.remove(id);
}

and also just basemapGallery.remove(galleryNode_basemap_7) as shown in the bellow image;remove_basemap.PNG

But dint work. can someone help me in removing those two basemaps from the basemap gallery.

Thanks in advance.

0 Kudos
BillDaigle
Occasional Contributor III

You'll need to wait for the basemap to load before using the 'remove' function.

basemapGallery.on('load',function(){
  basemapGallery.remove('basemap_2');
  basemapGallery.remove('basemap_9');
});
basemapGallery.startup();