Add Symbology Dynamic Layer List

496
1
Jump to solution
07-06-2012 09:52 AM
VernWolfley
New Contributor III
I have been working with the sample data for JavaScript API to create a layer list of my map service.  It works great but I would like to add the layer symbology to the list also.  I am having trouble with this.  Any suggestions? This is the code that I am using currently.

function buildLayerList(layer) {         var items = dojo.map(layer.layerInfos,function(info,index){           if (info.defaultVisibility) {             visible.push(info.id);           }           return "<input type='checkbox' class='list_item'" + (info.defaultVisibility ? "checked=checked" : "") + "' id='" + info.id + "' onclick='updateLayerVisibility();' /><label for='" + info.id + "'>" + "&nbsp" + info.id + "&nbsp" + info.name + "</label>";         })          dojo.byId("layer_list").innerHTML = items.join(' ');
0 Kudos
1 Solution

Accepted Solutions
VernWolfley
New Contributor III
Finally figured this one out the other day.  I was making it to complicated.  I just added a file with the symbol images and the ID numbers.  It loops through and adds them to the List.  Works great.

function buildLayerList(layer) {     var items = dojo.map(layer.layerInfos, function (info, index) {         if (info.defaultVisibility) {             visible.push(info.id);         }         return "<br/><input type='checkbox' class='list_item' checked=''" + (info.defaultVisibility ? "checked=checked" : "") + "' id='" + info.id + "' onclick='updateLayerVisibility();' /><img src='./images/symbols/" + info.id + ".png'><label for='" + info.id + "'>" + info.name + "</label>";     });      dojo.byId("layerlist").innerHTML = items.join(' ');      layer.setVisibleLayers(visible);     map.addLayer(layer); } 

View solution in original post

0 Kudos
1 Reply
VernWolfley
New Contributor III
Finally figured this one out the other day.  I was making it to complicated.  I just added a file with the symbol images and the ID numbers.  It loops through and adds them to the List.  Works great.

function buildLayerList(layer) {     var items = dojo.map(layer.layerInfos, function (info, index) {         if (info.defaultVisibility) {             visible.push(info.id);         }         return "<br/><input type='checkbox' class='list_item' checked=''" + (info.defaultVisibility ? "checked=checked" : "") + "' id='" + info.id + "' onclick='updateLayerVisibility();' /><img src='./images/symbols/" + info.id + ".png'><label for='" + info.id + "'>" + info.name + "</label>";     });      dojo.byId("layerlist").innerHTML = items.join(' ');      layer.setVisibleLayers(visible);     map.addLayer(layer); } 
0 Kudos