var countyLayer = new ArcGISDynamicMapServiceLayer(pathName+"/ArcGIS/rest/services/BaseMap/BasicBoundary/MapServer", {id:'countyLayer', visible:false}) countyLayer.setVisibleLayers([3]); //other layers I added, map gets created .... app.map.on("layers-add-result", function (event) { try { var toc = new agsjs.dijit.TOC({ map: app.map, layerInfos: [{ layer: controlLayer, title: "Control Points" },{ layer: plssLayer, title: "Public Land Survey System" },{ layer: twpRngLayer, title: "Township / Range" },{ layer:countyLayer, title:"Missouri Counties" }] }, 'tocDiv'); toc.startup(); } catch (e) { console.log(e.message); } });
toc.findTOCNode(layer, layerId).hide();
function createTOC() { try { var toc = new TOC({ map: map, layerInfos: layerInfo }, "divLayers"); toc.startup(); } catch (e) { console.log(e.message); } toc.on("load", function () { for (var k = 0; k < layerInfo.length; k++) { var layer = layerInfo.layer; var layersArray = layerInfo .layerList; if (layersArray != null) { var dynamicLayerInfos = layer.createDynamicLayerInfosFromLayerInfos(); for (var j = 0; j < dynamicLayerInfos.length; j++) { toc.findTOCNode(layer, dynamicLayerInfos .id).hide(); //hide all the layers for (var i = 0; i < layersArray.length; i++) { if (dynamicLayerInfos .id == layersArray.id) { toc.findTOCNode(layer, dynamicLayerInfos .id).show(); //only show the layers in the dynamicLayerInfos array } } } } } }); }
layerInfo = [{ layer: layerBenthic, title: "Benthic Data", slider: true, layerList: benthicLayers }];
benthicLayers: [ { label: "Boundaries", id: 72, showLayer: true }, { label: "Structure", id: 75, showLayer: true }, { label: "Biological Cover", id: 73, showLayer: true }, { label: "Live Coral Cover", id: 74, showLayer: true }, { label: "Percent Hardbottom", id: 76, showLayer: true }, { label: "Zone", id: 77, showLayer: true }
If i have a service that is broken, it breaks the TOC. How can i avoid this? I have some code that you gave me to check if the service is getting an error. How do i implement that in the TOC dynamically?
One way would be to build the layerInfo array dynamically, so that when a service loads properly, then the layers for that service gets added. Otherwise, they are not added and should not break the TOC
Ken,
Can i use this function to set the opacity of a single sub layer?
I am using this to hide layers:
tocEORI.findTOCNode(eoriLayers, 12).hide();
can i use something like that to set the opacity of that one layer?
You won't be able to do that with the findTOCNode method. It returns a TOC node, which can only be collapsed, expanded, shown, or hidden.
Thanks, that is what i suspected!