//add the legend map.on("layers-add-result", function (evt) { var layerInfo = arrayUtils.map(evt.layers, function (layer, index) { return {layer:layer.layer, title:layer.layer.name}; }); if (layerInfo.length > 0) { var legendDijit = new Legend({ map: map, layerInfos: layerInfo }, "legendDiv"); legendDijit.startup(); } });
if ((layer.layer.id == "tracts") || (layer.layer.id == "counties")) { return { layer: layer.layer, title: layer.layer.name }; }
I've run across the same problem. Rather than handle this in the layers-add-result event, you can build the layerInfos while you are adding the layers to the map.
First, create an empty array. Then, as you add each layer to the map, if the layer is not a WebTiledLayer, add a layerInfo element to that array. Finally, construct the Legend dijit, passing in your clean array of LayerInfos.
Ultimately, the lack of legend is a real shortcoming with WebTiledLayers. I'd like to see an alternate Legend dijit that lets me include a legend for my WebTiledLayers, too.