JS API proper web app layer initialization

Discussion created by jorge.vinagreesri-portugal-pt-esridist Employee on Jul 9, 2013
HI there

I would like to know how to properly initialize the basemap gallery(not arcgis basemaps) and operational layers in a web map

The code that exists now has the following order and it feels a little bit strange:


[config map and set intial extent]
[get base map and operation layers from a config file]
->initializeBaseMapsAndLayers(map, arrBasemaps, arrOperationalLayers);
which has the follwing code:

//Initialize BaseMaps
    var basemapGallery = new esri.dijit.BasemapGallery({
        showArcGISBasemaps: false,
        map: theMap,
        basemaps: arrBaseMaps
    }, "divBaseMapsGallery");


    dojo.connect(basemapGallery, "onError", function (msg) { console.log('initializeBaseMapsAndLayers error:' + msg) });

    dojo.connect(basemapGallery, "onSelectionChange", function () {
        //Add all the Operational Layers to the Map:
  //This fires dojo.connect(map, 'onLayersAddResult', function (results) {..........});

Then comes the onLayersAddResult event which configures stuf like nav bar and so

Is this the best way to do the initialization(i believe it is not)?


PS : JS API 3.2