AnsweredAssumed Answered

Legend - toggle services in AMD

Question asked by timw1984dev on Feb 7, 2014
Latest reply on Feb 7, 2014 by timw1984dev
Hey everybody!

Does anybody use the Legend - toggle services example in AMD format?

I tried to include it in my app, but I'm pretty new to JavaScript and this one is a head scratcher :)

Here is what I've got so far for that part of my code:

      var legendLayers = [];       var county = new FeatureLayer("http://gis.brevardcounty.us/gissrv/rest/services/Base_Map/General_WKID102100/MapServer/6",{         mode: FeatureLayer.MODE_ONDEMAND,         outFields:["*"]       });              //Create 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();         }       });       map.addLayers([county]);       legendLayers.push({layer:county, title:"County"});      //Create Checkboxes       map.on("layers-add-result", function (evt) {         arrayUtils.map(legendLayers, function (evt) {           var layerName = layer.title;           var checkBox = new CheckBox ({             name:"checkBox" + layer.layer.id,             checked: layer.layer.visible,             onChange: function (evt) {               var clayer=map.getLayer(this.value);               clayer.setVisibility(!clayer.visible);               this.checked = clayer.visible;             }           });           //Move the checkboxes to TOC           domConstruct.place(checkBox.domNode, dom.byId("toggle"), "after");           var checkLable = domConstruct.create('label', {'for':checkBox.name, innerHTML:layerName}, checkBox.domNode, "after");           domConstruct.place("<br />", checkLabel, "after");         });                });


If you used that example in AMD it would be nice to see working code.

Thanks

Tim

Outcomes