Select to view content in your preferred language

programmatically check checkbox in toc widget

2128
5
Jump to solution
04-12-2013 12:43 PM
GeoffreyJoseph1
Deactivated User
I am using the awesome toc widget, very new at arcgis and dojo and I am trying to check a checkbox on the toc widget when the user searches based on one of the layers.

For example, if the user searches based on "zip code", I would like to activate the zip code layer by checking the checkbox for "zip code" in the toc widget. I thought something like this (or some variation) would work:

dijit.byId("dijit_form_CheckBox_7").set("value",true);
dijit.byId("dijit_form_CheckBox_7").set("value","on");


<input type="checkbox" class="dijitReset dijitCheckBoxInput" data-dojo-attach-point="focusNode" data-dojo-attach-event="onclick:_onClick" value="on" tabindex="0" id="dijit_form_CheckBox_7" aria-checked="false" aria-disabled="false">

Also, if I succeed in checking the box, will this activate the widgets "onclick" event?

Can anyone help me with this? Thanks.
0 Kudos
1 Solution

Accepted Solutions
NianweiLiu
Frequent Contributor
I suggest watch firebug to see what's been sent to REST end point. If the request appears to be correct (i.e. layerIds and layerOptions are what you need), then there is a chance that the REST end point may ignore layerIds if the option is VISIBLE_LAYERS, you can try set it to ALL. (That's what I do to implement the functionality of only identify visible layers, although not use the JSAPI).

If after setting to ALL is still not getting your results, exam the group layers. Due to the fact that REST API does not handle "underfined", plus the true/false option can not be accurately represent a  "partial" state (i.e. some layers in the group is visible), the REST API has to make some assumptions to deal with groups. That undocumented assumption can change between arcgis server versions, so test carefully.

What I can tell you is that the TOC widget force groups to be off (thus not sending them in "show:" to refresh dynamic layer). The reason been the rendering engineer will render every individual layer in a group regardless it's visibility state if it's parent is listed in the "show" list. If that's actually caused your identify problem, you may need to add those groups in the identifyParams. Again, this also could change between versions.

In summary, watch REST communication in firebug, test out how REST handle groups, you should be able to get what you want. There is no need to programmatically check the boxes. Just use dynalayer.visibleLayers.

View solution in original post

0 Kudos
5 Replies
GeoffreyJoseph1
Deactivated User
Still bangin my head over this one, I do have the map published so it is can be viewed from the web

aecam map

My problem is simply this: I want provide identify information for only the layers that are checked in the TOC widget. My problem is I don't know how to identify which layers are checked to feed my identifyParams.layerIds.

identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = 3;
identifyParams.returnGeometry = true;
//identifyParams.layerIds = aecam.visibleLayers; //[0,5];
identifyParams.layerIds = [0,5];
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
identifyParams.width  = map.width;
identifyParams.height = map.height;


It seems that if I use visibleLayers it gives me the info for all layers. Right now I am using a range of layers, but my thought is if I can tell which TOC box is checked, I can assign the layerIds to use after the map is clicked. This is also made with a kludge of examples from the site, so there may be an issue with  that also. Can anyone help? Thanks
0 Kudos
KenBuja
MVP Esteemed Contributor
What I did in my app using the TOC widget was to set the identifyParams.layerIds in the executeIdentifyTask(evt) function.

Try using

function executeIdentifyTask(evt) {
    identifyParams.geometry = evt.mapPoint;
    identifyParams.mapExtent = map.extent;
    identifyParams.layerIds = aecam.visibleLayers;
    
    var deferred = identifyTask.execute(identifyParams);
0 Kudos
NianweiLiu
Frequent Contributor
I suggest watch firebug to see what's been sent to REST end point. If the request appears to be correct (i.e. layerIds and layerOptions are what you need), then there is a chance that the REST end point may ignore layerIds if the option is VISIBLE_LAYERS, you can try set it to ALL. (That's what I do to implement the functionality of only identify visible layers, although not use the JSAPI).

If after setting to ALL is still not getting your results, exam the group layers. Due to the fact that REST API does not handle "underfined", plus the true/false option can not be accurately represent a  "partial" state (i.e. some layers in the group is visible), the REST API has to make some assumptions to deal with groups. That undocumented assumption can change between arcgis server versions, so test carefully.

What I can tell you is that the TOC widget force groups to be off (thus not sending them in "show:" to refresh dynamic layer). The reason been the rendering engineer will render every individual layer in a group regardless it's visibility state if it's parent is listed in the "show" list. If that's actually caused your identify problem, you may need to add those groups in the identifyParams. Again, this also could change between versions.

In summary, watch REST communication in firebug, test out how REST handle groups, you should be able to get what you want. There is no need to programmatically check the boxes. Just use dynalayer.visibleLayers.
0 Kudos
KenBuja
MVP Esteemed Contributor
To show you an example of my previous post, this is what I get when I have use this code

            dojo.connect(map, "onClick", executeIdentifyTask);
            identifyTask = new esri.tasks.IdentifyTask("http://egisws02.nos.noaa.gov/ArcGIS/rest/services/biogeo/SEFCRI/MapServer");

            identifyParams = new esri.tasks.IdentifyParameters();
            identifyParams.tolerance = 3;
            identifyParams.returnGeometry = true;
            identifyParams.layerIds = layerSEFCRI.visibleLayers;
            identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
            identifyParams.width = map.width;
            identifyParams.height = map.height;

        }

        function executeIdentifyTask(evt) {
            identifyParams.geometry = evt.mapPoint;
            identifyParams.mapExtent = map.extent;
            identifyParams.layerIds = layerSEFCRI.visibleLayers;


[ATTACH=CONFIG]23740[/ATTACH]

When I comment the layerIds line out in the executeIdentifyTask function

            dojo.connect(map, "onClick", executeIdentifyTask);
            identifyTask = new esri.tasks.IdentifyTask("http://egisws02.nos.noaa.gov/ArcGIS/rest/services/biogeo/SEFCRI/MapServer");

            identifyParams = new esri.tasks.IdentifyParameters();
            identifyParams.tolerance = 3;
            identifyParams.returnGeometry = true;
            identifyParams.layerIds = layerSEFCRI.visibleLayers;
            identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
            identifyParams.width = map.width;
            identifyParams.height = map.height;

        }

        function executeIdentifyTask(evt) {
            identifyParams.geometry = evt.mapPoint;
            identifyParams.mapExtent = map.extent;
            //identifyParams.layerIds = layerSEFCRI.visibleLayers;


I don't get a result back.

[ATTACH=CONFIG]23741[/ATTACH]

As an aside, Nianwei, the visibility toggle isn't working properly if there are more than two levels of groupings. As you can see, the top most layer group "Legal and Regulatory Boundaries" is turned off. This should mean that that layer "Fishing Restrictions" isn't visible. This map service is publicly available if you'd like to check it out.
0 Kudos
GeoffreyJoseph1
Deactivated User
Thanks for all the replies, I am getting closer.

I did find out my problem with identifying the layers that are checked. instead of

identifyParams.layerIds = map.visibleLayers;


I used

map._layers.aecam.visibleLayers;


and I did place it inside my executeIdentifyTask(evt) function, thanks Ken for the suggestion.

Liu I will try out your suggestions.
0 Kudos