0

我正在使用 ArcGIS JavaScript 3.7 API,并且正在使用 agsjs.dijit.TOC 控件,它工作正常,但是当我在地图中添加标签图层时,标签图层正常,但 TOC 无法正常工作。

在按下复选框以打开-关闭图层时,它工作正常,但关于要素图层,我添加了一个未打开 - 关闭的标签图层

谁能告诉我如何关闭或打开标签层。

提前致谢。

我正在粘贴一些代码..

        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);
    fieldLabel.font.setSize("4pt");
    fieldLabel.font.setFamily("arial");

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

    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();
    load();
    var labelLayer = new esri.layers.LabelLayer();
    labelLayer.addFeatureLayer(layer, statesLabelRenderer, labelFields);
    layers.push(labelLayer);
    }
}
map.addLayers(layers);


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

1 回答 1

1

不熟悉 TOC 的工作原理,我手动构建了我的层逻辑。如果你走手动路线,你可以像下面那样使用显示和隐藏,或者像这样使用 setVisibleLayers 。

图层逻辑中的简单显示和隐藏将是:

labelLayer.hide();
labelLayer.show();
于 2013-10-24T20:57:09.673 回答