RWinter85

on "basemap-change" not firing and getBasemap not working as expected

Discussion created by RWinter85 on Oct 23, 2013
Latest reply on Oct 23, 2013 by RWinter85
Hi all,

  I am having some troubles with these two event listeners(onBasemapChange() and it's on equivalent "basemap-change") for the map as well as the map.getBasemap() function.

I have tried this in my own code and then also went to the basemap gallery sample and added these events/function to the sandbox to test there as well.

The sample I used is here: http://developers.arcgis.com/en/javascript/sandbox/sandbox.html?sample=widget_basemap

I then added the following code:
map.on("load",function(){
  map.on("basemap-change",function(){
    alert("Fired Basemap-change");
  });
});
        
basemapGallery.on("selection-change",function(){
  alert(map.getBasemap());
});


The "Fired Basemap-change" alert never fires even when I tried this
dojo.connect(map,"onBasemapChange",function(){
  alert("Fired Basemap-change")
})


The second alert will fire as it is inside the basemapGallery.on("selection-change") but the map.getBasemap() returns the same string every time, whatever I set the default basemap inside the map constructor to is the value this function always returns, I thought it was supposed to return the well-known name of the current basemap, is this normal for this function?

In the end I am building a custom dojo widget to sync 4 map objects together and am trying to add in a basemap syncing option as well so that when the user changes the basemap on the main map, it changes the other maps basemaps as well.  My thought was to get the well-known name of the current basemap from the main map and then loop through my array of other maps and just simply call map.setBasemap.  Is there another way to get this well-known basemap name?

Outcomes