Select to view content in your preferred language

Legend - toggle services in AMD

980
2
Jump to solution
02-07-2014 08:20 AM
TimWitt
Deactivated User
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
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Take a look at this post, where I set up a Fiddle with the sample written in AMD.

You might be interested in alternate ways of showing the legend and table of contents. There are a few widgets that integrate the TOC with the legend, like this one written by Nliu and this one by Matt Driscoll.

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor
Take a look at this post, where I set up a Fiddle with the sample written in AMD.

You might be interested in alternate ways of showing the legend and table of contents. There are a few widgets that integrate the TOC with the legend, like this one written by Nliu and this one by Matt Driscoll.
0 Kudos
TimWitt
Deactivated User
Thanks for the answer Ken.

I'm pretty new to the JavaScript API and I think that leads me to trying to re-invent the wheel 🙂
0 Kudos