map.getBasemap() not updating with the new base map

936
3
01-21-2014 05:24 AM
EkaitzHernandez
New Contributor
Hi all!

I have been working with BasemapGallery, and the Map class. My problem is that when I change the basemap with the basemapgallery then I try to access to  map.getBasemap() and is returning the same basemap that when the Map class was instantianted. It seems that the basemap in the Map class is not updating each time that I change the basemap with the BasemapGallery.


Thanks in advance and sorry for my English  😞
0 Kudos
3 Replies
Noah-Sager
Esri Regular Contributor
Hi Ekaitz,

Welcome to Esri Forum! Thank you for posting your question here.

I looked at our Basemap gallery sample, and you are correct, the map.getBasemap() returns the same basemap that the map was initialized with (e.g. "topo").

I think what you need to do to return the basemap from the basemap gallery widget is to use the getSelected() method.

Here is a code snippet that should work for that.

dojo.connect(basemapGallery,"onSelectionChange",function(){
     var basemap = basemapGallery.getSelected(); 
     alert(basemap.title);
});


Hope this helps!

-Noah
0 Kudos
EkaitzHernandez
New Contributor
Hi nsager, thank you for you reply.

I tried out with that method before, however the problem that  is returning different title that the title that I need in map.setBasemap("topo"). The problem is that title is "Topograpich" instead "Topo" that is the method that I need in setBasemap or when you need create a new map like here:

    map1 = new Map("map1", {
            basemap: "topo",
            center: [-105.255, 40.022],
           zoom: 3
          });



Do you know what I am trying to say?

Thank you


Hi Ekaitz,

Welcome to Esri Forum! Thank you for posting your question here.

I looked at our Basemap gallery sample, and you are correct, the map.getBasemap() returns the same basemap that the map was initialized with (e.g. "topo").

I think what you need to do to return the basemap from the basemap gallery widget is to use the getSelected() method.

Here is a code snippet that should work for that.

dojo.connect(basemapGallery,"onSelectionChange",function(){
     var basemap = basemapGallery.getSelected(); 
     alert(basemap.title);
});


Hope this helps!

-Noah
0 Kudos
Noah-Sager
Esri Regular Contributor
Hi Ekaitz,

I think I understand what you're saying. The issue is that you are comparing default Esri map basemaps from the JavaScript API to basemaps from ArcGIS.com.

Using the map constructor, valid basemap options from the JavaScript API are: "streets" , "satellite" , "hybrid", "topo", "gray", "oceans", "national-geographic", "osm". These are the default Esri basemaps that the JavaScript API can access and return.

The Basemap gallery sample uses the: "BasemapGallery widget to update the map's basemap. This widget presents a gallery of base maps that can be user-defined or generated by a query from ArcGIS.com. In this snippet a new BasemapGallery widget is created that contains basemaps from ArcGIS.com". Thus, these basemaps may not have the same name as the basemaps from the map constructor.

If you look at the Basemap Toggle sample, you can see that the "map.getBasemap()" method returns the actual name of the current basemap when you switch between them.

That being the case, you have several options moving forward, depending on what you wish to accomplish. You could create your own custom basemaps, and call them whatever you want. You could use the Esri basemaps that the JavaScript API can access and return in a basemap gallery dijit or basemap toggle dijit style, and have the names be the same there as they are in the map constructor.

-Noah
0 Kudos