I'm developing a Table of Content to turn on\off layers on map using javascript \ dojo-AMD sdk. I found a few places on the internet that shows ways. Nothing that is making complete sense to a newbie. Has anyone done this in a way that makes sense?
Mike,
Have you seen Nliu's TOC? http://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109
Here is a thread where some one else was have an issue getting it going and then got it figured out
TOC - totally stumped
I've been working on a TOC / Layer List control, too: WSDOT-GIS/arcgis-js-layer-list · GitHub
I feel like most people are using Nilu's TOC. I thought the instructions for implementing as dojo AMD were pretty straight forward.
this is why every so often I like to recommend ESRI to please include TOC as a part of the API. Probably something like 75% of people are using Nianwei Liu 's AGS TOC widget. I'd recommend using that, it's a fantastic widget. There's nothing wrong with making your own TOC if you want to do something unique but 9 out of 10 times we just need the basic functionality AGS TOC provides.
AGS TOC caveats and notes: On a recent project I found out ESRI removed the ability to embed tokens in proxies a few API versions back. Thus now AGSTOC now doesn't work with secure services! One reason why ESRI should officially add a TOC in the API. For this project... I "made" a TOC for the one secure service by creating a checkbox tied to a .show/hide for that layer..and use AGS TOC for the other services, one TOC per Accordion. (you can have multiple instances of a AGS TOC widget, and for example put one per accordion) Also AGSTOC doesn't work with Annotations. And until recently had problems with legends in secure services (an ESRI staffer was kind enough to provide a workaround) And when calling ESRI Support one must usually convince them to support AGS TOC widget once they notice that in the code. In a recent thread Kelly says they are considering adding the WebApp Builder TOC to the API. This will sure be a great thing! I am looking forward to it.
At this year's Developer Summit, I talked with one of the Javascript specialists about adding a TOC into the API. He talked about some of the issues with modifying the existing WebApp Builder TOC, since that relies on using ArcGIS.com web maps and not directly using services. I described how I was using the AGSTOC with both my own services and with outside services (when I didn't want to show all the layers in a particular service)
In a followup email, I gave him code samples on how I was able to show only a subset of layers in a service and also how I could create a TOC that allowed for both check box and radio button ways of turning on layers. In one case, I have a TOC that has layers that can be turned on independently and layers that can only be turned on one at a time.
Thanks for the information. This seems like a good route to take.
Mike Crook
You can find my implementation of a layer control included with cmv/cmv-app · GitHub for inspiration. It can also be used outside of the CMV framework.
Ben, that's an awesome website template. Thanks!
Hey Ken,
Is there anyway to turn on all sublayers and turn off all sublayers in the WebApp builder? I'm trying to do this with my own layers. Thanks
The TOC method that I chose was the AGSTOC. It's a great tool and I actually got it to work. I'm on my way. Thanks for all the input and feedback.
Ben,
Would your CMV layer control widget be easily extracted from CMV source code and put into an existing ArcGIS JS App? If so would it require a lot of code modifications or config to get working?
Thanks
Simon
You can certainly us it outside of CMV Simon.
Here's the docs: Layer Control - CMV
So CMV has some secret sauce which creates the LayerInfos array for layers loaded with CMV. You'll need to do that yourself. The docs explain it.
It uses Font Awesome, the iconic font and CSS toolkit so you need to have it loaded.
Quick tip: the layer property of a layerInfo object accepts either a layer object or layer id. If you are giving your layers ids (and you should) you can just use layer ids. Which is handy when you might not have the layer objects in the same scope.
If you just need to toggle layers on and off. I recommend the following (which may be in the API soon): Esri/arcgis-dijit-layer-list · GitHub
If you need more functionality such as a legend combination, etc then I'd recommend to use Nliu's.
Matt Driscoll What about dynamic sublayer control?
Yeah, it supports toggling sublayers.
Kind of. If you turn off a layer group with say 3 of 6 layers visible and then turn it back on all layers of the group are visible.
Matt,
Can you provide anymore info in this possibly being added to the ArcGIS JavaScript API? When? What functionality might it have?
I see with the latest JS API release 3.14 there is now a LayerList widget in the API in Beta.
LayerList | API Reference | ArcGIS API for JavaScript
@ ESRI developers:
There is a bug: It does not uncheck sublayers if you uncheck the group.
(as detailed here WebApp Builder TOC bug and About upcoming JSAPI 4.0 beta 1 )
You should also at least have an option to make it collapse the list of layers. (roll them up). And gray out scale dependent layers beyond scale.
In other words, make it like @Nianwei's AGS JS TOC.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.