Select to view content in your preferred language

Duplicate items in the legend (picture included)

1080
2
07-15-2013 06:21 AM
RuchiraWelikala
Regular Contributor
Hi All,
I have recently created a web map that uses the legend snippet from the ESRI JavaScript API website.
https://developers.arcgis.com/en/javascript/jssamples/widget_legend.html

It works great for the most part, but has one issue, there are duplicate entries in the legend. (Refer to this image: [ATTACH=CONFIG]25925[/ATTACH])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.

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},
                "legendDiv");
                legendDijit.startup();
            }
        });


Any information would help.

Thanks
0 Kudos
2 Replies
JohnGravois
Deactivated User
since you are relying on the 'onLayersAddResult' event to create your layerInfos object to pass in the legend widget constructor it would be helpful to know which specific layers in your application you are loading with map.addLayer() and which you are loading using map.addLayers([])

also, id be curious to know what the layerInfo you are passing to the legend widget contains.  can you set a breakpoint and take a look?
0 Kudos
RuchiraWelikala
Regular Contributor
since you are relying on the 'onLayersAddResult' event to create your layerInfos object to pass in the legend widget constructor it would be helpful to know which specific layers in your application you are loading with map.addLayer() and which you are loading using map.addLayers([])

also, id be curious to know what the layerInfo you are passing to the legend widget contains.  can you set a breakpoint and take a look?


Thanks for your reply, John.

There's only one instance in the entirety of my code where I add layers to the map. It's within a function I that also declares the infotemplate, a feature layer, and a dynamic map service.

Then I use:
 myMap.addLayers([featureLayer1, DMSL_StudyArea]);
to add the feature layer and the dynamic map service to the map. The symbology classes in the feature layer are the ones being duplicated.