jorge.vinagreesri-portugal-pt-esridist

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
application.



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

initMap();

[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");


    //basemapGallery.startup();


    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) {..........});
        theMap.addLayers(arrOperationalLayers.reverse());
    });


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)?

Thanks

PS : JS API 3.2

Outcomes