Select to view content in your preferred language

NLiu's Table of Contents(TOC)/Legend widget and Visibility States

3493
27
Jump to solution
03-09-2012 04:21 AM
AlexDeVine
Occasional Contributor
Hi Forum,

I am using NLiu's TOC Widget in a web application I am developing: http://www.arcgis.com/home/item.html?id=9c43bdf76a23452ba1d95684f7cd76d8

It is a great widget and it is working great, except one thing... I also have an Identify task that I would like to be able to only have work on the visible layers, but as the widget is handling the visibility, it has effectively "blackboxed" the layer visibility state for me. I was hoping to be able to obtain an array from the TOC widget and feed that to my identify task so that it had the latest info on what should be returned, but I am stymied. Any tips?

Thank you, in advance, for any help.

Alex DeVine
University of Georgia
0 Kudos
1 Solution

Accepted Solutions
NianweiLiu
Frequent Contributor
Hi Forum,

I was hoping to be able to obtain an array from the TOC widget and feed that to my identify task


You do not need the TOC to tell you which layer is visible.
For service level layer, you should be using Layer.visible. For layers underneath a dynamic map service, use ArcGISDynamicMapServiceLayer.visibleLayers.

View solution in original post

0 Kudos
27 Replies
NianweiLiu
Frequent Contributor
Hi Forum,

I was hoping to be able to obtain an array from the TOC widget and feed that to my identify task


You do not need the TOC to tell you which layer is visible.
For service level layer, you should be using Layer.visible. For layers underneath a dynamic map service, use ArcGISDynamicMapServiceLayer.visibleLayers.
0 Kudos
AlexDeVine
Occasional Contributor
You do not need the TOC to tell you which layer is visible.
For service level layer, you should be using Layer.visible. For layers underneath a dynamic map service, use ArcGISDynamicMapServiceLayer.visibleLayers.


Thank you! Sorry I did not see the obvious. I was trying to adapt a samples visibility check.

Alex
0 Kudos
StephenLead
Honored Contributor
It is a great widget


+1 it's an excellent widget which should be part of the API
0 Kudos
MichaelJenkins
Frequent Contributor
There is also an identify task parameter you can set so that only visible layers are queried.  That way you don't have to do any work to determine what is visible or to set which layers should be identified.

identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
GISP
0 Kudos
yanliyan
Emerging Contributor
HI,here I have another question.

I use BasemapGallery object to navigate my map services.

so when I change the map service, how refresh the TOC control?

can anyone help me out?
0 Kudos
DougCollins
Regular Contributor
I agree.  It should be part of the ArcGIS JavaScript API, especially since ESRI has not provided a useful TOC / Legend widget.  We are already at version 2.8 and there is still no useful TOC / Legend from ESRI.  This should be at the top of their development list!

Very frustrating!
Charlie
0 Kudos
StephenLead
Honored Contributor
I use BasemapGallery object to navigate my map services. so when I change the map service, how refresh the TOC control?


BasemapGallery has an event onSelectionChange - listen for this, and refresh the TOC when this occurs.
0 Kudos
yanliyan
Emerging Contributor
You do not need the TOC to tell you which layer is visible.
For service level layer, you should be using Layer.visible. For layers underneath a dynamic map service, use ArcGISDynamicMapServiceLayer.visibleLayers.


In fact ,I have met a problem about the Toc control developed by nLiu.

using the win7 as my server, i found my app normal in chrome, firefox and ie. however,it is abnormal in ie when on the windows 2008 iis server.

i can't figiure out it.

I report this to nliu ,maybe you can fix it next.

thanks
0 Kudos
yanliyan
Emerging Contributor
BasemapGallery has an event onSelectionChange - listen for this, and refresh the TOC when this occurs.


thank u,

I have work it out .but the control didnt provide method to refresh the service when map layers changed. so use the code below:
            toc.layerInfos = [];
            toc._rootLayerTOCs = [];
            for (var i = map.layerIds.length - 1; i >= 0; i--) {
               
                var rootLayer = map.getLayer(map.layerIds);
                toc.layerInfos.push({ layer: rootLayer });
            }
            toc._createTOC();


but i have met another problem. as i post before.
0 Kudos