Hi, I'm working with the javascript 3.2 api, and have a map that loads from a pre-defined web map. I'm now wanting to get a handle to a layer in the map using the layer name.
I've managed to write some javacript code that locates the layerInfo for the said layer, but I have no idea how to get the actual layer from the map.
_getFeatureLayer: function(layerName) {
var layer;
for (var j = 0, jl = this.map.layerIds.length; j < jl; j++)
{
var currentLayerName = this.map.layerIds;
var currentLayer = this.map.getLayer(currentLayerName);
if (currentLayer.layerInfos.length > 0)
{
layer = this._findSubLayerByName(currentLayer, layerName);
if (layer != null)
{
break;
}
}
}
return layer;
},
_findSubLayerByName: function (parentLayer, subLayerName)
{
var layer;
for (var j = 0, jl = parentLayer.layerInfos.length; j < jl; j++)
{
var layerInfo = parentLayer.layerInfos;
if (layerInfo.name == subLayerName)
{
/* The correct layer is located, but how do I actually get the layer, this does not work. */
var subLayerUrl = parentLayer.url + "/" + j;
layer = new FeatureLayer(subLayerUrl); /* This doesn't give me the layer that is already added to the map */
break;
}
}
return layer;
}