[Users] Layer Tree groups
Matt Priour
mpriour at kestrelcomputer.com
Mon Nov 8 19:08:24 CET 2010
While the JSON editing function in
http://api.geoext.org/1.0/examples/tree.js allows people to play with the
example directly, it has also generated quite a bit of confusion.
First, there is no need to write your child node configurations to JSON and
then parse it back out of JSON.
Second, do you actually want to show the layers from the WMS that make up
your labores_2010 WMS Layer and give users the ability to turn them on/off
independtly?
If so, then you want to use a LayerParamLoader, if not then you want to use
the regular OverlayLayerContainerLoader or a gx_layer node with no loader.
Here is the code you would use for allowing individual selection of the
different labores_2010 layers
{
nodeType: "gx_layer",
text: "Labores 2010",
layer: "labores_2010",
isLeaf:false
loader: {
param: "LAYERS"
}
// creates subnodes for the layers in the LAYERS param. If we assign
// a loader to a LayerNode and do not provide a loader class, a
// LayerParamLoader will be assumed.
}
Here is the code you would use for a single node to turn on/off the
labores_2010 layer
{
nodeType: "gx_layer",
text: "Labores 2010",
layer: "labores_2010",
isLeaf: true,
checked: true
}
Here is the code to use an OverlayLayerContainerLoader. This will create
subnodes for each non-baseLayer that has 'displayInLayerSwitcher' == true
(the default for the layer, unless you specifically set it false in the
layer options). It will use each layer's name attribute as the text for the
tree node.
{
nodeType:'gx_overlaylayercontainer',
expanded:true,
loader:{
baseAttrs:{checked:true} //this gives the overlayer layers checkboxes
}
}
Get rid of the OpenLayers.Format.JSON write & parse stuff and just use
treeConfig object directly.
Hope that helps
Matt Priour
Kestrel Computer Consulting
--------------------------------------------------
From: "antoniofacno" <antoniofcano at gmail.com>
Sent: Monday, November 08, 2010 11:38 AM
To: <users at geoext.org>
Subject: [Users] Layer Tree groups
> Hello,
>
> Again, I'm reading all the examples I find but the question doesn't
> becomes to me so clear... sorry :(
>
> I've got this Layer configuration (two groups: Base and Labores) and I'd
> like to show a layer tree panel. Following the
> http://api.geoext.org/1.0/examples/tree.js example, I'm able to show the
> carpets Base and Lavores 2010 but when expanding they do nothing.
>
> My code is this it:
>
> var lindes = new OpenLayers.Layer.WMS(
> "Lindes",
> "http://getcloud.info:8080/geoserver/wms",
> {
> layers: "lindes",
> format: "image/png",
> transparent:true
> },
> {isBaseLayer: true, singleTile: true}
> );
>
> var catastro = new OpenLayers.Layer.WMS(
> "Base",
> "http://getcloud.info:8080/geoserver/wms",
> {
> layers: "ao:Catastro",
> format: "image/png",
> transparent:true
> },
> {isBaseLayer: true, singleTile: true}
> );
>
> var labores_2010 = new OpenLayers.Layer.WMS(
> "Labores 2010",
> "http://getcloud.info:8080/geoserver/wms",
> {
> layers: [
> "tratamiento_2010",
> "rulo_2010",
> "varetas_2010",
> "desbrozar_2010",
> "soplar_2010"
> ],
> format: "image/png",
> transparent:true
> }, {
> isBaseLayer: false,
> buffer: 0,
> // exclude this layer from layer container nodes
> displayInLayerSwitcher: false,
> visibility: false
> }
> );
>
> layer = [catastro,lindes , labores_2010, labores];
> map.events.register('click', map, getAOFeatureInfo );
>
> //Panel Central con el Mapa
> var mapPanel = new GeoExt.MapPanel({
> map: map
> });
>
> var treeConfig = new OpenLayers.Format.JSON().write([{
> layer: "Base",
> nodeType: "gx_baselayercontainer",
> }, {
> nodeType: "gx_layer",
> //nodeType: "gx_overlaylayercontainer",
> layer: "Labores 2010",
> load: {
> param: "LAYERS"
> }
> }], true);
>
> // create the tree with the configuration from above
> tree = new Ext.tree.TreePanel({
> border: true,
> region: "west",
> title: "Capas",
> width: 200,
> split: true,
> collapsible: true,
> //loader: new Ext.tree.TreeLoader(),
> root: {
> nodeType: "async",
> // the children property of an Ext.tree.AsyncTreeNode
> is used to
> // provide an initial set of layer nodes. We use the
> treeConfig
> // from above, that we created with
> OpenLayers.Format.JSON.write.
> children: Ext.decode(treeConfig)
> }
> });
>
> Best wishes,
> _______________________________________________
> Users mailing list
> Users at geoext.org
> http://www.geoext.org/cgi-bin/mailman/listinfo/users
>
More information about the Users
mailing list