I need to modify this widget to return only two 'baseMaps' (it is written to return all baseMaps). I have been successfull except for one problem: the list in the combo box populates with duplicate values, 5 in fact, or 10 if I choose to include 2 layers, as in my example below. I use an index value to select the layer (the default is var i from the loop).
The original script is as follows:
private function getBasemapLayer():ArrayCollection
{
var baseMaps:ArrayCollection = new ArrayCollection();
for(var i:Number=0; i<configData.configBasemaps.length; i++)
{
baseMaps.addItem(configData.configBasemaps.label);
}
return baseMaps;
}
// TODO: Change to pull from configdata object
private function getLayers():ArrayCollection
{
var basemapLyrs:ArrayCollection = getBasemapLayer();
var layers:ArrayCollection = new ArrayCollection();
for(var i:Number = map.layerIds.length -1; i >= 0; i--)
{
var basemapLyr:Boolean = false;
for each(var id:String in basemapLyrs){
if (map.layerIds == id){
basemapLyr = true;
break;
}
}
if (basemapLyr) continue;
var layer:Layer = map.getLayer(map.layerIds);
if(!(layer is GraphicsLayer))
layers.addItem(layer);
}
return layers;
}
My modification is to the last section:
if (basemapLyr) continue;
var layer:Layer = map.getLayer(map.layerIds[2]);
var layer2:Layer = map.getLayer(map.layerIds[3]);
if(!(layer is GraphicsLayer))
layers.addItem(layer);
layers.addItem(layer2);
}
return layers;
}
Attached is a jpg of the combo box: it is populated with the two layers, but in pairs of 5, i.e. five duplicate items each (the second layer is in white, hard to see) .
The dataprovider for the combo box is mMapServices, which is declared = to the getLayers() function in the init().
Thanks,
Jim Faron