I am using ArcGIS JavaScript 3.7 API's and i am using agsjs.dijit.TOC control and it is working fine but when i added Label Layer in my map that time Label layer is coming fine but TOC is not working Properly.

While Pressing the checkbox to On-Off the Layer it is working fine but regarding the feature layer i added one Label layer that is not getting On-Off

Can anyone tell me how to Switch-Off or On the Label Layer.

Thanks in Advance.

I am Pasting some code..

    Var load = function () {
    require(["dojo/_base/Color", "esri/symbols/TextSymbol", "esri/renderers/SimpleRenderer", "esri/renderers/ScaleDependentRenderer"],
    function (Color, TextSymbol, SimpleRenderer, ScaleDependentRenderer) {
    var statesColor = new Color("#666");
    var fieldLabel = new TextSymbol().setColor(statesColor);

    statesLabelRenderer = new SimpleRenderer(fieldLabel);
    return statesLabelRenderer;
    var layers = [];  
    var layer = new esri.layers.FeatureLayer(url, {
        mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
        outFields: ["*"]                                    

    layerInfo.push({ layer: layer, title: item["LookupDisplayDesc"], boxLabel:     item["LookupDisplayDesc"], id: layer.id, checked: layer.visibleAtMapScale, slider: true });

if (item["LookupLongDesc"] != null && item["LookupLongDesc"] != "") {
    var fieldNames = item["LookupLongDesc"].split(",");
    var labelFields = "";
for (var i = 0 ; i < fieldNames.length ; i++) {
    labelFields = labelFields + "${" + fieldNames[i].trim() + "},";
    labelFields = labelFields.slice(0, -1).trim();
    var labelLayer = new esri.layers.LabelLayer();
    labelLayer.addFeatureLayer(layer, statesLabelRenderer, labelFields);

 dojo.connect(map, 'onLayersAddResult', function (results) {
                if (layerInfo.length > 0) {
                    var legendDijit = new esri.dijit.Legend({
                        map: map,
                        layerInfos: layerInfo
                    }, "legendDiv");
                toc = new agsjs.dijit.TOC({
                    map: map,
                    layerInfos: layerInfo
                }, 'LayerDiv');

U can achieve it, by simply adding a id to the LabelLayer:

 var labelLayer = new esri.layers.LabelLayer({ id: "labels" });

And then get the layer from the id, and set the visibility:


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.