How do I Iterate/Loop through all layers of a map - load a dojo combox with Names.

4279
1
08-03-2010 12:41 PM
TraciDukes
New Contributor
Hi All,
  I have added serveral layers to my map using id: as in the statement below.
I want to iterate/loop through the layers and if it is a visible layer add it to a dojo.combobox.
I have tried everything to loop through the layers unsuccessfully.
Can anyone please help.
Thanks Traci

var schools = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisservice.mt.gov/ArcGIS/rest/services/MSDI_Framework/SchoolDistrictBoundaries/MapServer", { id: "School Districts", visible: true });
0 Kudos
1 Reply
TraciDukes
New Contributor
Sorry I got it.  For anyone else stuck on this.
Here is an answer.

var options = new dojo.data.ItemFileWriteStore({ data: { identifier: 'name', items: []} });
    s = "ALL BOUNDARIES";
    options.newItem({ name: s });
    s = "";
var count = map.layerIds.length;
    for (var i=1;i<count-1;i++)
    {
        var layerName = map.layerIds;
        var layer = map.getLayer(layerName);
        if (layer.visible) {
            options.newItem({name:layerName});
        }
    }

    var combo3 = dijit.byId('selectBoundary');
    combo3.attr('store', options);
0 Kudos