I have recently created a web map that uses the legend snippet from the ESRI JavaScript API website. https://developers.arcgis.com/en/jav...et_legend.html

It works great for the most part, but has one issue, there are duplicate entries in the legend. The rest services that I am using are all symbolized properly without duplicates. The method I'm using to add the services to the map is through a feature layer.

enter image description here

This is the exact code in my .js file.

dojo.connect(myMap, 'onLayersAddResult', function (results) {
    var layerInfo = dojo.map(results, function (layer, index) {
        return { layer: layer.layer, title: layer.layer.name };

    if (layerInfo.length > 0) {
        var legendDijit = new esri.dijit.Legend({
            map: myMap,
            layerInfos: layerInfo},

//Layers are added to map
myMap.addLayers([featureLayer1, DMSL_StudyArea]);

Any information would help.


  • 1
    Welcome to SE.GIS forum. May be I think two layers which you have added at last using addlayer method has few common fields that's the reason your are getting duplicate legends. Try to add single layer then check. Legend code is perfect. – Sunil Jul 17 '13 at 4:59
  • Thanks for your comment, Sunil. I was wondering about the addLayer method myself, but if things are being added twice, wouldn't all of the items in the legend be repeated instead of the particular ones? All of the items you see in the picture are from one service/mxd sitting on our ArcGISServer. – Ruchira Welikala Jul 17 '13 at 13:40
  • 2
    if possible please put your code at jsfiddle so that we can check. – Sunil Jul 17 '13 at 16:26
  • 1
    The server won't work on your end because it is within our network for now. I have no way to publicly release the services either due to privacy issues. Either case, here's the link to the code: jsfiddle.net/xC6RH Thanks! – Ruchira Welikala Jul 17 '13 at 17:30
  • As of now this is favorite for 2 people, did you ever find the answer? Perhaps fire a console message to help debug it? – Barrett Aug 27 '14 at 18:24

Hope you figured this out.

I would check the layer itself in ArcMap and make sure you don't have duplicates in there, such as two layer groups that are identical.

  • Thanks!That's what I did.. I recreated the service layer (republished) and rewrote the code block. It just started working. – Ruchira Welikala Sep 19 '14 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.