Is it possible to get basemap short name?

609
1
06-27-2014 03:16 AM
SimonHodge
New Contributor III
When you create a map you can pass it an options object and specify the name of the basemap to load using a short name for each of the standard basemaps.  e.g.

var map = new Map({ basemap: "topo" });


Will load the Topographic map.  According to the api:

The following are valid options: "streets" , "satellite" , "hybrid", "topo", "gray", "oceans", "national-geographic", "osm". As of version 3.3


map.getBasemap() then returns the short name of the basemap it was loaded with, e.g "topo".

I'm then using the Basemap Gallery to allow the basemap to be changed.  However, even after changing the basemap via the Basemap Gallery, calling map.getBasemap() always returns the name of the basemap that the map was loaded with, not the name of the currently selected basemap.

You can get the currently selected basemap from the BasemapGallery using basemapGallery.getSelected().  The object this returns has a name property but this is the basemaps full name, i.e. "Topographic", "Imagery with Labels" etc.

Does anyone know how to get the short name of a basemap after it's been changed using the basemap gallery, or anything built in that can translate full names back to short names?

Thanks
Simon
0 Kudos
1 Reply
KonstantinLapine
New Contributor
It appears map.getBasemap() returns the basemap used in map constructor.

You can easily get title of a selected in the Basemap gallery map. Example:

http://developers.arcgis.com/javascript/samples/widget_basemap/

Select a basemap, then:

var b = dijit.byId('basemapGallery');
var s = b.getSelected();
var title = '';

if (s) {
    title = b.getSelected().title;
}

console.log(title);
0 Kudos