Select to view content in your preferred language

Create a base map gallery list in a drop down button using AMD

4212
10
Jump to solution
05-17-2013 12:11 PM
KenBuja
MVP Esteemed Contributor
I'm attempting to convert the example that Kelly wrote to add the basemap gallery basemaps to the map in a dropdown button into AMD. I'm running into a problem with getting the base maps added to the button. In this function, the ForEach loop fires, but the children aren't added. I've created a fiddler with the new code and original code commented out.

                         function createBasemapGallery() {                 var basemapGallery = new BasemapGallery({                     showArcGISBasemaps: true,                     map: map                 });                  connect.connect(basemapGallery, 'onLoad', function () {                     array.forEach(basemapGallery.basemaps, function (basemap)                          dom.byId('basemapMenu').addChild(new dijit.MenuItem({                             label: basemap.title,                             onClick: lang.hitch(this, function(){                                 this.basemapGallery.select(basemap.id);                             })                         }));                     });                 });             } 
0 Kudos
10 Replies
by Anonymous User
Not applicable
This is just a note for anyone who comes across this thread.

I had to revisit the issue with the basemapGallery dijit loading that I encountered before and finally got it resolved, definitely a forehead slapping moment as the reason is in the documentation ("'[load] Fires when the BasemapGallery retrieves the ArcGIS.com basemaps"). If 'showArcGISBasemaps:true' is set then it's important to use the basemaps.on("load") syntax. If it's ever set to false, however, this will NEVER fire because load only fires for fetching ArcGIS.com basemaps. The code now is:

 if (basemapGallery.showArcGISBasemaps) {
  basemapGallery.on("load", function() {
   createBasemapGallery();
  });
 } else {
  createBasemapGallery();
 }
0 Kudos