Friday 22 December 2017

Different legend properties with ArcGIS API for JavaScript


I have a map template that I use to display a variety of feature layers and dynamic layers.


I have found a snippet of code to add the legend to my map:


//add the legend
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();
}
});


The issue is, I can't figure out how to configure the names of the layers, labels, descriptions, etc. Most of the layers in my service are symbolized by Category, so, I want to be able to display those category names in the Legend.


This is what I want to show..or something like it, but with a category or layer heading


This is what shows up. No heading, just the categorized layer without a title or anything.


Any help would be appreciated.


Thanks



Answer



return { layer: layer.layer, title: layer.layer.name };

the property you are interested in setting is the title and the code you are using currently loops through each individual layer that has been successfully added to set this property using layer.name.



can you confirm that this actually present in the service? what do you see when you set a breakpoint within that loop?


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...