enter image description here

enter image description here

I am very new to ArcGIS JavaScript and have been reading some samples from the API. So pardon my ignorance and I hope I am asking the right question.

I am using ArcGIS JavaScript 3.5 API and agsjs.dijit.TOC control to display several layers in a map. I am trying to do the following:

Add a textbox, Type a layer name to filter, and the expected result is that only the filter layers should show up in TOC and the filtered layers in a map. Does this make sense? Like I said, I am using the TOC widget.

After looking around and reading a bit, I have been able to get a filtered array which has the list of filtered layers, but how do I update/filter the TOC contents with this? Or am I on the wrong route?

var filteredArray = 
        array.filter(this.map.getLayer(this.map.layerIds[1]).layerInfos, function (item)

            return item.name.indexOf("Text entered for filter") != -1;

I am trying to learn so any help is greatly appreciated!

  • Can you post additional code? If is difficult to make a suggestion with what is currently provided. – Jeremy Hamm Feb 28 '14 at 21:57

Use the ctrl + f function and you can just tick the boxes on or off.

  • The question though asks about how to do this in JavaScript. – nmtoken Jun 20 '17 at 12:50

I would use the latest version of the API (3.8) before you do anything.

Have you used Dojo before? This is the Javascript framework which the API is built upon. There are many good form examples here which you can use in the TOC. I would recommend the Combo Box. This seems to have the functionality you are looking for.

  • @jeremythamm- Thanks for your reply. I am also looking at dojo. I have updated my post with some screenshots. Screen shot 1 shows TOC of all layers, below is a textbox where some text to filter layer names can be typed. Once I typed the text 'base', it lists only the layers matching the search text. I hope this makes it a bit clear. As for the code, I only have the TOC widget code and another filter textbox, upon entering some search text, I am trying to update TOC. – Aqua267 Feb 28 '14 at 22:09
  • I am still unsure of exactly what the end goal is? What are you trying to accomplish? – Jeremy Hamm Feb 28 '14 at 22:12
  • I apologize, once a search text is typed in the filter, only those layers should show up in TOC. 'Filter by layer name' is the textbox where the user would enter some text. May be I am not being clear to you due to my lack of knowledge on this. For instance, in the second screenshot I typed 'base' as the text, TOC updated to show only the layer names that contained that text. – Aqua267 Feb 28 '14 at 22:14
  • It sounds like then you have already accomplished what you are wanting to do. If you type "base" in the text box and it does filter, it sounds like it is working correctly – Jeremy Hamm Feb 28 '14 at 22:17
  • This is just a sample from a different website I got. I am trying to implement this feature in the webapp I am developing. So far I can get the TOC to work, add a textbox to filter and upon changing/adding some text to the textbox, I am calling a function. But I am stuck there. From there on, I do not know how to replace the existing TOC with the filtered layers. – Aqua267 Feb 28 '14 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.