How can I add two or more layers in a group so that I can see them in layerswitcher categorised and can select or unselect all !?
Here is the code I have:
var line_1 = new OpenLayers.Layer.Vector(" Line no - 1", {
visibility: true,
projection: dproj,
strategies: [new OpenLayers.Strategy.Fixed()],
style: {strokeWidth: 4, strokeColor: "#ff0000", strokeOpacity: 1},
protocol: new OpenLayers.Protocol.HTTP({
url: "lines/en/line_1.kml",
format: new OpenLayers.Format.KML
})
});
var line_2 = new OpenLayers.Layer.Vector(" Line no - 2", {
visibility: true,
projection: dproj,
strategies: [new OpenLayers.Strategy.Fixed()],
style: {strokeWidth: 4, strokeColor: "#008000", strokeOpacity: 1},
protocol: new OpenLayers.Protocol.HTTP({
url: "lines/en/line_2.kml",
format: new OpenLayers.Format.KML
})
});
var layers = [line_1, line_2]
map.addLayers(layers);
Now how can I gorup these two in 1 with the name "Lines" ?
I think GeoExt.tree is what you want.
See this mail :
http://www.osgeo.org/pipermail/openlayers-users/2008-June/006358.html
Check out here : http://trac.osgeo.org/openlayers/browser/sandbox/jachym/openlayers/examples/layer-groups.html?rev=4958 it looks like a old branch of openlayers that supports it.
So lets look at this : http://api.geoext.org/1.0/examples/tree.html
I think GeoExt.tree is what you want.
I know this is old but I am answering in case if any one has the same question.
If you are using ol3-layerswitcher you can just create a new layer group with all your defined layers to show them under a group. The title of the layer group separates it from the layers.