在ArcGIS JavaScript中使用标签图层进行TOC

时间:2013-10-10 11:35:39

标签: javascript arcgis dijit.form

我使用的是ArcGIS JavaScript 3.7 API,我正在使用agsjs.dijit.TOC控件,它运行正常,但是当我在地图中添加Label Layer时,标签图层正常运行但是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();                
            });

1 个答案:

答案 0 :(得分:1)

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

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

labelLayer.hide();
labelLayer.show();