basemap-change event not called in 3.20

622
1
04-17-2017 09:51 AM
BryanBaker
Occasional Contributor

The basemap-changed event does not appear to fire correctly in the 3.20 version of the API. It doesn't work in my app, nor in the simple basemap gallery sample in the sandbox. I called up the sample at https://developers.arcgis.com/javascript/3/sandbox/sandbox.html?sample=widget_basemap, and then inserted a handler for the event just before the close of the script:

 map.on("basemap-change", function(e){
   console.log(e.current);
});

Nothing gets logged when the basemap changes. Is there some other way to get this to work? Or is it not really called when the basemap layer changes?

0 Kudos
1 Reply
BryanBaker
Occasional Contributor

So it appears that the BasemapGallery does not actually change the map's official "basemap". It removes the current basemap layer, but then just adds the new tiled layer to the map without updating the map's "basemap" (e.g., by using map.setBasemap()). In a way that makes sense in that you can add non-standard layers to the BasemapGallery, and those layers would not be one of the options available for the map.setBasemap method argument.

I can instead use the BasemapGallery's selection-change event to track the change to its basemap layer.

It would be helpful if the documentation in both the BasemapGallery and the map's relevant events/methods (basemap-change, getBasemap, setBasemap) noted that they are not talking about the same "basemap".